diff options
author | lloyd <[email protected]> | 2012-01-19 17:07:03 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-01-19 17:07:03 +0000 |
commit | 239241568d4d3ff14d2d1994e5829f3d548f2078 (patch) | |
tree | a21fe21d7c229f00ae06859dbe1768ead68e6d13 /src/tls/cert_req.cpp | |
parent | 30104a60568b392886c1d717a7ca006378552e4d (diff) |
Remove Handshake_Message::deserialize which was an unnecessary hook.
Instead deserialize directly in the constructors that are passed the
raw message data. This makes it easier to pass contextual information
needed for decoding (eg, version numbers) where necessary.
Diffstat (limited to 'src/tls/cert_req.cpp')
-rw-r--r-- | src/tls/cert_req.cpp | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/src/tls/cert_req.cpp b/src/tls/cert_req.cpp index 0168e4b7d..bdb25057c 100644 --- a/src/tls/cert_req.cpp +++ b/src/tls/cert_req.cpp @@ -37,29 +37,9 @@ Certificate_Req::Certificate_Req(Record_Writer& writer, } /** -* Serialize a Certificate Request message -*/ -MemoryVector<byte> Certificate_Req::serialize() const - { - MemoryVector<byte> buf; - - append_tls_length_value(buf, types, 1); - - for(size_t i = 0; i != names.size(); ++i) - { - DER_Encoder encoder; - encoder.encode(names[i]); - - append_tls_length_value(buf, encoder.get_contents(), 2); - } - - return buf; - } - -/** * Deserialize a Certificate Request message */ -void Certificate_Req::deserialize(const MemoryRegion<byte>& buf) +Certificate_Req::Certificate_Req(const MemoryRegion<byte>& buf) { if(buf.size() < 4) throw Decoding_Error("Certificate_Req: Bad certificate request"); @@ -96,43 +76,40 @@ void Certificate_Req::deserialize(const MemoryRegion<byte>& buf) } /** -* Create a new Certificate message +* Serialize a Certificate Request message */ -Certificate::Certificate(Record_Writer& writer, - TLS_Handshake_Hash& hash, - const std::vector<X509_Certificate>& cert_list) +MemoryVector<byte> Certificate_Req::serialize() const { - certs = cert_list; - send(writer, hash); - } + MemoryVector<byte> buf; -/** -* Serialize a Certificate message -*/ -MemoryVector<byte> Certificate::serialize() const - { - MemoryVector<byte> buf(3); + append_tls_length_value(buf, types, 1); - for(size_t i = 0; i != certs.size(); ++i) + for(size_t i = 0; i != names.size(); ++i) { - MemoryVector<byte> raw_cert = certs[i].BER_encode(); - const size_t cert_size = raw_cert.size(); - for(size_t i = 0; i != 3; ++i) - buf.push_back(get_byte<u32bit>(i+1, cert_size)); - buf += raw_cert; - } + DER_Encoder encoder; + encoder.encode(names[i]); - const size_t buf_size = buf.size() - 3; - for(size_t i = 0; i != 3; ++i) - buf[i] = get_byte<u32bit>(i+1, buf_size); + append_tls_length_value(buf, encoder.get_contents(), 2); + } return buf; } /** +* Create a new Certificate message +*/ +Certificate::Certificate(Record_Writer& writer, + TLS_Handshake_Hash& hash, + const std::vector<X509_Certificate>& cert_list) + { + certs = cert_list; + send(writer, hash); + } + +/** * Deserialize a Certificate message */ -void Certificate::deserialize(const MemoryRegion<byte>& buf) +Certificate::Certificate(const MemoryRegion<byte>& buf) { if(buf.size() < 3) throw Decoding_Error("Certificate: Message malformed"); @@ -163,4 +140,27 @@ void Certificate::deserialize(const MemoryRegion<byte>& buf) } } +/** +* Serialize a Certificate message +*/ +MemoryVector<byte> Certificate::serialize() const + { + MemoryVector<byte> buf(3); + + for(size_t i = 0; i != certs.size(); ++i) + { + MemoryVector<byte> raw_cert = certs[i].BER_encode(); + const size_t cert_size = raw_cert.size(); + for(size_t i = 0; i != 3; ++i) + buf.push_back(get_byte<u32bit>(i+1, cert_size)); + buf += raw_cert; + } + + const size_t buf_size = buf.size() - 3; + for(size_t i = 0; i != 3; ++i) + buf[i] = get_byte<u32bit>(i+1, buf_size); + + return buf; + } + } |