11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciif (!common.hasCrypto)
41cb0ef41Sopenharmony_ci  common.skip('missing crypto');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ciconst crypto = require('crypto');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst test = [
101cb0ef41Sopenharmony_ci  {
111cb0ef41Sopenharmony_ci    algorithm: 'aes128-wrap',
121cb0ef41Sopenharmony_ci    key: 'b26f309fbe57e9b3bb6ae5ef31d54450',
131cb0ef41Sopenharmony_ci    iv: '3fd838af4093d749',
141cb0ef41Sopenharmony_ci    text: '12345678123456781234567812345678'
151cb0ef41Sopenharmony_ci  },
161cb0ef41Sopenharmony_ci  {
171cb0ef41Sopenharmony_ci    algorithm: 'id-aes128-wrap-pad',
181cb0ef41Sopenharmony_ci    key: 'b26f309fbe57e9b3bb6ae5ef31d54450',
191cb0ef41Sopenharmony_ci    iv: '3fd838af',
201cb0ef41Sopenharmony_ci    text: '12345678123456781234567812345678123'
211cb0ef41Sopenharmony_ci  },
221cb0ef41Sopenharmony_ci  {
231cb0ef41Sopenharmony_ci    algorithm: 'aes192-wrap',
241cb0ef41Sopenharmony_ci    key: '40978085d68091f7dfca0d7dfc7a5ee76d2cc7f2f345a304',
251cb0ef41Sopenharmony_ci    iv: '3fd838af4093d749',
261cb0ef41Sopenharmony_ci    text: '12345678123456781234567812345678'
271cb0ef41Sopenharmony_ci  },
281cb0ef41Sopenharmony_ci  {
291cb0ef41Sopenharmony_ci    algorithm: 'id-aes192-wrap-pad',
301cb0ef41Sopenharmony_ci    key: '40978085d68091f7dfca0d7dfc7a5ee76d2cc7f2f345a304',
311cb0ef41Sopenharmony_ci    iv: '3fd838af',
321cb0ef41Sopenharmony_ci    text: '12345678123456781234567812345678123'
331cb0ef41Sopenharmony_ci  },
341cb0ef41Sopenharmony_ci  {
351cb0ef41Sopenharmony_ci    algorithm: 'aes256-wrap',
361cb0ef41Sopenharmony_ci    key: '29c9eab5ed5ad44134a1437fe2e673b4d88a5b7c72e68454fea08721392b7323',
371cb0ef41Sopenharmony_ci    iv: '3fd838af4093d749',
381cb0ef41Sopenharmony_ci    text: '12345678123456781234567812345678'
391cb0ef41Sopenharmony_ci  },
401cb0ef41Sopenharmony_ci  {
411cb0ef41Sopenharmony_ci    algorithm: 'id-aes256-wrap-pad',
421cb0ef41Sopenharmony_ci    key: '29c9eab5ed5ad44134a1437fe2e673b4d88a5b7c72e68454fea08721392b7323',
431cb0ef41Sopenharmony_ci    iv: '3fd838af',
441cb0ef41Sopenharmony_ci    text: '12345678123456781234567812345678123'
451cb0ef41Sopenharmony_ci  },
461cb0ef41Sopenharmony_ci];
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_citest.forEach((data) => {
491cb0ef41Sopenharmony_ci  const cipher = crypto.createCipheriv(
501cb0ef41Sopenharmony_ci    data.algorithm,
511cb0ef41Sopenharmony_ci    Buffer.from(data.key, 'hex'),
521cb0ef41Sopenharmony_ci    Buffer.from(data.iv, 'hex'));
531cb0ef41Sopenharmony_ci  const ciphertext = cipher.update(data.text, 'utf8');
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci  const decipher = crypto.createDecipheriv(
561cb0ef41Sopenharmony_ci    data.algorithm,
571cb0ef41Sopenharmony_ci    Buffer.from(data.key, 'hex'),
581cb0ef41Sopenharmony_ci    Buffer.from(data.iv, 'hex'));
591cb0ef41Sopenharmony_ci  const msg = decipher.update(ciphertext, 'buffer', 'utf8');
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci  assert.strictEqual(msg, data.text, `${data.algorithm} test case failed`);
621cb0ef41Sopenharmony_ci});
63