Skip to content

V4 Signer #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 26, 2017
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
14 changes: 7 additions & 7 deletions packages/crypto-sha256-node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ function castSourceData(toCast: SourceData, encoding?: string): Buffer {
return fromString(toCast, encoding);
}

if (toCast instanceof ArrayBuffer) {
return fromArrayBuffer(toCast);
if (ArrayBuffer.isView(toCast)) {
return fromArrayBuffer(
toCast.buffer,
toCast.byteOffset,
toCast.byteLength
);
}

return fromArrayBuffer(
toCast.buffer,
toCast.byteOffset,
toCast.byteLength
);
return fromArrayBuffer(toCast);
}
4 changes: 2 additions & 2 deletions packages/crypto-sha256-node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"target": "es5",
"module": "commonjs",
"lib": [
"ES5",
"ES2015.Promise"
"es5",
"es2015.promise"
],
"declaration": true,
"sourceMap": true,
Expand Down
3 changes: 3 additions & 0 deletions packages/is-array-buffer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.js
*.js.map
*.d.ts
37 changes: 37 additions & 0 deletions packages/is-array-buffer/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {isArrayBuffer} from "../";

describe('isArrayBuffer', () => {
const arrayBufferConstructor = ArrayBuffer;

afterEach(() => {
(ArrayBuffer as any) = arrayBufferConstructor;
});

it('should return true for ArrayBuffer objects', () => {
expect(isArrayBuffer(new ArrayBuffer(0))).toBe(true);
});

it('should return false for ArrayBufferView objects', () => {
const view = new Uint8Array(0);

expect(isArrayBuffer(view)).toBe(false);
expect(isArrayBuffer(view.buffer)).toBe(true);
});

it('should return false for scalar values', () => {
for (let scalar of ['string', 123.234, true, null, void 0]) {
expect(isArrayBuffer(scalar)).toBe(false);
}
});

it(
'should return true for ArrayBuffers created with a different instance of the ArrayBuffer constructor',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test! Take that, frames!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out to be surprisingly relevant to running Jest, too.

() => {
const buffer = new ArrayBuffer(0);
(ArrayBuffer as any) = () => buffer;

expect(buffer).not.toBeInstanceOf(ArrayBuffer);
expect(isArrayBuffer(buffer)).toBe(true);
}
);
});
7 changes: 7 additions & 0 deletions packages/is-array-buffer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function isArrayBuffer(arg: any): arg is ArrayBuffer {
return typeof ArrayBuffer === 'function'
&& (
arg instanceof ArrayBuffer ||
Object.prototype.toString.call(arg) === '[object ArrayBuffer]'
);
}
19 changes: 19 additions & 0 deletions packages/is-array-buffer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@aws/is-array-buffer",
"private": true,
"version": "0.0.1",
"description": "Provides a function for detecting if an argument is an ArrayBuffer",
"scripts": {
"pretest": "tsc",
"test": "jest"
},
"author": "[email protected]",
"license": "UNLICENSED",
"main": "index.js",
"devDependencies": {
"@types/jest": "^20.0.2",
"@types/node": "^7.0.12",
"jest": "^20.0.4",
"typescript": "^2.3"
}
}
9 changes: 9 additions & 0 deletions packages/is-array-buffer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"strict": true,
"sourceMap": true
}
}
6 changes: 3 additions & 3 deletions packages/service-model/__fixtures__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ export function deepCopy<T>(arg: T): T {
}

if (typeof arg === 'object') {
return <T>Object.keys(arg).reduce((
carry: object,
return Object.keys(arg).reduce((
carry: T,
item: keyof T
) => ({...carry, [item]: deepCopy(arg[item])}), {});
) => ({...carry as any, [item]: deepCopy(arg[item])}), {});
}

return arg;
Expand Down
4 changes: 4 additions & 0 deletions packages/signature-v4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules/
*.js
*.js.map
*.d.ts
Loading