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 var utils
= require('utils');
8 * Enum of possible key types (subset of WebCrypto.KeyType).
17 * Enum of possible key usages (subset of WebCrypto.KeyUsage).
26 * Implementation of WebCrypto.Key used in enterprise.platformKeys.
27 * @param {KeyType} type The type of the new key.
28 * @param {ArrayBuffer} publicKeySpki The Subject Public Key Info in DER
30 * @param {KeyAlgorithm} algorithm The algorithm identifier.
31 * @param {KeyUsage[]} usages The allowed key usages.
32 * @param {boolean} extractable Whether the key is extractable.
35 var KeyImpl = function(type
, publicKeySpki
, algorithm
, usages
, extractable
) {
37 this.spki
= publicKeySpki
;
38 this.algorithm
= algorithm
;
40 this.extractable
= extractable
;
43 var KeyBase = function() {};
45 Object
.defineProperty(KeyBase
.prototype, 'algorithm', {
48 return utils
.deepCopy(privates(this).impl
.algorithm
);
52 var Key
= utils
.expose(
55 {superclass
: KeyBase
, readonly
: ['extractable', 'type', 'usages']});
58 * Returns |key|'s Subject Public Key Info. Throws an exception if |key| is not
61 * @return {ArrayBuffer} The Subject Public Key Info in DER encoding of |key|.
63 function getSpki(key
) {
65 throw new Error('Invalid key object.');
66 var keyImpl
= privates(key
).impl
;
67 if (!keyImpl
|| !keyImpl
.spki
)
68 throw new Error('Invalid key object.');
73 exports
.KeyType
= KeyType
;
74 exports
.KeyUsage
= KeyUsage
;
75 exports
.getSpki
= getSpki
;