summaryrefslogtreecommitdiffstats
path: root/content/child/webcrypto/nss/key_nss.cc
blob: 0887fe659eae969da86633f5bdd014914d3318d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/child/webcrypto/nss/key_nss.h"

#include "content/child/webcrypto/crypto_data.h"
#include "content/child/webcrypto/status.h"
#include "content/child/webcrypto/webcrypto_util.h"

namespace content {

namespace webcrypto {

KeyNss::KeyNss(const CryptoData& serialized_key_data)
    : serialized_key_data_(
          serialized_key_data.bytes(),
          serialized_key_data.bytes() + serialized_key_data.byte_length()) {
}

KeyNss::~KeyNss() {
}

SymKeyNss* KeyNss::AsSymKey() {
  return NULL;
}

PublicKeyNss* KeyNss::AsPublicKey() {
  return NULL;
}

PrivateKeyNss* KeyNss::AsPrivateKey() {
  return NULL;
}

SymKeyNss::~SymKeyNss() {
}

SymKeyNss* SymKeyNss::Cast(const blink::WebCryptoKey& key) {
  KeyNss* platform_key = reinterpret_cast<KeyNss*>(key.handle());
  return platform_key->AsSymKey();
}

SymKeyNss* SymKeyNss::AsSymKey() {
  return this;
}

SymKeyNss::SymKeyNss(crypto::ScopedPK11SymKey key,
                     const CryptoData& raw_key_data)
    : KeyNss(raw_key_data), key_(key.Pass()) {
}

PublicKeyNss::~PublicKeyNss() {
}

PublicKeyNss* PublicKeyNss::Cast(const blink::WebCryptoKey& key) {
  KeyNss* platform_key = reinterpret_cast<KeyNss*>(key.handle());
  return platform_key->AsPublicKey();
}

PublicKeyNss* PublicKeyNss::AsPublicKey() {
  return this;
}

PublicKeyNss::PublicKeyNss(crypto::ScopedSECKEYPublicKey key,
                           const CryptoData& spki_data)
    : KeyNss(spki_data), key_(key.Pass()) {
}

PrivateKeyNss::~PrivateKeyNss() {
}

PrivateKeyNss* PrivateKeyNss::Cast(const blink::WebCryptoKey& key) {
  KeyNss* platform_key = reinterpret_cast<KeyNss*>(key.handle());
  return platform_key->AsPrivateKey();
}

PrivateKeyNss* PrivateKeyNss::AsPrivateKey() {
  return this;
}

PrivateKeyNss::PrivateKeyNss(crypto::ScopedSECKEYPrivateKey key,
                             const CryptoData& pkcs8_data)
    : KeyNss(pkcs8_data), key_(key.Pass()) {
}

}  // namespace webcrypto

}  // namespace content