Chromium Code Reviews| Index: crypto/secure_hash_default.cc |
| diff --git a/crypto/secure_hash_default.cc b/crypto/secure_hash_default.cc |
| index d85754a8e37d8ccbddcc0eaf64caf6c13dca5a70..1da77fccde80284abb29ac69d1547a9b2ddb6d19 100644 |
| --- a/crypto/secure_hash_default.cc |
| +++ b/crypto/secure_hash_default.cc |
| @@ -5,6 +5,7 @@ |
| #include "crypto/secure_hash.h" |
| #include "base/logging.h" |
| +#include "base/pickle.h" |
| #include "crypto/third_party/nss/chromium-blapi.h" |
| #include "crypto/third_party/nss/chromium-sha256.h" |
| @@ -14,6 +15,9 @@ namespace { |
| class SecureHashSHA256NSS : public SecureHash { |
| public: |
| + static const int kSecureHashVersion = 1; |
| + static const char* kDescriptor; |
| + |
| SecureHashSHA256NSS() { |
| SHA256_Begin(&ctx_); |
| } |
| @@ -30,10 +34,58 @@ class SecureHashSHA256NSS : public SecureHash { |
| static_cast<unsigned int>(len)); |
| } |
| + virtual bool Serialize(Pickle* pickle); |
| + virtual bool Deserialize(Pickle* pickle); |
| + |
| private: |
| SHA256Context ctx_; |
| }; |
| +const char* SecureHashSHA256NSS::kDescriptor = "NSS"; |
|
agl
2011/11/18 19:57:02
Move it out of the class and do:
static const cha
ahendrickson
2011/11/18 21:23:09
Done.
|
| + |
| +bool SecureHashSHA256NSS::Serialize(Pickle* pickle) { |
| + if (!pickle) |
| + return false; |
| + |
| + if (!pickle->WriteInt(kSecureHashVersion)) |
|
agl
2011/11/18 19:57:02
if (!pickle->WriteInt(kSecureHashVersion) ||
!
ahendrickson
2011/11/18 21:23:09
Done.
|
| + return false; |
| + if (!pickle->WriteString(kDescriptor)) |
| + return false; |
| + if (!pickle->WriteBytes(&ctx_, sizeof(ctx_))) |
| + return false; |
| + |
| + return true; |
| +} |
| + |
| +bool SecureHashSHA256NSS::Deserialize(Pickle* pickle) { |
|
agl
2011/11/18 19:57:02
this interface (specifically the lack of a void* i
ahendrickson
2011/11/18 21:23:09
Fixed.
|
| + if (!pickle) |
| + return false; |
| + |
| + void* data_iterator = NULL; |
| + int version; |
| + if (!pickle->ReadInt(&data_iterator, &version)) |
| + return false; |
| + |
| + if (version > kSecureHashVersion) |
| + return false; // We don't know how to deal with this. |
| + |
| + std::string type; |
| + if (!pickle->ReadString(&data_iterator, &type)) |
| + return false; |
| + |
| + if (type != kDescriptor) |
| + return false; // It's the wrong kind. |
| + |
| + char data_buffer[sizeof(ctx_)] = ""; |
|
agl
2011/11/18 19:57:02
Pickle doesn't need a buffer to write it. It sets
ahendrickson
2011/11/18 21:23:09
Done.
|
| + const char* data = data_buffer; |
| + if (!pickle->ReadBytes(&data_iterator, &data, sizeof(ctx_))) |
| + return false; |
| + |
| + memcpy(&ctx_, data, sizeof(ctx_)); |
| + |
| + return true; |
| +} |
| + |
| } // namespace |
| SecureHash* SecureHash::Create(Algorithm algorithm) { |