Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / renderer / resources / extensions / enterprise_platform_keys / key_pair.js
blobdc06f16498ddb53cc8a090af60275f7a59758d72
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');
6 var intersect = require('platformKeys.utils').intersect;
7 var keyModule = require('platformKeys.Key');
8 var Key = keyModule.Key;
9 var KeyType = keyModule.KeyType;
10 var KeyUsage = keyModule.KeyUsage;
12 /**
13 * Implementation of WebCrypto.KeyPair used in enterprise.platformKeys.
14 * @param {ArrayBuffer} publicKeySpki The Subject Public Key Info in DER
15 * encoding.
16 * @param {KeyAlgorithm} algorithm The algorithm identifier.
17 * @param {KeyUsage[]} usages The allowed key usages.
18 * @constructor
20 var KeyPairImpl = function(publicKeySpki, algorithm, usages) {
21 this.publicKey = new Key(KeyType.public,
22 publicKeySpki,
23 algorithm,
24 intersect([KeyUsage.verify], usages),
25 true /* extractable */);
26 this.privateKey = new Key(KeyType.private,
27 publicKeySpki,
28 algorithm,
29 intersect([KeyUsage.sign], usages),
30 false /* not extractable */);
33 exports.KeyPair = utils.expose('KeyPair',
34 KeyPairImpl,
35 {readonly:['publicKey', 'privateKey']});