Chromium Code Reviews| Index: base/secure_hash_nss.cc |
| diff --git a/base/secure_hash_nss.cc b/base/secure_hash_nss.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..900404362ad44739c2cfddcf39931de452e8b6e1 |
| --- /dev/null |
| +++ b/base/secure_hash_nss.cc |
| @@ -0,0 +1,49 @@ |
| +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/secure_hash.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/stl_util-inl.h" |
|
wtc
2011/01/25 19:06:43
Remove this header.
bulach
2011/01/25 20:33:41
Done.
|
| +#include "base/third_party/nss/blapi.h" |
| +#include "base/third_party/nss/sha256.h" |
| + |
| +namespace base { |
| + |
| +namespace { |
| + |
| +class SecureHashSHA256NSS : public SecureHash { |
| + public: |
| + SecureHashSHA256NSS() { |
| + SHA256_Begin(&ctx_); |
| + } |
| + |
| + virtual ~SecureHashSHA256NSS() { |
| + } |
| + |
| + virtual void Update(const std::string& str) { |
| + SHA256_Update(&ctx_, reinterpret_cast<const unsigned char*>(str.data()), |
| + static_cast<unsigned int>(str.length())); |
| + |
| + } |
| + |
| + virtual void Finish(void* output, size_t len) { |
| + SHA256_End(&ctx_, static_cast<unsigned char*>(output), NULL, |
| + static_cast<unsigned int>(len)); |
| + } |
| + |
| + private: |
| + ::SHA256Context ctx_; |
|
wtc
2011/01/25 19:06:43
Nit: you can remove :: now.
bulach
2011/01/25 20:33:41
Done.
|
| +}; |
| + |
| +} // namespace |
| + |
| +SecureHash* SecureHash::Create(Type type) { |
| + if (type == TYPE_SHA256) |
| + return new SecureHashSHA256NSS(); |
| + NOTIMPLEMENTED(); |
| + return NULL; |
|
wtc
2011/01/25 19:06:43
Please use a switch statement to make it easy to a
bulach
2011/01/25 20:33:41
Done.
|
| +} |
| + |
| +} // namespace base |