diff options
Diffstat (limited to 'src/asn1/der_enc.cpp')
-rw-r--r-- | src/asn1/der_enc.cpp | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/src/asn1/der_enc.cpp b/src/asn1/der_enc.cpp index fa53aa921..1d12ed5f6 100644 --- a/src/asn1/der_enc.cpp +++ b/src/asn1/der_enc.cpp @@ -31,12 +31,12 @@ SecureVector<byte> encode_tag(ASN1_Tag type_tag, ASN1_Tag class_tag) encoded_tag.push_back(static_cast<byte>(type_tag | class_tag)); else { - u32bit blocks = high_bit(type_tag) + 6; + size_t blocks = high_bit(type_tag) + 6; blocks = (blocks - (blocks % 7)) / 7; encoded_tag.push_back(class_tag | 0x1F); - for(u32bit k = 0; k != blocks - 1; ++k) - encoded_tag.push_back(0x80 | ((type_tag >> 7*(blocks-k-1)) & 0x7F)); + for(size_t i = 0; i != blocks - 1; ++i) + encoded_tag.push_back(0x80 | ((type_tag >> 7*(blocks-i-1)) & 0x7F)); encoded_tag.push_back(type_tag & 0x7F); } @@ -46,17 +46,19 @@ SecureVector<byte> encode_tag(ASN1_Tag type_tag, ASN1_Tag class_tag) /* * DER encode an ASN.1 length field */ -SecureVector<byte> encode_length(u32bit length) +SecureVector<byte> encode_length(size_t length) { SecureVector<byte> encoded_length; if(length <= 127) encoded_length.push_back(static_cast<byte>(length)); else { - const u32bit top_byte = significant_bytes(length); + const size_t top_byte = significant_bytes(length); + encoded_length.push_back(static_cast<byte>(0x80 | top_byte)); - for(u32bit j = 4-top_byte; j != 4; ++j) - encoded_length.push_back(get_byte(j, length)); + + for(size_t i = sizeof(length) - top_byte; i != sizeof(length); ++i) + encoded_length.push_back(get_byte(i, length)); } return encoded_length; } @@ -73,8 +75,8 @@ SecureVector<byte> DER_Encoder::DER_Sequence::get_contents() if(type_tag == SET) { std::sort(set_contents.begin(), set_contents.end()); - for(u32bit j = 0; j != set_contents.size(); ++j) - contents += set_contents[j]; + for(size_t i = 0; i != set_contents.size(); ++i) + contents += set_contents[i]; set_contents.clear(); } @@ -90,7 +92,7 @@ SecureVector<byte> DER_Encoder::DER_Sequence::get_contents() /* * Add an encoded value to the SEQUENCE/SET */ -void DER_Encoder::DER_Sequence::add_bytes(const byte data[], u32bit length) +void DER_Encoder::DER_Sequence::add_bytes(const byte data[], size_t length) { if(type_tag == SET) set_contents.push_back(SecureVector<byte>(data, length)); @@ -183,7 +185,7 @@ DER_Encoder& DER_Encoder::raw_bytes(const MemoryRegion<byte>& val) /* * Write raw bytes into the stream */ -DER_Encoder& DER_Encoder::raw_bytes(const byte bytes[], u32bit length) +DER_Encoder& DER_Encoder::raw_bytes(const byte bytes[], size_t length) { if(subsequences.size()) subsequences[subsequences.size()-1].add_bytes(bytes, length); @@ -238,7 +240,7 @@ DER_Encoder& DER_Encoder::encode(const MemoryRegion<byte>& bytes, /* * Encode this object */ -DER_Encoder& DER_Encoder::encode(const byte bytes[], u32bit length, +DER_Encoder& DER_Encoder::encode(const byte bytes[], size_t length, ASN1_Tag real_type) { return encode(bytes, length, real_type, real_type, UNIVERSAL); @@ -277,10 +279,10 @@ DER_Encoder& DER_Encoder::encode(const BigInt& n, BigInt::encode(&contents[extra_zero], n); if(n < 0) { - for(u32bit j = 0; j != contents.size(); ++j) - contents[j] = ~contents[j]; - for(u32bit j = contents.size(); j > 0; --j) - if(++contents[j-1]) + for(size_t i = 0; i != contents.size(); ++i) + contents[i] = ~contents[i]; + for(size_t i = contents.size(); i > 0; --i) + if(++contents[i-1]) break; } @@ -301,7 +303,7 @@ DER_Encoder& DER_Encoder::encode(const MemoryRegion<byte>& bytes, /* * DER encode an OCTET STRING or BIT STRING */ -DER_Encoder& DER_Encoder::encode(const byte bytes[], u32bit length, +DER_Encoder& DER_Encoder::encode(const byte bytes[], size_t length, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag) { @@ -342,7 +344,7 @@ DER_Encoder& DER_Encoder::encode(const ASN1_Object& obj) * Write the encoding of the byte(s) */ DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, - const byte rep[], u32bit length) + const byte rep[], size_t length) { SecureVector<byte> buffer; buffer += encode_tag(type_tag, class_tag); @@ -359,7 +361,7 @@ DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const MemoryRegion<byte>& rep_buf) { const byte* rep = &rep_buf[0]; - const u32bit rep_len = rep_buf.size(); + const size_t rep_len = rep_buf.size(); return add_object(type_tag, class_tag, rep, rep_len); } @@ -370,7 +372,7 @@ DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const std::string& rep_str) { const byte* rep = reinterpret_cast<const byte*>(rep_str.data()); - const u32bit rep_len = rep_str.size(); + const size_t rep_len = rep_str.size(); return add_object(type_tag, class_tag, rep, rep_len); } |