Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23,920 changes: 11,960 additions & 11,960 deletions dist/aws-sdk-core-react-native.js

Large diffs are not rendered by default.

47,396 changes: 21,271 additions & 26,125 deletions dist/aws-sdk-react-native.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/api_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ function apiLoader(svc, version) {
}

/**
* @api private
*
* This member of AWS.apiLoader is private, but changing it will necessitate a
* change to ../scripts/services-table-generator.ts
*/
Expand Down
34 changes: 34 additions & 0 deletions lib/browserCryptoLib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var Hmac = require('./browserHmac');
var Md5 = require('./browserMd5');
var Sha1 = require('./browserSha1');
var Sha256 = require('./browserSha256');

module.exports = exports = {
createHash: function createHash(alg) {
alg = alg.toLowerCase();
if (alg === 'md5') {
return new Md5();
} else if (alg === 'sha256') {
return new Sha256();
} else if (alg === 'sha1') {
return new Sha1();
}

throw new Error('Hash algorithm ' + alg + ' is not supported in the browser SDK');
},
createHmac: function createHmac(alg, key) {
alg = alg.toLowerCase();
if (alg === 'md5') {
return new Hmac(Md5, key);
} else if (alg === 'sha256') {
return new Hmac(Sha256, key);
} else if (alg === 'sha1') {
return new Hmac(Sha1, key);
}

throw new Error('HMAC algorithm ' + alg + ' is not supported in the browser SDK');
},
createSign: function() {
throw new Error('createSign is not implemented in the browser');
}
}
62 changes: 62 additions & 0 deletions lib/browserHashUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var Buffer = require('buffer/').Buffer;

/**
* This is a polyfill for the static method `isView` of `ArrayBuffer`, which is
* e.g. missing in IE 10.
*
* @api private
*/
if (
typeof ArrayBuffer !== 'undefined' &&
typeof ArrayBuffer.isView === 'undefined'
) {
ArrayBuffer.isView = function(arg) {
return viewStrings.indexOf(Object.prototype.toString.call(arg)) > -1;
};
}

/**
* @api private
*/
var viewStrings = [
'[object Int8Array]',
'[object Uint8Array]',
'[object Uint8ClampedArray]',
'[object Int16Array]',
'[object Uint16Array]',
'[object Int32Array]',
'[object Uint32Array]',
'[object Float32Array]',
'[object Float64Array]',
'[object DataView]',
];

/**
* @api private
*/
function isEmptyData(data) {
if (typeof data === 'string') {
return data.length === 0;
}
return data.byteLength === 0;
}

/**
* @api private
*/
function convertToBuffer(data) {
if (typeof data === 'string') {
data = new Buffer(data, 'utf8');
}

if (ArrayBuffer.isView(data)) {
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
}

return new Uint8Array(data);
}

module.exports = exports = {
isEmptyData: isEmptyData,
convertToBuffer: convertToBuffer,
}
62 changes: 62 additions & 0 deletions lib/browserHmac.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var hashUtils = require('./browserHashUtils');

/**
* @api private
*/
function Hmac(hashCtor, secret) {
this.hash = new hashCtor();
this.outer = new hashCtor();

var inner = bufferFromSecret(hashCtor, secret);
var outer = new Uint8Array(hashCtor.BLOCK_SIZE);
outer.set(inner);

for (var i = 0; i < hashCtor.BLOCK_SIZE; i++) {
inner[i] ^= 0x36;
outer[i] ^= 0x5c;
}

this.hash.update(inner);
this.outer.update(outer);

// Zero out the copied key buffer.
for (var i = 0; i < inner.byteLength; i++) {
inner[i] = 0;
}
}

module.exports = exports = Hmac;

Hmac.prototype.update = function (toHash) {
if (hashUtils.isEmptyData(toHash) || this.error) {
return this;
}

try {
this.hash.update(hashUtils.convertToBuffer(toHash));
} catch (e) {
this.error = e;
}

return this;
};

Hmac.prototype.digest = function (encoding) {
if (!this.outer.finished) {
this.outer.update(this.hash.digest());
}

return this.outer.digest(encoding);
}

function bufferFromSecret(hashCtor, secret) {
var input = hashUtils.convertToBuffer(secret);
if (input.byteLength > hashCtor.BLOCK_SIZE) {
var bufferHash = new hashCtor;
bufferHash.update(input);
input = bufferHash.digest();
}
var buffer = new Uint8Array(hashCtor.BLOCK_SIZE);
buffer.set(input);
return buffer;
}
179 changes: 179 additions & 0 deletions lib/browserMd5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
var hashUtils = require('./browserHashUtils');
var Buffer = require('buffer/').Buffer;

var BLOCK_SIZE = 64;

var DIGEST_LENGTH = 16;

var INIT = [
0x67452301,
0xefcdab89,
0x98badcfe,
0x10325476,
];

/**
* @api private
*/
function Md5() {
this.state = [
0x67452301,
0xefcdab89,
0x98badcfe,
0x10325476,
];
this.buffer = new DataView(new ArrayBuffer(BLOCK_SIZE));
this.bufferLength = 0;
this.bytesHashed = 0;
this.finished = false;
}

module.exports = exports = Md5;

Md5.BLOCK_SIZE = BLOCK_SIZE;

Md5.prototype.update = function (sourceData) {
if (hashUtils.isEmptyData(sourceData)) {
return this;
} else if (this.finished) {
throw new Error('Attempted to update an already finished hash.');
}

var data = hashUtils.convertToBuffer(sourceData);
var position = 0;
var byteLength = data.byteLength;
this.bytesHashed += byteLength;
while (byteLength > 0) {
this.buffer.setUint8(this.bufferLength++, data[position++]);
byteLength--;
if (this.bufferLength === BLOCK_SIZE) {
this.hashBuffer();
this.bufferLength = 0;
}
}

return this;
};

Md5.prototype.digest = function (encoding) {
if (!this.finished) {
var _a = this, buffer = _a.buffer, undecoratedLength = _a.bufferLength, bytesHashed = _a.bytesHashed;
var bitsHashed = bytesHashed * 8;
buffer.setUint8(this.bufferLength++, 128);
// Ensure the final block has enough room for the hashed length
if (undecoratedLength % BLOCK_SIZE >= BLOCK_SIZE - 8) {
for (var i = this.bufferLength; i < BLOCK_SIZE; i++) {
buffer.setUint8(i, 0);
}
this.hashBuffer();
this.bufferLength = 0;
}
for (var i = this.bufferLength; i < BLOCK_SIZE - 8; i++) {
buffer.setUint8(i, 0);
}
buffer.setUint32(BLOCK_SIZE - 8, bitsHashed >>> 0, true);
buffer.setUint32(BLOCK_SIZE - 4, Math.floor(bitsHashed / 0x100000000), true);
this.hashBuffer();
this.finished = true;
}
var out = new DataView(new ArrayBuffer(DIGEST_LENGTH));
for (var i = 0; i < 4; i++) {
out.setUint32(i * 4, this.state[i], true);
}
var buff = new Buffer(out.buffer, out.byteOffset, out.byteLength);
return encoding ? buff.toString(encoding) : buff;
};

Md5.prototype.hashBuffer = function () {
var _a = this, buffer = _a.buffer, state = _a.state;
var a = state[0], b = state[1], c = state[2], d = state[3];
a = ff(a, b, c, d, buffer.getUint32(0, true), 7, 0xd76aa478);
d = ff(d, a, b, c, buffer.getUint32(4, true), 12, 0xe8c7b756);
c = ff(c, d, a, b, buffer.getUint32(8, true), 17, 0x242070db);
b = ff(b, c, d, a, buffer.getUint32(12, true), 22, 0xc1bdceee);
a = ff(a, b, c, d, buffer.getUint32(16, true), 7, 0xf57c0faf);
d = ff(d, a, b, c, buffer.getUint32(20, true), 12, 0x4787c62a);
c = ff(c, d, a, b, buffer.getUint32(24, true), 17, 0xa8304613);
b = ff(b, c, d, a, buffer.getUint32(28, true), 22, 0xfd469501);
a = ff(a, b, c, d, buffer.getUint32(32, true), 7, 0x698098d8);
d = ff(d, a, b, c, buffer.getUint32(36, true), 12, 0x8b44f7af);
c = ff(c, d, a, b, buffer.getUint32(40, true), 17, 0xffff5bb1);
b = ff(b, c, d, a, buffer.getUint32(44, true), 22, 0x895cd7be);
a = ff(a, b, c, d, buffer.getUint32(48, true), 7, 0x6b901122);
d = ff(d, a, b, c, buffer.getUint32(52, true), 12, 0xfd987193);
c = ff(c, d, a, b, buffer.getUint32(56, true), 17, 0xa679438e);
b = ff(b, c, d, a, buffer.getUint32(60, true), 22, 0x49b40821);
a = gg(a, b, c, d, buffer.getUint32(4, true), 5, 0xf61e2562);
d = gg(d, a, b, c, buffer.getUint32(24, true), 9, 0xc040b340);
c = gg(c, d, a, b, buffer.getUint32(44, true), 14, 0x265e5a51);
b = gg(b, c, d, a, buffer.getUint32(0, true), 20, 0xe9b6c7aa);
a = gg(a, b, c, d, buffer.getUint32(20, true), 5, 0xd62f105d);
d = gg(d, a, b, c, buffer.getUint32(40, true), 9, 0x02441453);
c = gg(c, d, a, b, buffer.getUint32(60, true), 14, 0xd8a1e681);
b = gg(b, c, d, a, buffer.getUint32(16, true), 20, 0xe7d3fbc8);
a = gg(a, b, c, d, buffer.getUint32(36, true), 5, 0x21e1cde6);
d = gg(d, a, b, c, buffer.getUint32(56, true), 9, 0xc33707d6);
c = gg(c, d, a, b, buffer.getUint32(12, true), 14, 0xf4d50d87);
b = gg(b, c, d, a, buffer.getUint32(32, true), 20, 0x455a14ed);
a = gg(a, b, c, d, buffer.getUint32(52, true), 5, 0xa9e3e905);
d = gg(d, a, b, c, buffer.getUint32(8, true), 9, 0xfcefa3f8);
c = gg(c, d, a, b, buffer.getUint32(28, true), 14, 0x676f02d9);
b = gg(b, c, d, a, buffer.getUint32(48, true), 20, 0x8d2a4c8a);
a = hh(a, b, c, d, buffer.getUint32(20, true), 4, 0xfffa3942);
d = hh(d, a, b, c, buffer.getUint32(32, true), 11, 0x8771f681);
c = hh(c, d, a, b, buffer.getUint32(44, true), 16, 0x6d9d6122);
b = hh(b, c, d, a, buffer.getUint32(56, true), 23, 0xfde5380c);
a = hh(a, b, c, d, buffer.getUint32(4, true), 4, 0xa4beea44);
d = hh(d, a, b, c, buffer.getUint32(16, true), 11, 0x4bdecfa9);
c = hh(c, d, a, b, buffer.getUint32(28, true), 16, 0xf6bb4b60);
b = hh(b, c, d, a, buffer.getUint32(40, true), 23, 0xbebfbc70);
a = hh(a, b, c, d, buffer.getUint32(52, true), 4, 0x289b7ec6);
d = hh(d, a, b, c, buffer.getUint32(0, true), 11, 0xeaa127fa);
c = hh(c, d, a, b, buffer.getUint32(12, true), 16, 0xd4ef3085);
b = hh(b, c, d, a, buffer.getUint32(24, true), 23, 0x04881d05);
a = hh(a, b, c, d, buffer.getUint32(36, true), 4, 0xd9d4d039);
d = hh(d, a, b, c, buffer.getUint32(48, true), 11, 0xe6db99e5);
c = hh(c, d, a, b, buffer.getUint32(60, true), 16, 0x1fa27cf8);
b = hh(b, c, d, a, buffer.getUint32(8, true), 23, 0xc4ac5665);
a = ii(a, b, c, d, buffer.getUint32(0, true), 6, 0xf4292244);
d = ii(d, a, b, c, buffer.getUint32(28, true), 10, 0x432aff97);
c = ii(c, d, a, b, buffer.getUint32(56, true), 15, 0xab9423a7);
b = ii(b, c, d, a, buffer.getUint32(20, true), 21, 0xfc93a039);
a = ii(a, b, c, d, buffer.getUint32(48, true), 6, 0x655b59c3);
d = ii(d, a, b, c, buffer.getUint32(12, true), 10, 0x8f0ccc92);
c = ii(c, d, a, b, buffer.getUint32(40, true), 15, 0xffeff47d);
b = ii(b, c, d, a, buffer.getUint32(4, true), 21, 0x85845dd1);
a = ii(a, b, c, d, buffer.getUint32(32, true), 6, 0x6fa87e4f);
d = ii(d, a, b, c, buffer.getUint32(60, true), 10, 0xfe2ce6e0);
c = ii(c, d, a, b, buffer.getUint32(24, true), 15, 0xa3014314);
b = ii(b, c, d, a, buffer.getUint32(52, true), 21, 0x4e0811a1);
a = ii(a, b, c, d, buffer.getUint32(16, true), 6, 0xf7537e82);
d = ii(d, a, b, c, buffer.getUint32(44, true), 10, 0xbd3af235);
c = ii(c, d, a, b, buffer.getUint32(8, true), 15, 0x2ad7d2bb);
b = ii(b, c, d, a, buffer.getUint32(36, true), 21, 0xeb86d391);
state[0] = (a + state[0]) & 0xFFFFFFFF;
state[1] = (b + state[1]) & 0xFFFFFFFF;
state[2] = (c + state[2]) & 0xFFFFFFFF;
state[3] = (d + state[3]) & 0xFFFFFFFF;
};

function cmn(q, a, b, x, s, t) {
a = (((a + q) & 0xFFFFFFFF) + ((x + t) & 0xFFFFFFFF)) & 0xFFFFFFFF;
return (((a << s) | (a >>> (32 - s))) + b) & 0xFFFFFFFF;
}

function ff(a, b, c, d, x, s, t) {
return cmn((b & c) | ((~b) & d), a, b, x, s, t);
}

function gg(a, b, c, d, x, s, t) {
return cmn((b & d) | (c & (~d)), a, b, x, s, t);
}

function hh(a, b, c, d, x, s, t) {
return cmn(b ^ c ^ d, a, b, x, s, t);
}

function ii(a, b, c, d, x, s, t) {
return cmn(c ^ (b | (~d)), a, b, x, s, t);
}
Loading