<commit_before>/**
 * Test dependencies
 */
const chai = require('chai')
const expect = chai.expect

/**
 * Assertions
 */
chai.should()

const {TextEncoder} = require('text-encoding')
const crypto = require('../../src')
const CryptoKey = require('../../src/keys/CryptoKey')
const CryptoKeyPair = require('../../src/keys/CryptoKeyPair')
const KeyAlgorithm = require('../../src/dictionaries/KeyAlgorithm')
const AesKeyAlgorithm = require('../../src/dictionaries/AesKeyAlgorithm')
const AES_GCM = require('../../src/algorithms/AES-GCM')
const DataError = require('../../src/errors/DataError')
const OperationError = require('../../src/errors/OperationError')
const NotSupportedError = require('../../src/errors/NotSupportedError')
const CurrentlyNotSupportedError = require('../../src/errors/CurrentlyNotSupportedError')

/**
 * Test code  
 */
const good_iv =  Buffer.from([ 220, 29, 37, 164, 41, 84, 153, 197, 157, 122, 156, 254, 196, 161, 114, 74 ])
const bad_iv = Buffer.from([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]) // too short

/**
 * Tests
 */
describe('AES_GCM', () => {
  /**
   * dictionaries getter
   */
  describe.skip('dictionaries getter', () => {
    it('should return an array', () => {
      AES_GCM.dictionaries.should.eql([
        KeyAlgorithm,
        AesKeyAlgorithm
      ])
    })
  })

  /**
   * members getter
   */
  describe.skip('members getter', () => {
    it('should return an object', () => {
      AES_GCM.members.publicExponent.should.equal('BufferSource')
    })
  })

  /**
   * encrypt
   */
  describe.skip('encrypt', () => {
    let aes, key, data, signature

    before(() => {     
        aes = new AES_GCM({ name: "AES-GCM", length: 256 }) 
        key = aes.importKey(
            "jwk", 
            {   
                kty: "oct",
                k: "<KEY>",
                alg: "A256GCM",
                ext: true,
            },
            {   
                name: "AES-GCM",
            },
            true, 
            ["encrypt", "decrypt"] 
        )
        data = new TextEncoder().encode('Encoded with WebCrypto')
        signature = new Uint8Array(
            [28, 37, 34, 19, 165, 194, 33, 41, 41, 64, 114, 99, 135, 63, 127, 127, 177, 159, 109, 92, 80, 40, 168, 117, 38, 124, 35, 180, 244, 74, 59, 140, 210, 236, 134, 182, 126, 180])
    })

    it("should throw with invalid iv length", () => {
        expect(() => {
            aes.encrypt({name: "AES-GCM", iv: bad_iv},key,new Uint8Array())
        }).to.throw('IV Length must be exactly 16 bytes')
    })

    it('should return an ArrayBuffer', () => {
      aes.encrypt({name: "AES-GCM", iv: good_iv},key,data).should.be.instanceof(ArrayBuffer)
    })

    it('should return a valid encryption', () => {
        Buffer.from(aes.encrypt({name: "AES-GCM", iv: good_iv},key,data))
        .should.eql(Buffer.from(signature.buffer)) 
    })
  }) // encrypt

/**
 * decrypt
 */
  describe.skip('decrypt', () => {
    let aes, key, data, signature
    before(() => {     
        aes = new AES_GCM({ name: "AES-GCM", length: 256 }) 
        key = aes.importKey(
            "jwk", 
            {   
                kty: "oct",
                k: "<KEY>",
                alg: "A256GCM",
                ext: true,
            },
            {   
                name: "AES-GCM",
            },
            true, 
            ["encrypt", "decrypt"] 
        )
        data = new Uint8Array([28, 37, 34, 19, 165, 194, 33, 41, 41, 64, 114, 99, 135, 63, 127, 127, 177, 159, 109, 92, 80, 40, 168, 117, 38, 124, 35, 180, 244, 74, 59, 140, 210, 236, 134, 182, 126, 180])
        signature = new TextEncoder().encode('Encoded with WebCrypto')
    })

    it("should throw with invalid iv length", () => {
        expect(() => {
            aes.decrypt({name: "AES-GCM", iv: bad_iv},key,new Uint8Array())
        }).to.throw('IV Length must be exactly 16 bytes')
    })

    it('should return an ArrayBuffer', () => {
      aes.decrypt({name: "AES-GCM", iv: good_iv},key,data).should.be.instanceof(ArrayBuffer)
    }) 

    it('should return a valid encryption', () => {
        Buffer.from(aes.decrypt({name: "AES-GCM", iv: good_iv},key,data))
        .should.eql(Buffer.from(signature.buffer)) 
    })
  }) // decrypt

/**
 * generateKey
 */
  describe.skip('generateKey', () => {
    let alg, aes, cryptoKey
    
    before(() => {
        alg = {
            name: "AES-GCM",<commit_msg>wip(aes-gcm): unstubbed enc/dec and resolved an input err<commit_after>/**
 * Test dependencies
 */
const chai = require('chai')
const expect = chai.expect

/**
 * Assertions
 */
chai.should()

const {TextEncoder} = require('text-encoding')
const crypto = require('../../src')
const CryptoKey = require('../../src/keys/CryptoKey')
const CryptoKeyPair = require('../../src/keys/CryptoKeyPair')
const KeyAlgorithm = require('../../src/dictionaries/KeyAlgorithm')
const AesKeyAlgorithm = require('../../src/dictionaries/AesKeyAlgorithm')
const AES_GCM = require('../../src/algorithms/AES-GCM')
const DataError = require('../../src/errors/DataError')
const OperationError = require('../../src/errors/OperationError')
const NotSupportedError = require('../../src/errors/NotSupportedError')
const CurrentlyNotSupportedError = require('../../src/errors/CurrentlyNotSupportedError')

/**
 * Test code  
 */
const good_iv =  Buffer.from([ 220, 29, 37, 164, 41, 84, 153, 197, 157, 122, 156, 254, 196, 161, 114, 74 ])
const bad_iv = Buffer.from([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 ]) // too short

/**
 * Tests
 */
describe('AES_GCM', () => {
  /**
   * dictionaries getter
   */
  describe.skip('dictionaries getter', () => {
    it('should return an array', () => {
      AES_GCM.dictionaries.should.eql([
        KeyAlgorithm,
        AesKeyAlgorithm
      ])
    })
  })

  /**
   * members getter
   */
  describe.skip('members getter', () => {
    it('should return an object', () => {
      AES_GCM.members.publicExponent.should.equal('BufferSource')
    })
  })

  /**
   * encrypt
   */
  describe('encrypt', () => {
    let aes, key, data, signature

    before(() => {     
        aes = new AES_GCM({ name: "AES-GCM", length: 256 }) 
        key = aes.importKey(
            "jwk", 
            {   
                kty: "oct",
                k: "<KEY>",
                alg: "A256GCM",
                ext: true,
            },
            {   
                name: "AES-GCM",
            },
            true, 
            ["encrypt", "decrypt"] 
        )
        data = new TextEncoder().encode('Encoded with WebCrypto')
        signature = new Uint8Array(
            [28, 37, 34, 19, 165, 194, 33, 41, 41, 64, 114, 99, 135, 63, 127, 127, 177, 159, 109, 92, 80, 40, 168, 117, 38, 124, 35, 180, 244, 74, 59, 140, 210, 236, 134, 182, 126, 180])
    })

    it.skip("should throw with invalid iv length", () => {
        expect(() => {
            aes.encrypt({name: "AES-GCM", iv: bad_iv},key,new Uint8Array())
        }).to.throw('IV Length must be exactly 16 bytes')
    })

    it.skip('should return an ArrayBuffer', () => {
      aes.encrypt({name: "AES-GCM", iv: good_iv},key,data).should.be.instanceof(ArrayBuffer)
    })

    it('should return a valid encryption', () => {
        Buffer.from(aes.encrypt({name: "AES-GCM", iv: good_iv},key,data))
        .should.eql(Buffer.from(signature.buffer)) 
    })
  }) // encrypt

/**
 * decrypt
 */
  describe('decrypt', () => {
    let aes, key, data, signature
    before(() => {     
        aes = new AES_GCM({ name: "AES-GCM", length: 256 }) 
        key = aes.importKey(
            "jwk", 
            {   
                kty: "oct",
                k: "<KEY>",
                alg: "A256GCM",
                ext: true,
            },
            {   
                name: "AES-GCM",
            },
            true, 
            ["encrypt", "decrypt"] 
        )
        data = new Uint8Array([28, 37, 34, 19, 165, 194, 33, 41, 41, 64, 114, 99, 135, 63, 127, 127, 177, 159, 109, 92, 80, 40, 168, 117, 38, 124, 35, 180, 244, 74, 59, 140, 210, 236, 134, 182, 126, 180])
        signature = new TextEncoder().encode('Encoded with WebCrypto')
    })

    it.skip("should throw with invalid iv length", () => {
        expect(() => {
            aes.decrypt({name: "AES-GCM", iv: bad_iv},key,new Uint8Array())
        }).to.throw('IV Length must be exactly 16 bytes')
    })

    it.skip('should return an ArrayBuffer', () => {
      aes.decrypt({name: "AES-GCM", iv: good_iv},key,data).should.be.instanceof(ArrayBuffer)
    }) 

    it('should return a valid encryption', () => {
        Buffer.from(aes.decrypt({name: "AES-GCM", iv: good_iv, tagLength:128},key,data))
        .should.eql(Buffer.from(signature.buffer)) 
    })
  }) // decrypt

/**
 * generateKey
 */
  describe.skip('generateKey', () => {
    let alg, aes, cryptoKey
    
    before(() => {
        alg = {
            name: "AES-GCM",
{'fraction_non_alphanumeric': 0.18250309231980208, 'fraction_numerical': 0.06263353199145395, 'mean_word_length': 2.1152364273204904, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7367086', 'n_tokens_mistral': 3535, 'n_tokens_neox': 2868, 'n_words': 699}