Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4072)

Unified Diff: chrome/renderer/resources/extensions/platform_keys/get_public_key.js

Issue 884073002: Implement chrome.platformKeys.getKeyPair(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cert_impl2
Patch Set: Rebased. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/platform_keys/get_public_key.js
diff --git a/chrome/renderer/resources/extensions/platform_keys/get_public_key.js b/chrome/renderer/resources/extensions/platform_keys/get_public_key.js
new file mode 100644
index 0000000000000000000000000000000000000000..290d8f8dfd3cdec6902ad33d0c7095f4de124c1a
--- /dev/null
+++ b/chrome/renderer/resources/extensions/platform_keys/get_public_key.js
@@ -0,0 +1,54 @@
+// Copyright 2015 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.
+
+var internalAPI = require('platformKeys.internalAPI');
+
+var normalizeAlgorithm =
+ requireNative('platform_keys_natives').NormalizeAlgorithm;
+
+function combineAlgorithms(algorithm, importParams) {
+ if (importParams.name === undefined) {
+ importParams.name = algorithm.name;
+ }
+
+ // Verify whether importParams.hash equals
+ // { name: 'none' }
+ if (importParams.hash &&
+ importParams.hash.name.toLowerCase() === 'none') {
+ if (Object.keys(importParams.hash).length != 1 ||
+ Object.keys(importParams).length != 2) {
+ // 'name' must be the only hash property in this case.
+ throw new Error('A required parameter was missing or out-of-range');
+ }
+ importParams.hash.name = 'none';
+ } else {
+ // Otherwise apply WebCrypto's algorithm normalization.
+ importParams = normalizeAlgorithm(importParams, 'ImportKey');
+ if (!importParams) {
+ // throw CreateSyntaxError();
+ throw new Error('A required parameter was missing or out-of-range');
+ }
+ }
+
+ // internalAPI.getPublicKey returns publicExponent as ArrayBuffer, but it
+ // should be a Uint8Array.
+ if (algorithm.publicExponent) {
+ algorithm.publicExponent = new Uint8Array(algorithm.publicExponent);
+ }
+
+ for (var key in importParams) {
+ algorithm[key] = importParams[key];
+ }
+
+ return algorithm;
+}
+
+function getPublicKey(cert, importParams, callback) {
+ internalAPI.getPublicKey(cert, function(publicKey, algorithm) {
+ var combinedAlgorithm = combineAlgorithms(algorithm, importParams);
+ callback(publicKey, combinedAlgorithm);
+ });
+}
+
+exports.getPublicKey = getPublicKey;

Powered by Google App Engine
This is Rietveld 408576698