forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest-crypto-gcm-explicit-short-tag.js
More file actions
47 lines (37 loc) · 1001 Bytes
/
test-crypto-gcm-explicit-short-tag.js
File metadata and controls
47 lines (37 loc) · 1001 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Flags: --pending-deprecation
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const { createDecipheriv, randomBytes } = require('crypto');
common.expectWarning({
DeprecationWarning: []
});
const key = randomBytes(32);
const iv = randomBytes(16);
{
// Full 128-bit tag.
const tag = randomBytes(16);
createDecipheriv('aes-256-gcm', key, iv).setAuthTag(tag);
}
{
// Shortened tag with explicit length option.
const tag = randomBytes(12);
createDecipheriv('aes-256-gcm', key, iv, {
authTagLength: tag.byteLength
}).setAuthTag(tag);
}
{
// Shortened tag with explicit but incorrect length option.
const tag = randomBytes(12);
assert.throws(() => {
createDecipheriv('aes-256-gcm', key, iv, {
authTagLength: 14
}).setAuthTag(tag);
}, {
name: 'TypeError',
message: 'Invalid authentication tag length: 12',
code: 'ERR_CRYPTO_INVALID_AUTH_TAG'
});
}