diff options
-rw-r--r-- | src/asn1/asn1_oid.cpp | 40 | ||||
-rw-r--r-- | src/asn1/asn1_str.cpp | 4 | ||||
-rw-r--r-- | src/asn1/asn1_tm.cpp | 8 | ||||
-rw-r--r-- | src/asn1/ber_dec.cpp | 42 | ||||
-rw-r--r-- | src/asn1/ber_dec.h | 2 | ||||
-rw-r--r-- | src/asn1/der_enc.cpp | 42 | ||||
-rw-r--r-- | src/asn1/der_enc.h | 14 |
7 files changed, 77 insertions, 75 deletions
diff --git a/src/asn1/asn1_oid.cpp b/src/asn1/asn1_oid.cpp index 820492e18..ae3d48ce2 100644 --- a/src/asn1/asn1_oid.cpp +++ b/src/asn1/asn1_oid.cpp @@ -50,10 +50,10 @@ void OID::clear() std::string OID::as_string() const { std::string oid_str; - for(u32bit j = 0; j != id.size(); ++j) + for(size_t i = 0; i != id.size(); ++i) { - oid_str += to_string(id[j]); - if(j != id.size() - 1) + oid_str += to_string(id[i]); + if(i != id.size() - 1) oid_str += '.'; } return oid_str; @@ -66,8 +66,8 @@ bool OID::operator==(const OID& oid) const { if(id.size() != oid.id.size()) return false; - for(u32bit j = 0; j != id.size(); ++j) - if(id[j] != oid.id[j]) + for(size_t i = 0; i != id.size(); ++i) + if(id[i] != oid.id[i]) return false; return true; } @@ -111,11 +111,11 @@ bool operator<(const OID& a, const OID& b) return true; if(oid1.size() > oid2.size()) return false; - for(u32bit j = 0; j != oid1.size(); ++j) + for(size_t i = 0; i != oid1.size(); ++i) { - if(oid1[j] < oid2[j]) + if(oid1[i] < oid2[i]) return true; - if(oid1[j] > oid2[j]) + if(oid1[i] > oid2[i]) return false; } return false; @@ -132,18 +132,18 @@ void OID::encode_into(DER_Encoder& der) const MemoryVector<byte> encoding; encoding.push_back(40 * id[0] + id[1]); - for(u32bit j = 2; j != id.size(); ++j) + for(size_t i = 2; i != id.size(); ++i) { - if(id[j] == 0) + if(id[i] == 0) encoding.push_back(0); else { - u32bit blocks = high_bit(id[j]) + 6; + size_t blocks = high_bit(id[i]) + 6; blocks = (blocks - (blocks % 7)) / 7; - for(u32bit k = 0; k != blocks - 1; ++k) - encoding.push_back(0x80 | ((id[j] >> 7*(blocks-k-1)) & 0x7F)); - encoding.push_back(id[j] & 0x7F); + for(size_t j = 0; j != blocks - 1; ++j) + encoding.push_back(0x80 | ((id[i] >> 7*(blocks-j-1)) & 0x7F)); + encoding.push_back(id[i] & 0x7F); } } der.add_object(OBJECT_ID, UNIVERSAL, encoding); @@ -166,15 +166,15 @@ void OID::decode_from(BER_Decoder& decoder) id.push_back(obj.value[0] / 40); id.push_back(obj.value[0] % 40); - u32bit j = 0; - while(j != obj.value.size() - 1) + size_t i = 0; + while(i != obj.value.size() - 1) { u32bit component = 0; - while(j != obj.value.size() - 1) + while(i != obj.value.size() - 1) { - ++j; - component = (component << 7) + (obj.value[j] & 0x7F); - if(!(obj.value[j] & 0x80)) + ++i; + component = (component << 7) + (obj.value[i] & 0x7F); + if(!(obj.value[i] & 0x80)) break; } id.push_back(component); diff --git a/src/asn1/asn1_str.cpp b/src/asn1/asn1_str.cpp index 25782e239..3d79674ec 100644 --- a/src/asn1/asn1_str.cpp +++ b/src/asn1/asn1_str.cpp @@ -45,9 +45,9 @@ ASN1_Tag choose_encoding(const std::string& str, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - for(u32bit j = 0; j != str.size(); ++j) + for(size_t i = 0; i != str.size(); ++i) { - if(!IS_PRINTABLE[static_cast<byte>(str[j])]) + if(!IS_PRINTABLE[static_cast<byte>(str[i])]) { if(type == "utf8") return UTF8_STRING; if(type == "latin1") return T61_STRING; diff --git a/src/asn1/asn1_tm.cpp b/src/asn1/asn1_tm.cpp index 54af6154f..a059e0528 100644 --- a/src/asn1/asn1_tm.cpp +++ b/src/asn1/asn1_tm.cpp @@ -62,7 +62,7 @@ void X509_Time::set_to(const std::string& time_str) std::vector<std::string> params; std::string current; - for(u32bit j = 0; j != time_str.size(); ++j) + for(size_t j = 0; j != time_str.size(); ++j) { if(Charset::is_digit(time_str[j])) current += time_str[j]; @@ -109,17 +109,17 @@ void X509_Time::set_to(const std::string& t_spec, ASN1_Tag spec_tag) if(t_spec[t_spec.size()-1] != 'Z') throw Invalid_Argument("Invalid time encoding: " + t_spec); - const u32bit YEAR_SIZE = (spec_tag == UTC_TIME) ? 2 : 4; + const size_t YEAR_SIZE = (spec_tag == UTC_TIME) ? 2 : 4; std::vector<std::string> params; std::string current; - for(u32bit j = 0; j != YEAR_SIZE; ++j) + for(size_t j = 0; j != YEAR_SIZE; ++j) current += t_spec[j]; params.push_back(current); current.clear(); - for(u32bit j = YEAR_SIZE; j != t_spec.size() - 1; ++j) + for(size_t j = YEAR_SIZE; j != t_spec.size() - 1; ++j) { current += t_spec[j]; if(current.size() == 2) diff --git a/src/asn1/ber_dec.cpp b/src/asn1/ber_dec.cpp index 7f0459e22..e98ab3b61 100644 --- a/src/asn1/ber_dec.cpp +++ b/src/asn1/ber_dec.cpp @@ -16,7 +16,7 @@ namespace { /* * BER decode an ASN.1 type tag */ -u32bit decode_tag(DataSource* ber, ASN1_Tag& type_tag, ASN1_Tag& class_tag) +size_t decode_tag(DataSource* ber, ASN1_Tag& type_tag, ASN1_Tag& class_tag) { byte b; if(!ber->read_byte(b)) @@ -32,10 +32,10 @@ u32bit decode_tag(DataSource* ber, ASN1_Tag& type_tag, ASN1_Tag& class_tag) return 1; } - u32bit tag_bytes = 1; + size_t tag_bytes = 1; class_tag = ASN1_Tag(b & 0xE0); - u32bit tag_buf = 0; + size_t tag_buf = 0; while(true) { if(!ber->read_byte(b)) @@ -53,12 +53,12 @@ u32bit decode_tag(DataSource* ber, ASN1_Tag& type_tag, ASN1_Tag& class_tag) /* * Find the EOC marker */ -u32bit find_eoc(DataSource*); +size_t find_eoc(DataSource*); /* * BER decode an ASN.1 length field */ -u32bit decode_length(DataSource* ber, u32bit& field_size) +size_t decode_length(DataSource* ber, size_t& field_size) { byte b; if(!ber->read_byte(b)) @@ -72,9 +72,9 @@ u32bit decode_length(DataSource* ber, u32bit& field_size) if(field_size > 5) throw BER_Decoding_Error("Length field is too large"); - u32bit length = 0; + size_t length = 0; - for(u32bit j = 0; j != field_size - 1; ++j) + for(size_t i = 0; i != field_size - 1; ++i) { if(get_byte(0, length) != 0) throw BER_Decoding_Error("Field length overflow"); @@ -88,22 +88,22 @@ u32bit decode_length(DataSource* ber, u32bit& field_size) /* * BER decode an ASN.1 length field */ -u32bit decode_length(DataSource* ber) +size_t decode_length(DataSource* ber) { - u32bit dummy; + size_t dummy; return decode_length(ber, dummy); } /* * Find the EOC marker */ -u32bit find_eoc(DataSource* ber) +size_t find_eoc(DataSource* ber) { SecureVector<byte> buffer(DEFAULT_BUFFERSIZE), data; while(true) { - const u32bit got = ber->peek(&buffer[0], buffer.size(), data.size()); + const size_t got = ber->peek(&buffer[0], buffer.size(), data.size()); if(got == 0) break; @@ -113,16 +113,16 @@ u32bit find_eoc(DataSource* ber) DataSource_Memory source(data); data.clear(); - u32bit length = 0; + size_t length = 0; while(true) { ASN1_Tag type_tag, class_tag; - u32bit tag_size = decode_tag(&source, type_tag, class_tag); + size_t tag_size = decode_tag(&source, type_tag, class_tag); if(type_tag == NO_OBJECT) break; - u32bit length_size = 0; - u32bit item_size = decode_length(&source, length_size); + size_t length_size = 0; + size_t item_size = decode_length(&source, length_size); source.discard_next(item_size); length += item_size + length_size + tag_size; @@ -205,7 +205,7 @@ BER_Object BER_Decoder::get_next_object() if(next.type_tag == NO_OBJECT) return next; - u32bit length = decode_length(source); + size_t length = decode_length(source); next.value.resize(length); if(source->read(&next.value[0], length) != length) throw BER_Decoding_Error("Value truncated"); @@ -266,7 +266,7 @@ BER_Decoder::BER_Decoder(DataSource& src) /* * BER_Decoder Constructor */ -BER_Decoder::BER_Decoder(const byte data[], u32bit length) +BER_Decoder::BER_Decoder(const byte data[], size_t length) { source = new DataSource_Memory(data, length); owns = true; @@ -416,11 +416,11 @@ BER_Decoder& BER_Decoder::decode(BigInt& out, if(negative) { - for(u32bit j = obj.value.size(); j > 0; --j) - if(obj.value[j-1]--) + for(size_t i = obj.value.size(); i > 0; --i) + if(obj.value[i-1]--) break; - for(u32bit j = 0; j != obj.value.size(); ++j) - obj.value[j] = ~obj.value[j]; + for(size_t i = 0; i != obj.value.size(); ++i) + obj.value[i] = ~obj.value[i]; } out = BigInt(&obj.value[0], obj.value.size()); diff --git a/src/asn1/ber_dec.h b/src/asn1/ber_dec.h index 52e309aec..8dddcb7f4 100644 --- a/src/asn1/ber_dec.h +++ b/src/asn1/ber_dec.h @@ -75,7 +75,7 @@ class BOTAN_DLL BER_Decoder ASN1_Tag, u16bit); BER_Decoder(DataSource&); - BER_Decoder(const byte[], u32bit); + BER_Decoder(const byte[], size_t); BER_Decoder(const MemoryRegion<byte>&); BER_Decoder(const BER_Decoder&); ~BER_Decoder(); diff --git a/src/asn1/der_enc.cpp b/src/asn1/der_enc.cpp index affb40372..c6ceaf86d 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); } diff --git a/src/asn1/der_enc.h b/src/asn1/der_enc.h index ae10b4bc8..b3fce389d 100644 --- a/src/asn1/der_enc.h +++ b/src/asn1/der_enc.h @@ -30,7 +30,7 @@ class BOTAN_DLL DER_Encoder DER_Encoder& start_explicit(u16bit); DER_Encoder& end_explicit(); - DER_Encoder& raw_bytes(const byte[], u32bit); + DER_Encoder& raw_bytes(const byte[], size_t); DER_Encoder& raw_bytes(const MemoryRegion<byte>&); DER_Encoder& encode_null(); @@ -38,7 +38,7 @@ class BOTAN_DLL DER_Encoder DER_Encoder& encode(u32bit); DER_Encoder& encode(const BigInt&); DER_Encoder& encode(const MemoryRegion<byte>&, ASN1_Tag); - DER_Encoder& encode(const byte[], u32bit, ASN1_Tag); + DER_Encoder& encode(const byte[], size_t, ASN1_Tag); DER_Encoder& encode(bool, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); DER_Encoder& encode(u32bit, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); @@ -46,7 +46,7 @@ class BOTAN_DLL DER_Encoder ASN1_Tag = CONTEXT_SPECIFIC); DER_Encoder& encode(const MemoryRegion<byte>&, ASN1_Tag, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); - DER_Encoder& encode(const byte[], u32bit, ASN1_Tag, + DER_Encoder& encode(const byte[], size_t, ASN1_Tag, ASN1_Tag, ASN1_Tag = CONTEXT_SPECIFIC); template<typename T> @@ -60,15 +60,15 @@ class BOTAN_DLL DER_Encoder template<typename T> DER_Encoder& encode_list(const std::vector<T>& values) { - for(u32bit j = 0; j != values.size(); ++j) - encode(values[j]); + for(size_t i = 0; i != values.size(); ++i) + encode(values[i]); return (*this); } DER_Encoder& encode(const ASN1_Object&); DER_Encoder& encode_if(bool, DER_Encoder&); - DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const byte[], u32bit); + DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const byte[], size_t); DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const MemoryRegion<byte>&); DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, const std::string&); DER_Encoder& add_object(ASN1_Tag, ASN1_Tag, byte); @@ -78,7 +78,7 @@ class BOTAN_DLL DER_Encoder public: ASN1_Tag tag_of() const; SecureVector<byte> get_contents(); - void add_bytes(const byte[], u32bit); + void add_bytes(const byte[], size_t); DER_Sequence(ASN1_Tag, ASN1_Tag); private: ASN1_Tag type_tag, class_tag; |