Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Fixes code to work on older versions of Chrome.
Browse files Browse the repository at this point in the history
  • Loading branch information
alokmenghrajani committed Sep 9, 2015
1 parent 6e58eb6 commit 221dbdb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 57 deletions.
3 changes: 2 additions & 1 deletion Gruntfile.js
Expand Up @@ -64,7 +64,8 @@ module.exports = function(grunt) {
files: [
{pattern: 'dist/jose-testing.js', watching: false, included: false},
{pattern: 'test/qunit-promises.js', watching: false, included: false},
'test/jose-jwe-test.html'
'test/jose-jwe-test.html',
'test/jose-jws-test.html'
],
autoWatch: true,
browsers: ['Chrome'],
Expand Down
27 changes: 9 additions & 18 deletions dist/jose-testing.js
Expand Up @@ -399,8 +399,8 @@ WebCryptographer.prototype.decrypt = function(cek_promise, aad, iv, cipher_text,
* Signs plain_text.
*
* @param aad json
* @param key_promise Promise<CryptoKey>
* @param payload String or json
* @param key_promise Promise<CryptoKey>
* @return Promise<ArrayBuffer>
*/
WebCryptographer.prototype.sign = function(aad, payload, key_promise) {
Expand Down Expand Up @@ -1052,29 +1052,20 @@ Utils.Base64Url.decodeArray = function(str) {
};

Utils.sha256 = function(str) {
return crypto.subtle.digest("SHA-256", Utils.arrayFromString(str)).then(function(hash) {
// Browser docs indicate the first parameter to crypto.subtle.digest to be a
// DOMString. This was initially implemented as an object and continues to be
// supported, so we favor the older form for backwards compatibility.
return crypto.subtle.digest({name: "SHA-256"}, Utils.arrayFromString(str)).then(function(hash) {
return Utils.Base64Url.encodeArray(hash);
});
};

Utils.isCryptoKey = function(rsa_key) {
var hexStr = /[a-f0-9]{2}(:[a-f0-9]{2})+/i;

if (typeof(window.CryptoKey) != 'undefined') {
return rsa_key instanceof CryptoKey;
}

if (rsa_key instanceof Object) {
return hexStr.test(rsa_key.n) &&
((hexStr.test(rsa_key.e) || typeof(rsa_key.e) == 'number') ||
(hexStr.test(rsa_key.d) &&
hexStr.test(rsa_key.p) &&
hexStr.test(rsa_key.q) &&
hexStr.test(rsa_key.qi) &&
hexStr.test(rsa_key.dq) &&
hexStr.test(rsa_key.dp)));
}
// Some browsers don't expose the CryptoKey as an object, so we need to check
// the constructor's name.
return rsa_key.constructor.name == 'CryptoKey';
};

/*-
* Copyright 2014 Square Inc.
*
Expand Down
27 changes: 9 additions & 18 deletions dist/jose.js
Expand Up @@ -401,8 +401,8 @@ WebCryptographer.prototype.decrypt = function(cek_promise, aad, iv, cipher_text,
* Signs plain_text.
*
* @param aad json
* @param key_promise Promise<CryptoKey>
* @param payload String or json
* @param key_promise Promise<CryptoKey>
* @return Promise<ArrayBuffer>
*/
WebCryptographer.prototype.sign = function(aad, payload, key_promise) {
Expand Down Expand Up @@ -1054,29 +1054,20 @@ Utils.Base64Url.decodeArray = function(str) {
};

Utils.sha256 = function(str) {
return crypto.subtle.digest("SHA-256", Utils.arrayFromString(str)).then(function(hash) {
// Browser docs indicate the first parameter to crypto.subtle.digest to be a
// DOMString. This was initially implemented as an object and continues to be
// supported, so we favor the older form for backwards compatibility.
return crypto.subtle.digest({name: "SHA-256"}, Utils.arrayFromString(str)).then(function(hash) {
return Utils.Base64Url.encodeArray(hash);
});
};

Utils.isCryptoKey = function(rsa_key) {
var hexStr = /[a-f0-9]{2}(:[a-f0-9]{2})+/i;

if (typeof(window.CryptoKey) != 'undefined') {
return rsa_key instanceof CryptoKey;
}

if (rsa_key instanceof Object) {
return hexStr.test(rsa_key.n) &&
((hexStr.test(rsa_key.e) || typeof(rsa_key.e) == 'number') ||
(hexStr.test(rsa_key.d) &&
hexStr.test(rsa_key.p) &&
hexStr.test(rsa_key.q) &&
hexStr.test(rsa_key.qi) &&
hexStr.test(rsa_key.dq) &&
hexStr.test(rsa_key.dp)));
}
// Some browsers don't expose the CryptoKey as an object, so we need to check
// the constructor's name.
return rsa_key.constructor.name == 'CryptoKey';
};

/*-
* Copyright 2014 Square Inc.
*
Expand Down

0 comments on commit 221dbdb

Please sign in to comment.