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 #include "components/webcrypto/nss/key_nss.h"
7 #include "components/webcrypto/crypto_data.h"
8 #include "components/webcrypto/status.h"
9 #include "components/webcrypto/webcrypto_util.h"
13 KeyNss::KeyNss(const CryptoData
& serialized_key_data
)
14 : serialized_key_data_(
15 serialized_key_data
.bytes(),
16 serialized_key_data
.bytes() + serialized_key_data
.byte_length()) {
22 SymKeyNss
* KeyNss::AsSymKey() {
26 PublicKeyNss
* KeyNss::AsPublicKey() {
30 PrivateKeyNss
* KeyNss::AsPrivateKey() {
34 SymKeyNss::~SymKeyNss() {
37 SymKeyNss
* SymKeyNss::Cast(const blink::WebCryptoKey
& key
) {
38 KeyNss
* platform_key
= reinterpret_cast<KeyNss
*>(key
.handle());
39 return platform_key
->AsSymKey();
42 SymKeyNss
* SymKeyNss::AsSymKey() {
46 SymKeyNss::SymKeyNss(crypto::ScopedPK11SymKey key
,
47 const CryptoData
& raw_key_data
)
48 : KeyNss(raw_key_data
), key_(key
.Pass()) {
51 PublicKeyNss::~PublicKeyNss() {
54 PublicKeyNss
* PublicKeyNss::Cast(const blink::WebCryptoKey
& key
) {
55 KeyNss
* platform_key
= reinterpret_cast<KeyNss
*>(key
.handle());
56 return platform_key
->AsPublicKey();
59 PublicKeyNss
* PublicKeyNss::AsPublicKey() {
63 PublicKeyNss::PublicKeyNss(crypto::ScopedSECKEYPublicKey key
,
64 const CryptoData
& spki_data
)
65 : KeyNss(spki_data
), key_(key
.Pass()) {
68 PrivateKeyNss::~PrivateKeyNss() {
71 PrivateKeyNss
* PrivateKeyNss::Cast(const blink::WebCryptoKey
& key
) {
72 KeyNss
* platform_key
= reinterpret_cast<KeyNss
*>(key
.handle());
73 return platform_key
->AsPrivateKey();
76 PrivateKeyNss
* PrivateKeyNss::AsPrivateKey() {
80 PrivateKeyNss::PrivateKeyNss(crypto::ScopedSECKEYPrivateKey key
,
81 const CryptoData
& pkcs8_data
)
82 : KeyNss(pkcs8_data
), key_(key
.Pass()) {
85 } // namespace webcrypto