goog.provide('wycheproof.BigInteger');
goog.provide('wycheproof.BigPrimeInteger');
goog.require('e2e.BigNum');
goog.require('e2e.BigPrimeNum');
goog.require('goog.crypt');
goog.require('goog.crypt.base64');
goog.require('goog.testing.asserts');
goog.require('wycheproof.TestUtil');
var TestUtil = wycheproof.TestUtil;
wycheproof.BigInteger = function(optValue) {
wycheproof.BigInteger.base(this, 'constructor', optValue);
};
goog.inherits(wycheproof.BigInteger, e2e.BigNum);
wycheproof.BigInteger.fromHex = function(s) {
assertTrue('Input is not a hex string', TestUtil.isHex(s));
if (s.length % 2 == 1) {
s = '0' + s;
}
var bytes = goog.crypt.hexToByteArray(s);
var bigInt = new wycheproof.BigInteger(bytes);
return bigInt.dropLeadingZeros();
};
wycheproof.BigInteger.prototype.toBase64Url = function(optValue) {
var bytes = this.toByteArray();
if (optValue !== undefined && optValue > bytes.length) {
var addingZeros = new Array(optValue-bytes.length).fill(0);
bytes = addingZeros.concat(bytes);
}
var b64Str = goog.crypt.base64.encodeByteArray(bytes);
return TestUtil.base64ToBase64Url(b64Str);
};
wycheproof.BigInteger.prototype.toArrayBuffer = function(optValue) {
var bytes = this.toByteArray();
if (optValue !== undefined && optValue > bytes.length) {
var addingZeros = new Array(optValue-bytes.length).fill(0);
bytes = addingZeros.concat(bytes);
}
return new Uint8Array(bytes).buffer;
};
wycheproof.BigPrimeInteger = function(modulus) {
wycheproof.BigPrimeInteger.base(this, 'constructor', modulus);
};
goog.inherits(wycheproof.BigPrimeInteger, e2e.BigPrimeNum);