Skip to content

Commit c9b0318

Browse files
authored
fix: Add tests for signature info (#134)
Add tests for signature info
1 parent 21d65d0 commit c9b0318

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

modules/serialize/test/fixtures.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,11 @@ export function headerAuthIV () {
6868
export function encryptedDataKey () {
6969
return new Uint8Array([ 0, 2, 0, 12, 194, 189, 32, 43, 32, 194, 188, 32, 61, 32, 194, 190, 0, 8, 102, 105, 114, 115, 116, 75, 101, 121, 0, 5, 1, 2, 3, 4, 5, 0, 12, 194, 189, 32, 43, 32, 194, 188, 32, 61, 32, 194, 190, 0, 9, 115, 101, 99, 111, 110, 100, 75, 101, 121, 0, 5, 6, 7, 8, 9, 0 ])
7070
}
71+
72+
export function ecdsaP256Signature () {
73+
return new Uint8Array([48, 68, 2, 32, 22, 77, 187, 192, 175, 104, 2, 240, 55, 2, 6, 138, 103, 148, 214, 240, 244, 65, 224, 254, 60, 52, 218, 22, 250, 245, 216, 228, 151, 151, 220, 234, 2, 32, 125, 9, 97, 8, 132, 123, 79, 193, 216, 207, 214, 0, 73, 183, 149, 173, 26, 173, 251, 132, 140, 139, 44, 122, 11, 50, 163, 105, 138, 221, 223, 29])
74+
}
75+
76+
export function ecdsaP256SignatureInfo () {
77+
return new Uint8Array([0, 70, 48, 68, 2, 32, 22, 77, 187, 192, 175, 104, 2, 240, 55, 2, 6, 138, 103, 148, 214, 240, 244, 65, 224, 254, 60, 52, 218, 22, 250, 245, 216, 228, 151, 151, 220, 234, 2, 32, 125, 9, 97, 8, 132, 123, 79, 193, 216, 207, 214, 0, 73, 183, 149, 173, 26, 173, 251, 132, 140, 139, 44, 122, 11, 50, 163, 105, 138, 221, 223, 29])
78+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is
6+
* located at
7+
*
8+
* http://aws.amazon.com/apache2.0/
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed on an
11+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12+
* implied. See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
/* eslint-env mocha */
17+
18+
import { expect } from 'chai'
19+
import 'mocha'
20+
import { serializeSignatureInfo, deserializeSignature } from '../src/signature_info'
21+
import * as fixtures from './fixtures'
22+
23+
describe('serializeSignatureInfo', () => {
24+
it('returns signature info', () => {
25+
const test = serializeSignatureInfo(fixtures.ecdsaP256Signature())
26+
expect(test).to.deep.equal(fixtures.ecdsaP256SignatureInfo())
27+
})
28+
})
29+
30+
describe('deserializeSignature', () => {
31+
it('returns the signature', () => {
32+
const test = deserializeSignature(fixtures.ecdsaP256SignatureInfo())
33+
expect(test).to.deep.equal(fixtures.ecdsaP256Signature())
34+
})
35+
36+
it('Precondition: There must be information for a signature.', () => {
37+
expect(() => deserializeSignature({} as any)).to.throw()
38+
})
39+
40+
it('Precondition: The signature length must be positive.', () => {
41+
const badInfo = fixtures.ecdsaP256SignatureInfo()
42+
badInfo[1] = 0
43+
expect(() => deserializeSignature(badInfo)).to.throw()
44+
})
45+
46+
it('Precondition: The data must match the serialized length.', () => {
47+
const badInfo = fixtures.ecdsaP256SignatureInfo()
48+
badInfo[1] = badInfo[1] + 1
49+
expect(() => deserializeSignature(badInfo)).to.throw()
50+
})
51+
})

0 commit comments

Comments
 (0)