Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / child / webcrypto / nss / key_nss.h
blob39bd1961c4933d0e6b6869dc313887152b602b46
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_
6 #define CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_
8 #include <stdint.h>
9 #include <vector>
11 #include "crypto/scoped_nss_types.h"
12 #include "third_party/WebKit/public/platform/WebCryptoKey.h"
14 namespace content {
16 namespace webcrypto {
18 class CryptoData;
19 class PrivateKeyNss;
20 class PublicKeyNss;
21 class SymKeyNss;
23 // Base key class for all NSS keys, used to safely cast between types. Each key
24 // maintains a copy of its serialized form in either 'raw', 'pkcs8', or 'spki'
25 // format. This is to allow structured cloning of keys synchronously from the
26 // target Blink thread without having to lock access to the key.
27 class KeyNss : public blink::WebCryptoKeyHandle {
28 public:
29 explicit KeyNss(const CryptoData& serialized_key_data);
30 virtual ~KeyNss();
32 virtual SymKeyNss* AsSymKey();
33 virtual PublicKeyNss* AsPublicKey();
34 virtual PrivateKeyNss* AsPrivateKey();
36 const std::vector<uint8_t>& serialized_key_data() const {
37 return serialized_key_data_;
40 private:
41 const std::vector<uint8_t> serialized_key_data_;
44 class SymKeyNss : public KeyNss {
45 public:
46 virtual ~SymKeyNss();
47 SymKeyNss(crypto::ScopedPK11SymKey key, const CryptoData& raw_key_data);
49 static SymKeyNss* Cast(const blink::WebCryptoKey& key);
51 PK11SymKey* key() { return key_.get(); }
52 virtual SymKeyNss* AsSymKey() OVERRIDE;
54 const std::vector<uint8_t>& raw_key_data() const {
55 return serialized_key_data();
58 private:
59 crypto::ScopedPK11SymKey key_;
61 DISALLOW_COPY_AND_ASSIGN(SymKeyNss);
64 class PublicKeyNss : public KeyNss {
65 public:
66 virtual ~PublicKeyNss();
67 PublicKeyNss(crypto::ScopedSECKEYPublicKey key, const CryptoData& spki_data);
69 static PublicKeyNss* Cast(const blink::WebCryptoKey& key);
71 SECKEYPublicKey* key() { return key_.get(); }
72 virtual PublicKeyNss* AsPublicKey() OVERRIDE;
74 const std::vector<uint8_t>& spki_data() const {
75 return serialized_key_data();
78 private:
79 crypto::ScopedSECKEYPublicKey key_;
81 DISALLOW_COPY_AND_ASSIGN(PublicKeyNss);
84 class PrivateKeyNss : public KeyNss {
85 public:
86 virtual ~PrivateKeyNss();
87 PrivateKeyNss(crypto::ScopedSECKEYPrivateKey key,
88 const CryptoData& pkcs8_data);
90 static PrivateKeyNss* Cast(const blink::WebCryptoKey& key);
92 SECKEYPrivateKey* key() { return key_.get(); }
93 virtual PrivateKeyNss* AsPrivateKey() OVERRIDE;
95 const std::vector<uint8_t>& pkcs8_data() const {
96 return serialized_key_data();
99 private:
100 crypto::ScopedSECKEYPrivateKey key_;
102 DISALLOW_COPY_AND_ASSIGN(PrivateKeyNss);
105 } // namespace webcrypto
107 } // namespace content
109 #endif // CONTENT_CHILD_WEBCRYPTO_NSS_KEY_NSS_H_