Add a stub __cxa_demangle to disable LLVM's demangler.
[chromium-blink-merge.git] / components / webcrypto / nss / key_nss.h
blobe3127d8d58fe003f32b711cce6fb9c1aef512602
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 COMPONENTS_WEBCRYPTO_NSS_KEY_NSS_H_
6 #define COMPONENTS_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 webcrypto {
16 class CryptoData;
17 class PrivateKeyNss;
18 class PublicKeyNss;
19 class SymKeyNss;
21 // Base key class for all NSS keys, used to safely cast between types. Each key
22 // maintains a copy of its serialized form in either 'raw', 'pkcs8', or 'spki'
23 // format. This is to allow structured cloning of keys synchronously from the
24 // target Blink thread without having to lock access to the key.
25 class KeyNss : public blink::WebCryptoKeyHandle {
26 public:
27 explicit KeyNss(const CryptoData& serialized_key_data);
28 ~KeyNss() override;
30 virtual SymKeyNss* AsSymKey();
31 virtual PublicKeyNss* AsPublicKey();
32 virtual PrivateKeyNss* AsPrivateKey();
34 const std::vector<uint8_t>& serialized_key_data() const {
35 return serialized_key_data_;
38 private:
39 const std::vector<uint8_t> serialized_key_data_;
42 class SymKeyNss : public KeyNss {
43 public:
44 ~SymKeyNss() override;
45 SymKeyNss(crypto::ScopedPK11SymKey key, const CryptoData& raw_key_data);
47 static SymKeyNss* Cast(const blink::WebCryptoKey& key);
49 PK11SymKey* key() { return key_.get(); }
50 SymKeyNss* AsSymKey() override;
52 const std::vector<uint8_t>& raw_key_data() const {
53 return serialized_key_data();
56 private:
57 crypto::ScopedPK11SymKey key_;
59 DISALLOW_COPY_AND_ASSIGN(SymKeyNss);
62 class PublicKeyNss : public KeyNss {
63 public:
64 ~PublicKeyNss() override;
65 PublicKeyNss(crypto::ScopedSECKEYPublicKey key, const CryptoData& spki_data);
67 static PublicKeyNss* Cast(const blink::WebCryptoKey& key);
69 SECKEYPublicKey* key() { return key_.get(); }
70 PublicKeyNss* AsPublicKey() override;
72 const std::vector<uint8_t>& spki_data() const {
73 return serialized_key_data();
76 private:
77 crypto::ScopedSECKEYPublicKey key_;
79 DISALLOW_COPY_AND_ASSIGN(PublicKeyNss);
82 class PrivateKeyNss : public KeyNss {
83 public:
84 ~PrivateKeyNss() override;
85 PrivateKeyNss(crypto::ScopedSECKEYPrivateKey key,
86 const CryptoData& pkcs8_data);
88 static PrivateKeyNss* Cast(const blink::WebCryptoKey& key);
90 SECKEYPrivateKey* key() { return key_.get(); }
91 PrivateKeyNss* AsPrivateKey() override;
93 const std::vector<uint8_t>& pkcs8_data() const {
94 return serialized_key_data();
97 private:
98 crypto::ScopedSECKEYPrivateKey key_;
100 DISALLOW_COPY_AND_ASSIGN(PrivateKeyNss);
103 } // namespace webcrypto
105 #endif // COMPONENTS_WEBCRYPTO_NSS_KEY_NSS_H_