mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2026-02-21 03:02:59 +00:00
Addresses various review comments by @sanjanarajan
* Various FIXME tags are removed * In curve.js: - webCrypto/nodeCrypto fallback bug is fixed - Curve25519 has keyType ecdsa (won't be used for signing, but technically can be) - webGenKeyPair is simplifed * In base64.js: - documentation added and arguments simplified * In ecdsa.js and eddsa.js: - hash_algo is now at least as strong as the default curve hash - simplified the code by moving webSign/nodeSign and webVerify/nodeVerify to live in key.js (ht @ismaelbej) * In message.js: - in decryptSessionKey, loops break once a key packet is decrypted * In key.js: - getPreferredHashAlgorithm returns the best hash algorithm - enums are used for curve selection
This commit is contained in:
committed by
Sanjana Rajan
parent
3129e7c4e3
commit
5cb89f4f25
@@ -17,20 +17,21 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var b64s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||
var b64u = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
||||
var b64s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; // Standard radix-64
|
||||
var b64u = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; // URL-safe radix-64
|
||||
|
||||
/**
|
||||
* Convert binary array to radix-64
|
||||
* @param {Uint8Array} t Uint8Array to convert
|
||||
* @param {bool} u if true, output is URL-safe
|
||||
* @returns {string} radix-64 version of input string
|
||||
* @static
|
||||
*/
|
||||
function s2r(t, o, u) {
|
||||
function s2r(t, u = false) {
|
||||
// TODO check btoa alternative
|
||||
var b64 = (u === "base64url") ? b64u : b64s;
|
||||
var b64 = u ? b64u : b64s;
|
||||
var a, c, n;
|
||||
var r = o ? o : [],
|
||||
var r = [],
|
||||
l = 0,
|
||||
s = 0;
|
||||
var tl = t.length;
|
||||
@@ -67,33 +68,30 @@ function s2r(t, o, u) {
|
||||
if ((l % 60) === 0 && !u) {
|
||||
r.push("\n");
|
||||
}
|
||||
if (u !== 'base64url') {
|
||||
if (!u) {
|
||||
r.push('=');
|
||||
l += 1;
|
||||
}
|
||||
}
|
||||
if (s === 1 && u !== 'base64url') {
|
||||
if (s === 1 && !u) {
|
||||
if ((l % 60) === 0 && !u) {
|
||||
r.push("\n");
|
||||
}
|
||||
r.push('=');
|
||||
}
|
||||
if (o)
|
||||
{
|
||||
return;
|
||||
}
|
||||
return r.join('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert radix-64 to binary array
|
||||
* @param {String} t radix-64 string to convert
|
||||
* @param {bool} u if true, input is interpreted as URL-safe
|
||||
* @returns {Uint8Array} binary array version of input string
|
||||
* @static
|
||||
*/
|
||||
function r2s(t, u) {
|
||||
// TODO check atob alternative
|
||||
var b64 = (u === "base64url") ? b64u : b64s;
|
||||
var b64 = u ? b64u : b64s;
|
||||
var c, n;
|
||||
var r = [],
|
||||
s = 0,
|
||||
|
||||
Reference in New Issue
Block a user