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 "content/child/webcrypto/nss/key_nss.h"
7 #include "content/child/webcrypto/crypto_data.h"
8 #include "content/child/webcrypto/status.h"
9 #include "content/child/webcrypto/webcrypto_util.h"
15 KeyNss::KeyNss(const CryptoData
& serialized_key_data
)
16 : serialized_key_data_(
17 serialized_key_data
.bytes(),
18 serialized_key_data
.bytes() + serialized_key_data
.byte_length()) {
24 SymKeyNss
* KeyNss::AsSymKey() {
28 PublicKeyNss
* KeyNss::AsPublicKey() {
32 PrivateKeyNss
* KeyNss::AsPrivateKey() {
36 SymKeyNss::~SymKeyNss() {
39 SymKeyNss
* SymKeyNss::Cast(const blink::WebCryptoKey
& key
) {
40 KeyNss
* platform_key
= reinterpret_cast<KeyNss
*>(key
.handle());
41 return platform_key
->AsSymKey();
44 SymKeyNss
* SymKeyNss::AsSymKey() {
48 SymKeyNss::SymKeyNss(crypto::ScopedPK11SymKey key
,
49 const CryptoData
& raw_key_data
)
50 : KeyNss(raw_key_data
), key_(key
.Pass()) {
53 PublicKeyNss::~PublicKeyNss() {
56 PublicKeyNss
* PublicKeyNss::Cast(const blink::WebCryptoKey
& key
) {
57 KeyNss
* platform_key
= reinterpret_cast<KeyNss
*>(key
.handle());
58 return platform_key
->AsPublicKey();
61 PublicKeyNss
* PublicKeyNss::AsPublicKey() {
65 PublicKeyNss::PublicKeyNss(crypto::ScopedSECKEYPublicKey key
,
66 const CryptoData
& spki_data
)
67 : KeyNss(spki_data
), key_(key
.Pass()) {
70 PrivateKeyNss::~PrivateKeyNss() {
73 PrivateKeyNss
* PrivateKeyNss::Cast(const blink::WebCryptoKey
& key
) {
74 KeyNss
* platform_key
= reinterpret_cast<KeyNss
*>(key
.handle());
75 return platform_key
->AsPrivateKey();
78 PrivateKeyNss
* PrivateKeyNss::AsPrivateKey() {
82 PrivateKeyNss::PrivateKeyNss(crypto::ScopedSECKEYPrivateKey key
,
83 const CryptoData
& pkcs8_data
)
84 : KeyNss(pkcs8_data
), key_(key
.Pass()) {
87 } // namespace webcrypto
89 } // namespace content