diff options
author | lloyd <[email protected]> | 2010-09-15 13:44:42 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-09-15 13:44:42 +0000 |
commit | 180c5358cb31e9c003cada3705bb30cf01732878 (patch) | |
tree | 951038dfaf2c33bcee5e27c4b1d2980eb35494a3 /src/asn1 | |
parent | a9d0f37596e5413cae45f32740738c5c68abcce1 (diff) |
Update all uses of MemoryRegion::append to use either push_back or operator+=
Diffstat (limited to 'src/asn1')
-rw-r--r-- | src/asn1/alg_id.cpp | 4 | ||||
-rw-r--r-- | src/asn1/asn1_oid.cpp | 8 | ||||
-rw-r--r-- | src/asn1/ber_dec.cpp | 5 | ||||
-rw-r--r-- | src/asn1/der_enc.cpp | 48 |
4 files changed, 30 insertions, 35 deletions
diff --git a/src/asn1/alg_id.cpp b/src/asn1/alg_id.cpp index 94709ba16..b48db3e50 100644 --- a/src/asn1/alg_id.cpp +++ b/src/asn1/alg_id.cpp @@ -42,7 +42,7 @@ AlgorithmIdentifier::AlgorithmIdentifier(const OID& alg_id, oid = alg_id; if(option == USE_NULL_PARAM) - parameters.append(DER_NULL, sizeof(DER_NULL)); + parameters += std::make_pair(DER_NULL, sizeof(DER_NULL)); } /* @@ -55,7 +55,7 @@ AlgorithmIdentifier::AlgorithmIdentifier(const std::string& alg_id, oid = OIDS::lookup(alg_id); if(option == USE_NULL_PARAM) - parameters.append(DER_NULL, sizeof(DER_NULL)); + parameters += std::make_pair(DER_NULL, sizeof(DER_NULL)); } /* diff --git a/src/asn1/asn1_oid.cpp b/src/asn1/asn1_oid.cpp index 6c420ff0d..820492e18 100644 --- a/src/asn1/asn1_oid.cpp +++ b/src/asn1/asn1_oid.cpp @@ -130,20 +130,20 @@ void OID::encode_into(DER_Encoder& der) const throw Invalid_Argument("OID::encode_into: OID is invalid"); MemoryVector<byte> encoding; - encoding.append(40 * id[0] + id[1]); + encoding.push_back(40 * id[0] + id[1]); for(u32bit j = 2; j != id.size(); ++j) { if(id[j] == 0) - encoding.append(0); + encoding.push_back(0); else { u32bit blocks = high_bit(id[j]) + 6; blocks = (blocks - (blocks % 7)) / 7; for(u32bit k = 0; k != blocks - 1; ++k) - encoding.append(0x80 | ((id[j] >> 7*(blocks-k-1)) & 0x7F)); - encoding.append(id[j] & 0x7F); + encoding.push_back(0x80 | ((id[j] >> 7*(blocks-k-1)) & 0x7F)); + encoding.push_back(id[j] & 0x7F); } } der.add_object(OBJECT_ID, UNIVERSAL, encoding); diff --git a/src/asn1/ber_dec.cpp b/src/asn1/ber_dec.cpp index f2873c177..860003440 100644 --- a/src/asn1/ber_dec.cpp +++ b/src/asn1/ber_dec.cpp @@ -106,7 +106,8 @@ u32bit find_eoc(DataSource* ber) const u32bit got = ber->peek(&buffer[0], buffer.size(), data.size()); if(got == 0) break; - data.append(&buffer[0], got); + + data += std::make_pair(&buffer[0], got); } DataSource_Memory source(data); @@ -171,7 +172,7 @@ BER_Decoder& BER_Decoder::raw_bytes(MemoryRegion<byte>& out) out.clear(); byte buf; while(source->read_byte(buf)) - out.append(buf); + out.push_back(buf); return (*this); } diff --git a/src/asn1/der_enc.cpp b/src/asn1/der_enc.cpp index 0ce633c7a..affb40372 100644 --- a/src/asn1/der_enc.cpp +++ b/src/asn1/der_enc.cpp @@ -28,16 +28,16 @@ SecureVector<byte> encode_tag(ASN1_Tag type_tag, ASN1_Tag class_tag) SecureVector<byte> encoded_tag; if(type_tag <= 30) - encoded_tag.append(static_cast<byte>(type_tag | class_tag)); + encoded_tag.push_back(static_cast<byte>(type_tag | class_tag)); else { u32bit blocks = high_bit(type_tag) + 6; blocks = (blocks - (blocks % 7)) / 7; - encoded_tag.append(class_tag | 0x1F); + encoded_tag.push_back(class_tag | 0x1F); for(u32bit k = 0; k != blocks - 1; ++k) - encoded_tag.append(0x80 | ((type_tag >> 7*(blocks-k-1)) & 0x7F)); - encoded_tag.append(type_tag & 0x7F); + encoded_tag.push_back(0x80 | ((type_tag >> 7*(blocks-k-1)) & 0x7F)); + encoded_tag.push_back(type_tag & 0x7F); } return encoded_tag; @@ -50,13 +50,13 @@ SecureVector<byte> encode_length(u32bit length) { SecureVector<byte> encoded_length; if(length <= 127) - encoded_length.append(static_cast<byte>(length)); + encoded_length.push_back(static_cast<byte>(length)); else { const u32bit top_byte = significant_bytes(length); - encoded_length.append(static_cast<byte>(0x80 | top_byte)); + encoded_length.push_back(static_cast<byte>(0x80 | top_byte)); for(u32bit j = 4-top_byte; j != 4; ++j) - encoded_length.append(get_byte(j, length)); + encoded_length.push_back(get_byte(j, length)); } return encoded_length; } @@ -70,24 +70,21 @@ SecureVector<byte> DER_Encoder::DER_Sequence::get_contents() { const ASN1_Tag real_class_tag = ASN1_Tag(class_tag | CONSTRUCTED); - SecureVector<byte> encoded_tag = encode_tag(type_tag, real_class_tag); - if(type_tag == SET) { std::sort(set_contents.begin(), set_contents.end()); for(u32bit j = 0; j != set_contents.size(); ++j) - contents.append(set_contents[j]); + contents += set_contents[j]; set_contents.clear(); } - SecureVector<byte> encoded_length = encode_length(contents.size()); - - SecureVector<byte> retval; - retval.append(encoded_tag); - retval.append(encoded_length); - retval.append(contents); + SecureVector<byte> result; + result += encode_tag(type_tag, real_class_tag); + result += encode_length(contents.size()); + result += contents; contents.clear(); - return retval; + + return result; } /* @@ -98,7 +95,7 @@ void DER_Encoder::DER_Sequence::add_bytes(const byte data[], u32bit length) if(type_tag == SET) set_contents.push_back(SecureVector<byte>(data, length)); else - contents.append(data, length); + contents += std::make_pair(data, length); } /* @@ -191,7 +188,7 @@ DER_Encoder& DER_Encoder::raw_bytes(const byte bytes[], u32bit length) if(subsequences.size()) subsequences[subsequences.size()-1].add_bytes(bytes, length); else - contents.append(bytes, length); + contents += std::make_pair(bytes, length); return (*this); } @@ -314,8 +311,8 @@ DER_Encoder& DER_Encoder::encode(const byte bytes[], u32bit length, if(real_type == BIT_STRING) { SecureVector<byte> encoded; - encoded.append(0); - encoded.append(bytes, length); + encoded.push_back(0); + encoded += std::make_pair(bytes, length); return add_object(type_tag, class_tag, encoded); } else @@ -347,13 +344,10 @@ DER_Encoder& DER_Encoder::encode(const ASN1_Object& obj) DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const byte rep[], u32bit length) { - SecureVector<byte> encoded_tag = encode_tag(type_tag, class_tag); - SecureVector<byte> encoded_length = encode_length(length); - SecureVector<byte> buffer; - buffer.append(encoded_tag); - buffer.append(encoded_length); - buffer.append(rep, length); + buffer += encode_tag(type_tag, class_tag); + buffer += encode_length(length); + buffer += std::make_pair(rep, length); return raw_bytes(buffer); } |