Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(879)

Unified Diff: content/child/webcrypto/nss/sym_key_nss.cc

Issue 1077273002: html_viewer: Move webcrypto to a place where html_viewer can use it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to ToT Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/child/webcrypto/nss/sym_key_nss.h ('k') | content/child/webcrypto/nss/util_nss.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/nss/sym_key_nss.cc
diff --git a/content/child/webcrypto/nss/sym_key_nss.cc b/content/child/webcrypto/nss/sym_key_nss.cc
deleted file mode 100644
index 53efeb0dd87a6e77bfe1f5274ee65adc94e5b3f6..0000000000000000000000000000000000000000
--- a/content/child/webcrypto/nss/sym_key_nss.cc
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright 2014 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 "content/child/webcrypto/nss/sym_key_nss.h"
-
-#include "base/logging.h"
-#include "content/child/webcrypto/crypto_data.h"
-#include "content/child/webcrypto/generate_key_result.h"
-#include "content/child/webcrypto/nss/key_nss.h"
-#include "content/child/webcrypto/nss/util_nss.h"
-#include "content/child/webcrypto/status.h"
-#include "content/child/webcrypto/webcrypto_util.h"
-#include "crypto/scoped_nss_types.h"
-#include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
-
-namespace content {
-
-namespace webcrypto {
-
-Status GenerateSecretKeyNss(const blink::WebCryptoKeyAlgorithm& algorithm,
- bool extractable,
- blink::WebCryptoKeyUsageMask usages,
- unsigned int keylen_bits,
- CK_MECHANISM_TYPE mechanism,
- GenerateKeyResult* result) {
- DCHECK_NE(CKM_INVALID_MECHANISM, mechanism);
-
- crypto::ScopedPK11Slot slot(PK11_GetInternalKeySlot());
- if (!slot)
- return Status::OperationError();
-
- std::vector<uint8_t> bytes(NumBitsToBytes(keylen_bits));
- if (bytes.size() > 0) {
- if (PK11_GenerateRandom(&bytes[0], bytes.size()) != SECSuccess)
- return Status::OperationError();
- TruncateToBitLength(keylen_bits, &bytes);
- }
-
- blink::WebCryptoKey key;
- Status status = ImportKeyRawNss(CryptoData(bytes), algorithm, extractable,
- usages, mechanism, &key);
- if (status.IsError())
- return status;
-
- result->AssignSecretKey(key);
- return Status::Success();
-}
-
-Status ImportKeyRawNss(const CryptoData& key_data,
- const blink::WebCryptoKeyAlgorithm& algorithm,
- bool extractable,
- blink::WebCryptoKeyUsageMask usages,
- CK_MECHANISM_TYPE mechanism,
- blink::WebCryptoKey* key) {
- // The usages are enforced at the WebCrypto layer, so it isn't necessary to
- // create keys with limited usages.
- CK_FLAGS flags = kAllOperationFlags;
-
- DCHECK(!algorithm.isNull());
- SECItem key_item = MakeSECItemForBuffer(key_data);
-
- crypto::ScopedPK11Slot slot(PK11_GetInternalSlot());
- crypto::ScopedPK11SymKey pk11_sym_key(PK11_ImportSymKeyWithFlags(
- slot.get(), mechanism, PK11_OriginUnwrap, CKA_FLAGS_ONLY, &key_item,
- flags, false, NULL));
- if (!pk11_sym_key.get())
- return Status::OperationError();
-
- scoped_ptr<SymKeyNss> handle(new SymKeyNss(pk11_sym_key.Pass(), key_data));
-
- *key = blink::WebCryptoKey::create(handle.release(),
- blink::WebCryptoKeyTypeSecret, extractable,
- algorithm, usages);
- return Status::Success();
-}
-
-} // namespace webcrypto
-
-} // namespace content
« no previous file with comments | « content/child/webcrypto/nss/sym_key_nss.h ('k') | content/child/webcrypto/nss/util_nss.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698