Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / content / child / webcrypto / nss / key_nss.cc
blob0887fe659eae969da86633f5bdd014914d3318d6
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"
11 namespace content {
13 namespace webcrypto {
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()) {
21 KeyNss::~KeyNss() {
24 SymKeyNss* KeyNss::AsSymKey() {
25 return NULL;
28 PublicKeyNss* KeyNss::AsPublicKey() {
29 return NULL;
32 PrivateKeyNss* KeyNss::AsPrivateKey() {
33 return NULL;
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() {
45 return this;
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() {
62 return this;
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() {
79 return this;
82 PrivateKeyNss::PrivateKeyNss(crypto::ScopedSECKEYPrivateKey key,
83 const CryptoData& pkcs8_data)
84 : KeyNss(pkcs8_data), key_(key.Pass()) {
87 } // namespace webcrypto
89 } // namespace content