aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2021-01-11 10:18:31 -0500
committerJack Lloyd <[email protected]>2021-01-13 07:54:13 -0500
commit1b424ce680b1bd88a31b2c229dd89a784c24fd9f (patch)
tree8065ad47cef5462e179e0fe2771c99b49692e36c
parent25dfe1d2f30447ba73181cf784e1e26a6be31f07 (diff)
Add some helpers for start_cons
Nothing in the library uses start_cons anymore but it is left exposed for applications which need to encode something unusual.
-rw-r--r--src/lib/asn1/ber_dec.h22
-rw-r--r--src/lib/asn1/der_enc.h20
-rw-r--r--src/lib/pk_pad/emsa_pssr/pssr.cpp8
-rw-r--r--src/lib/prov/openssl/openssl_ec.cpp8
-rw-r--r--src/lib/pubkey/ecc_key/ecc_key.cpp2
-rw-r--r--src/lib/x509/ocsp.cpp2
-rw-r--r--src/lib/x509/x509_attribute.cpp4
-rw-r--r--src/lib/x509/x509_dn.cpp4
-rw-r--r--src/lib/x509/x509_ext.cpp2
9 files changed, 49 insertions, 23 deletions
diff --git a/src/lib/asn1/ber_dec.h b/src/lib/asn1/ber_dec.h
index 3784c929d..3a485470a 100644
--- a/src/lib/asn1/ber_dec.h
+++ b/src/lib/asn1/ber_dec.h
@@ -106,14 +106,26 @@ class BOTAN_PUBLIC_API(2,0) BER_Decoder final
*/
BER_Decoder& discard_remaining();
- /**
- * Start decoding a constructed data (sequence or set)
- */
- BER_Decoder start_cons(ASN1_Type type_tag, ASN1_Class class_tag = ASN1_Class::UNIVERSAL);
+ BER_Decoder start_cons(ASN1_Type type_tag, ASN1_Class class_tag);
BER_Decoder start_sequence()
{
- return start_cons(ASN1_Type::SEQUENCE);
+ return start_cons(ASN1_Type::SEQUENCE, ASN1_Class::UNIVERSAL);
+ }
+
+ BER_Decoder start_set()
+ {
+ return start_cons(ASN1_Type::SET, ASN1_Class::UNIVERSAL);
+ }
+
+ BER_Decoder start_context_specific(uint32_t tag)
+ {
+ return start_cons(ASN1_Type(tag), ASN1_Class::CONTEXT_SPECIFIC);
+ }
+
+ BER_Decoder start_explicit_context_specific(uint32_t tag)
+ {
+ return start_cons(ASN1_Type(tag), ASN1_Class::EXPLICIT_CONTEXT_SPECIFIC);
}
/**
diff --git a/src/lib/asn1/der_enc.h b/src/lib/asn1/der_enc.h
index e8ac2bf4f..ba49ea421 100644
--- a/src/lib/asn1/der_enc.h
+++ b/src/lib/asn1/der_enc.h
@@ -61,12 +61,26 @@ class BOTAN_PUBLIC_API(2,0) DER_Encoder final
BOTAN_DEPRECATED("Use DER_Encoder(vector) instead")
std::vector<uint8_t> get_contents_unlocked();
- DER_Encoder& start_cons(ASN1_Type type_tag,
- ASN1_Class class_tag = ASN1_Class::UNIVERSAL);
+ DER_Encoder& start_cons(ASN1_Type type_tag, ASN1_Class class_tag);
DER_Encoder& start_sequence()
{
- return start_cons(ASN1_Type::SEQUENCE);
+ return start_cons(ASN1_Type::SEQUENCE, ASN1_Class::UNIVERSAL);
+ }
+
+ DER_Encoder& start_set()
+ {
+ return start_cons(ASN1_Type::SET, ASN1_Class::UNIVERSAL);
+ }
+
+ DER_Encoder& start_context_specific(uint32_t tag)
+ {
+ return start_cons(ASN1_Type(tag), ASN1_Class::CONTEXT_SPECIFIC);
+ }
+
+ DER_Encoder& start_explicit_context_specific(uint32_t tag)
+ {
+ return start_cons(ASN1_Type(tag), ASN1_Class::EXPLICIT_CONTEXT_SPECIFIC);
}
DER_Encoder& end_cons();
diff --git a/src/lib/pk_pad/emsa_pssr/pssr.cpp b/src/lib/pk_pad/emsa_pssr/pssr.cpp
index 2920e81db..cf7312900 100644
--- a/src/lib/pk_pad/emsa_pssr/pssr.cpp
+++ b/src/lib/pk_pad/emsa_pssr/pssr.cpp
@@ -208,10 +208,10 @@ AlgorithmIdentifier PSSR::config_for_x509(const Private_Key& key,
std::vector<uint8_t> parameters;
DER_Encoder(parameters)
.start_sequence()
- .start_cons(ASN1_Type(0), ASN1_Class::CONTEXT_SPECIFIC).encode(hash_id).end_cons()
- .start_cons(ASN1_Type(1), ASN1_Class::CONTEXT_SPECIFIC).encode(mgf_id).end_cons()
- .start_cons(ASN1_Type(2), ASN1_Class::CONTEXT_SPECIFIC).encode(m_salt_size).end_cons()
- .start_cons(ASN1_Type(3), ASN1_Class::CONTEXT_SPECIFIC).encode(size_t(1)).end_cons() // trailer field
+ .start_context_specific(0).encode(hash_id).end_cons()
+ .start_context_specific(1).encode(mgf_id).end_cons()
+ .start_context_specific(2).encode(m_salt_size).end_cons()
+ .start_context_specific(3).encode(size_t(1)).end_cons() // trailer field
.end_cons();
// hardcoded as RSA is the only valid algorithm for EMSA4 at the moment
diff --git a/src/lib/prov/openssl/openssl_ec.cpp b/src/lib/prov/openssl/openssl_ec.cpp
index 5229952dc..4f04618f3 100644
--- a/src/lib/prov/openssl/openssl_ec.cpp
+++ b/src/lib/prov/openssl/openssl_ec.cpp
@@ -51,11 +51,11 @@ secure_vector<uint8_t> PKCS8_for_openssl(const EC_PrivateKey& ec)
.start_sequence()
.encode(static_cast<size_t>(1))
.encode(BigInt::encode_1363(priv_key, priv_key.bytes()), ASN1_Type::OCTET_STRING)
- .start_cons(ASN1_Type(0), ASN1_Class::EXPLICIT_CONTEXT_SPECIFIC)
- .raw_bytes(ec.domain().DER_encode(EC_Group_Encoding::NamedCurve))
+ .start_explicit_context_specific(0)
+ .raw_bytes(ec.domain().DER_encode(EC_Group_Encoding::NamedCurve))
.end_cons()
- .start_cons(ASN1_Type(1), ASN1_Class::EXPLICIT_CONTEXT_SPECIFIC)
- .encode(pub_key.encode(PointGFp::UNCOMPRESSED), ASN1_Type::BIT_STRING)
+ .start_explicit_context_specific(1)
+ .encode(pub_key.encode(PointGFp::UNCOMPRESSED), ASN1_Type::BIT_STRING)
.end_cons()
.end_cons()
.get_contents();
diff --git a/src/lib/pubkey/ecc_key/ecc_key.cpp b/src/lib/pubkey/ecc_key/ecc_key.cpp
index 559c42dad..94d6b4202 100644
--- a/src/lib/pubkey/ecc_key/ecc_key.cpp
+++ b/src/lib/pubkey/ecc_key/ecc_key.cpp
@@ -146,7 +146,7 @@ secure_vector<uint8_t> EC_PrivateKey::private_key_bits() const
.start_sequence()
.encode(static_cast<size_t>(1))
.encode(BigInt::encode_1363(m_private_key, m_private_key.bytes()), ASN1_Type::OCTET_STRING)
- .start_cons(ASN1_Type(1), ASN1_Class::EXPLICIT_CONTEXT_SPECIFIC)
+ .start_explicit_context_specific(1)
.encode(m_public_key.encode(PointGFp::Compression_Type::UNCOMPRESSED), ASN1_Type::BIT_STRING)
.end_cons()
.end_cons()
diff --git a/src/lib/x509/ocsp.cpp b/src/lib/x509/ocsp.cpp
index 1155c7a42..d229aa188 100644
--- a/src/lib/x509/ocsp.cpp
+++ b/src/lib/x509/ocsp.cpp
@@ -115,7 +115,7 @@ Response::Response(const uint8_t response_bits[], size_t response_bits_len) :
if(response_outer.more_items())
{
BER_Decoder response_bytes =
- response_outer.start_cons(ASN1_Type(0), ASN1_Class::CONTEXT_SPECIFIC).start_sequence();
+ response_outer.start_context_specific(0).start_sequence();
response_bytes.decode_and_check(OID("1.3.6.1.5.5.7.48.1.1"),
"Unknown response type in OCSP response");
diff --git a/src/lib/x509/x509_attribute.cpp b/src/lib/x509/x509_attribute.cpp
index 52ea23b14..b92ee00e0 100644
--- a/src/lib/x509/x509_attribute.cpp
+++ b/src/lib/x509/x509_attribute.cpp
@@ -36,7 +36,7 @@ void Attribute::encode_into(DER_Encoder& codec) const
{
codec.start_sequence()
.encode(m_oid)
- .start_cons(ASN1_Type::SET)
+ .start_set()
.raw_bytes(m_parameters)
.end_cons()
.end_cons();
@@ -49,7 +49,7 @@ void Attribute::decode_from(BER_Decoder& codec)
{
codec.start_sequence()
.decode(m_oid)
- .start_cons(ASN1_Type::SET)
+ .start_set()
.raw_bytes(m_parameters)
.end_cons()
.end_cons();
diff --git a/src/lib/x509/x509_dn.cpp b/src/lib/x509/x509_dn.cpp
index 4c1b1e9e2..1747a12dc 100644
--- a/src/lib/x509/x509_dn.cpp
+++ b/src/lib/x509/x509_dn.cpp
@@ -262,7 +262,7 @@ void X509_DN::encode_into(DER_Encoder& der) const
{
for(const auto& dn : m_rdn)
{
- der.start_cons(ASN1_Type::SET)
+ der.start_set()
.start_sequence()
.encode(dn.first)
.encode(dn.second)
@@ -291,7 +291,7 @@ void X509_DN::decode_from(BER_Decoder& source)
while(sequence.more_items())
{
- BER_Decoder rdn = sequence.start_cons(ASN1_Type::SET);
+ BER_Decoder rdn = sequence.start_set();
while(rdn.more_items())
{
diff --git a/src/lib/x509/x509_ext.cpp b/src/lib/x509/x509_ext.cpp
index c5713e3b6..b90eef523 100644
--- a/src/lib/x509/x509_ext.cpp
+++ b/src/lib/x509/x509_ext.cpp
@@ -840,7 +840,7 @@ void CRL_Distribution_Points::Distribution_Point::encode_into(class DER_Encoder&
void CRL_Distribution_Points::Distribution_Point::decode_from(class BER_Decoder& ber)
{
ber.start_sequence()
- .start_cons(ASN1_Type(0), ASN1_Class::CONTEXT_SPECIFIC)
+ .start_context_specific(0)
.decode_optional_implicit(m_point, ASN1_Type(0),
ASN1_Class::CONTEXT_SPECIFIC | ASN1_Class::CONSTRUCTED,
ASN1_Type::SEQUENCE, ASN1_Class::CONSTRUCTED)