Refine ASN.1 functions

This commit is contained in:
Zhi Guan
2023-01-14 19:07:03 +08:00
parent e54b4ae182
commit b858b01d39
7 changed files with 1173 additions and 847 deletions

1819
src/asn1.c

File diff suppressed because it is too large Load Diff

View File

@@ -345,10 +345,10 @@ int x509_rdn_to_der(int oid, int tag, const uint8_t *val, size_t vlen,
{
size_t len = 0;
if (x509_attr_type_and_value_to_der(oid, tag, val, vlen, NULL, &len) != 1
|| asn1_data_to_der(more, morelen, NULL, &len) < 0
|| asn1_any_to_der(more, morelen, NULL, &len) < 0
|| asn1_set_header_to_der(len, out, outlen) != 1
|| x509_attr_type_and_value_to_der(oid, tag, val, vlen, out, outlen) != 1
|| asn1_data_to_der(more, morelen, out, outlen) < 0) {
|| asn1_any_to_der(more, morelen, out, outlen) < 0) {
error_print();
return -1;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@@ -992,11 +992,11 @@ int x509_tbs_crl_sign(
error_print();
return -1;
}
if (asn1_data_to_der(tbs, tbslen, NULL, &len) != 1
if (asn1_any_to_der(tbs, tbslen, NULL, &len) != 1
|| x509_signature_algor_to_der(signature_algor, NULL, &len) != 1
|| asn1_bit_octets_to_der(sig, siglen, NULL, &len) != 1
|| asn1_sequence_header_to_der(len, &out, &outlen) != 1
|| asn1_data_to_der(tbs, tbslen, &out, &outlen) != 1
|| asn1_any_to_der(tbs, tbslen, &out, &outlen) != 1
|| x509_signature_algor_to_der(signature_algor, &out, &outlen) != 1
|| asn1_bit_octets_to_der(sig, siglen, &out, &outlen) != 1) {
error_print();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
* Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@@ -92,7 +92,7 @@ int x509_directory_name_from_der(int *tag, const uint8_t **d, size_t *dlen, cons
{
int ret;
if ((ret = asn1_tag_get(tag, in, inlen)) != 1) {
if ((ret = asn1_tag_from_der_readonly(tag, in, inlen)) != 1) {
if (ret < 0) error_print();
return ret;
}
@@ -204,7 +204,7 @@ int x509_display_text_from_der(int *tag, const uint8_t **d, size_t *dlen, const
{
int ret;
if ((ret = asn1_tag_get(tag, in, inlen)) != 1) {
if ((ret = asn1_tag_from_der_readonly(tag, in, inlen)) != 1) {
if (ret < 0) error_print();
return ret;
}