diff options
author | eroman <eroman@chromium.org> | 2015-08-05 16:00:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-08-05 23:01:30 +0000 |
commit | 8dca668477f982305daed4ffa81bdb2a441d9a6c (patch) | |
tree | c13035a237e0edb4dedd994c75718f897060c20a | |
parent | 669dda3d77f4ba264569fa37e7f12aa3fffd4df1 (diff) | |
download | chromium_src-8dca668477f982305daed4ffa81bdb2a441d9a6c.zip chromium_src-8dca668477f982305daed4ffa81bdb2a441d9a6c.tar.gz chromium_src-8dca668477f982305daed4ffa81bdb2a441d9a6c.tar.bz2 |
[refactor] move BitString from der/input.h --> der/parse_values.h
BUG=None
Review URL: https://codereview.chromium.org/1272743002
Cr-Commit-Position: refs/heads/master@{#341999}
-rw-r--r-- | net/cert/internal/verify_signed_data.cc | 1 | ||||
-rw-r--r-- | net/cert/internal/verify_signed_data_unittest.cc | 1 | ||||
-rw-r--r-- | net/der/input.cc | 6 | ||||
-rw-r--r-- | net/der/input.h | 25 | ||||
-rw-r--r-- | net/der/parse_values.cc | 6 | ||||
-rw-r--r-- | net/der/parse_values.h | 25 | ||||
-rw-r--r-- | net/der/parser.h | 2 |
7 files changed, 35 insertions, 31 deletions
diff --git a/net/cert/internal/verify_signed_data.cc b/net/cert/internal/verify_signed_data.cc index e61defe..db76c50 100644 --- a/net/cert/internal/verify_signed_data.cc +++ b/net/cert/internal/verify_signed_data.cc @@ -5,6 +5,7 @@ #include "net/cert/internal/verify_signed_data.h" #include "base/logging.h" +#include "net/der/parse_values.h" // TODO(eroman): There is no intention to implement this for non-OpenSSL. Remove // this branch once the migration is complete. This could have been done as a diff --git a/net/cert/internal/verify_signed_data_unittest.cc b/net/cert/internal/verify_signed_data_unittest.cc index 3f8bf07..879bca0 100644 --- a/net/cert/internal/verify_signed_data_unittest.cc +++ b/net/cert/internal/verify_signed_data_unittest.cc @@ -12,6 +12,7 @@ #include "net/cert/internal/signature_algorithm.h" #include "net/cert/pem_tokenizer.h" #include "net/der/input.h" +#include "net/der/parse_values.h" #include "net/der/parser.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/net/der/input.cc b/net/der/input.cc index b5388a5..45edfdc 100644 --- a/net/der/input.cc +++ b/net/der/input.cc @@ -23,12 +23,6 @@ bool Input::Equals(const Input& other) const { return memcmp(data_, other.data_, len_) == 0; } -BitString::BitString(const Input& bytes, uint8_t unused_bits) - : bytes_(bytes), unused_bits_(unused_bits) { - DCHECK_LT(unused_bits, 8); - DCHECK(unused_bits == 0 || bytes.Length() != 0); -} - ByteReader::ByteReader(const Input& in) : data_(in.UnsafeData()), len_(in.Length()) { } diff --git a/net/der/input.h b/net/der/input.h index c5f9a94..f8eb467 100644 --- a/net/der/input.h +++ b/net/der/input.h @@ -66,31 +66,6 @@ class NET_EXPORT_PRIVATE Input { size_t len_; }; -// The BitString class is a helper for representing a valid parsed BIT STRING. -// -// * The bits are ordered within each octet of bytes() from most to least -// significant, as in the DER encoding. -// -// * There may be at most 7 unused bits. -class NET_EXPORT BitString { - public: - BitString() : unused_bits_(0) {} - - // |unused_bits| represents the number of bits in the last octet of |bytes|, - // starting from the least significant bit, that are unused. It MUST be < 8. - // And if bytes is empty, then it MUST be 0. - BitString(const Input& bytes, uint8_t unused_bits); - - const Input& bytes() const { return bytes_; } - uint8_t unused_bits() const { return unused_bits_; } - - private: - Input bytes_; - uint8_t unused_bits_; - - // Default assignment and copy constructor are OK. -}; - // This class provides ways to read data from an Input in a bounds-checked way. // The ByteReader is designed to read through the input sequentially. Once a // byte has been read with a ByteReader, the caller can't go back and re-read diff --git a/net/der/parse_values.cc b/net/der/parse_values.cc index aebfc53..93e99b7 100644 --- a/net/der/parse_values.cc +++ b/net/der/parse_values.cc @@ -164,6 +164,12 @@ bool ParseUint64(const Input& in, uint64_t* out) { return true; } +BitString::BitString(const Input& bytes, uint8_t unused_bits) + : bytes_(bytes), unused_bits_(unused_bits) { + DCHECK_LT(unused_bits, 8); + DCHECK(unused_bits == 0 || bytes.Length() != 0); +} + bool ParseBitString(const Input& in, BitString* out) { ByteReader reader(in); diff --git a/net/der/parse_values.h b/net/der/parse_values.h index 1b54675..39c3c02 100644 --- a/net/der/parse_values.h +++ b/net/der/parse_values.h @@ -30,6 +30,31 @@ NET_EXPORT bool ParseBoolRelaxed(const Input& in, bool* out) WARN_UNUSED_RESULT; // uint64_t, is negative, or if there is an error reading the integer. NET_EXPORT bool ParseUint64(const Input& in, uint64_t* out) WARN_UNUSED_RESULT; +// The BitString class is a helper for representing a valid parsed BIT STRING. +// +// * The bits are ordered within each octet of bytes() from most to least +// significant, as in the DER encoding. +// +// * There may be at most 7 unused bits. +class NET_EXPORT BitString { + public: + BitString() : unused_bits_(0) {} + + // |unused_bits| represents the number of bits in the last octet of |bytes|, + // starting from the least significant bit, that are unused. It MUST be < 8. + // And if bytes is empty, then it MUST be 0. + BitString(const Input& bytes, uint8_t unused_bits); + + const Input& bytes() const { return bytes_; } + uint8_t unused_bits() const { return unused_bits_; } + + private: + Input bytes_; + uint8_t unused_bits_; + + // Default assignment and copy constructor are OK. +}; + // Reads a DER-encoded ASN.1 BIT STRING value from |in| and puts the resulting // octet string and number of unused bits into |bit_string| // diff --git a/net/der/parser.h b/net/der/parser.h index 706ec43..37f1f85 100644 --- a/net/der/parser.h +++ b/net/der/parser.h @@ -15,6 +15,8 @@ namespace net { namespace der { +class BitString; + // Parses a DER-encoded ASN.1 structure. DER (distinguished encoding rules) // encodes each data value with a tag, length, and value (TLV). The tag // indicates the type of the ASN.1 value. Depending on the type of the value, |