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

Unified Diff: content/child/webcrypto/nss/key_nss.h

Issue 379383002: Refactor WebCrypto code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase onto master (no longer has BoringSSL) Created 6 years, 5 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/hmac_nss.cc ('k') | content/child/webcrypto/nss/key_nss.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/nss/key_nss.h
diff --git a/content/child/webcrypto/nss/key_nss.h b/content/child/webcrypto/nss/key_nss.h
new file mode 100644
index 0000000000000000000000000000000000000000..f1980e27ad7ff7f4e04a4d506eaf02534834eea1
--- /dev/null
+++ b/content/child/webcrypto/nss/key_nss.h
@@ -0,0 +1,102 @@
+// 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.
+
+#ifndef CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_
+#define CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_
+
+#include "content/child/webcrypto/algorithm_implementation.h"
+
+#include "crypto/scoped_nss_types.h"
+
+namespace content {
+
+namespace webcrypto {
+
+class PrivateKeyNss;
+class PublicKeyNss;
+class SymKeyNss;
+
+// Base key class for all NSS keys, used to safely cast between types. Each key
+// maintains a copy of its serialized form in either 'raw', 'pkcs8', or 'spki'
+// format. This is to allow structured cloning of keys synchronously from the
+// target Blink thread without having to lock access to the key.
+class KeyNss : public blink::WebCryptoKeyHandle {
+ public:
+ explicit KeyNss(const CryptoData& serialized_key_data);
+ virtual ~KeyNss();
+
+ virtual SymKeyNss* AsSymKey();
+ virtual PublicKeyNss* AsPublicKey();
+ virtual PrivateKeyNss* AsPrivateKey();
+
+ const std::vector<uint8>& serialized_key_data() const {
+ return serialized_key_data_;
+ }
+
+ private:
+ const std::vector<uint8> serialized_key_data_;
+};
+
+class SymKeyNss : public KeyNss {
+ public:
+ virtual ~SymKeyNss();
+ SymKeyNss(crypto::ScopedPK11SymKey key, const CryptoData& raw_key_data);
+
+ static SymKeyNss* Cast(const blink::WebCryptoKey& key);
+
+ PK11SymKey* key() { return key_.get(); }
+ virtual SymKeyNss* AsSymKey() OVERRIDE;
+
+ const std::vector<uint8>& raw_key_data() const {
+ return serialized_key_data();
+ }
+
+ private:
+ crypto::ScopedPK11SymKey key_;
+
+ DISALLOW_COPY_AND_ASSIGN(SymKeyNss);
+};
+
+class PublicKeyNss : public KeyNss {
+ public:
+ virtual ~PublicKeyNss();
+ PublicKeyNss(crypto::ScopedSECKEYPublicKey key, const CryptoData& spki_data);
+
+ static PublicKeyNss* Cast(const blink::WebCryptoKey& key);
+
+ SECKEYPublicKey* key() { return key_.get(); }
+ virtual PublicKeyNss* AsPublicKey() OVERRIDE;
+
+ const std::vector<uint8>& spki_data() const { return serialized_key_data(); }
+
+ private:
+ crypto::ScopedSECKEYPublicKey key_;
+
+ DISALLOW_COPY_AND_ASSIGN(PublicKeyNss);
+};
+
+class PrivateKeyNss : public KeyNss {
+ public:
+ virtual ~PrivateKeyNss();
+ PrivateKeyNss(crypto::ScopedSECKEYPrivateKey key,
+ const CryptoData& pkcs8_data);
+
+ static PrivateKeyNss* Cast(const blink::WebCryptoKey& key);
+
+ SECKEYPrivateKey* key() { return key_.get(); }
+ virtual PrivateKeyNss* AsPrivateKey() OVERRIDE;
+
+ const std::vector<uint8>& pkcs8_data() const { return serialized_key_data(); }
+
+ private:
+ crypto::ScopedSECKEYPrivateKey key_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrivateKeyNss);
+};
+
+} // namespace webcrypto
+
+} // namespace content
+
+#endif // CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_
« no previous file with comments | « content/child/webcrypto/nss/hmac_nss.cc ('k') | content/child/webcrypto/nss/key_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698