| Index: base/crypto/signature_creator_win.cc
|
| diff --git a/base/crypto/signature_creator_win.cc b/base/crypto/signature_creator_win.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..651ed7ac16df37d13191700a604f8fe8fba319a0
|
| --- /dev/null
|
| +++ b/base/crypto/signature_creator_win.cc
|
| @@ -0,0 +1,62 @@
|
| +// Copyright (c) 2009 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/crypto/signature_creator.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/scoped_ptr.h"
|
| +
|
| +namespace base {
|
| +
|
| +// static
|
| +SignatureCreator* SignatureCreator::Create(RSAPrivateKey* key) {
|
| + scoped_ptr<SignatureCreator> result(new SignatureCreator);
|
| + result->key_ = key;
|
| +
|
| + if (!CryptCreateHash(key->provider(), CALG_SHA1, 0, 0,
|
| + &result->hash_object_)) {
|
| + NOTREACHED();
|
| + return NULL;
|
| + }
|
| +
|
| + return result.release();
|
| +}
|
| +
|
| +SignatureCreator::~SignatureCreator() {
|
| + if (hash_object_) {
|
| + if (!CryptDestroyHash(hash_object_))
|
| + NOTREACHED();
|
| +
|
| + hash_object_ = 0;
|
| + }
|
| +}
|
| +
|
| +bool SignatureCreator::Update(const uint8* data_part, int data_part_len) {
|
| + if (!CryptHashData(hash_object_, data_part, data_part_len, 0)) {
|
| + NOTREACHED();
|
| + return false;
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| +bool SignatureCreator::Final(std::vector<uint8>* signature) {
|
| + DWORD signature_length = 0;
|
| + if (!CryptSignHash(hash_object_, AT_SIGNATURE, NULL, 0, NULL,
|
| + &signature_length)) {
|
| + return false;
|
| + }
|
| +
|
| + signature->resize(signature_length);
|
| + if (!CryptSignHash(hash_object_, AT_SIGNATURE, NULL, 0, &signature->front(),
|
| + &signature_length)) {
|
| + return false;
|
| + }
|
| +
|
| + signature->resize(signature_length);
|
| + hash_object_ = 0;
|
| + return true;
|
| +}
|
| +
|
| +} // namespace base
|
|
|