import test from 'ava'

let root
let keyRoot

if ('WEBCRYPTO' in process.env) {
  root = keyRoot = '#dist/webcrypto'
} else if ('CRYPTOKEY' in process.env) {
  root = '#dist'
  keyRoot = '#dist/webcrypto'
} else {
  root = keyRoot = '#dist'
}

const jose = await import(keyRoot)

function conditional({ webcrypto = 1, electron = 1 } = {}) {
  let run = test
  if (!webcrypto && ('WEBCRYPTO' in process.env || 'CRYPTOKEY' in process.env)) {
    run = run.failing
  }

  if (!electron && 'electron' in process.versions) {
    run = run.failing
  }
  return run
}

const keys = {
  rsa: {
    privateKey:
      '-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDC9YmaZYpqBfdy\nb6DL37m4L6N+isRpbMPH6Bpymww/scbMj8jXNCA5fx+0CxwPwe4d/E7lDZ6hED+a\n3p42T6H44jacYNWdZus+OkJkariZgbb26siAfOjcqu7Adotqcl5Q1b4Og+gdOopN\n/y5XfmwfP0ovGHhfeR8CWKOgtn1ACoffYc2IQYpbe9M/ieFmGj6h9/TTcbtpxC8V\nJ4Fvl3ENyBh6wQbGJ04wk2MKvGAaU2GzyiZbusAE75leQ//HhN4F4wMo/294m/GZ\nLEfJ6wFEgoyqVPjrtY3auDo+A3wkCus2nlvZStStly0edLaOBv20MR5/lJbVfdBs\nsjP2dZTzAgMBAAECggEAau3TCAzTSu10154kGk3eBgiS6q/fpFcUVouWHe+uWyz9\ndWsTY/1iA0cXM1+4h2f9WxLsjrLWo05PJHkfW3h3xRMFkuWFpCwzsFCx43OpRgCg\nQnNpfxeDfKyAAK3EL6EE298vu7RbVdSq0La6SyC62rSS0pvgQbUj7dyB+n682ac3\n1y5DHwvhJaVQAL3SWunkjdu3aV+HQ0hWLL5PhwJpnqlAyGusyB1ydH709PZ/mw+N\n6sfVvUFSgOCYJLhIVi5h4ORZ4mV3PiJZE4+zPjMNJlT9GqKL6bBcDw5yCUj5cJ9p\no3N3lgrlvKDQ5RcGUWwHpKI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hlKcYCM/b/c6Kf55jPfIRv\nJIh/FueN36bFWJtAXA/Ztwym+BrSK4CAHL2PXCVMAaYVtTK13pVN2uSGCtSfE1sp\nUSUuJ/OW5rZeyKBKV+KozE2yVce0YPRIR4t6gpnjLGglrtoVxZeOBrXo6R/1GCKz\nkMi0Rv+vNqgIu3IHoPa1WCwSjlAItBE7YIK9E0LaeUyGdp+BhbDYkr/9sSW3yWKq\n8XvjwmhxYf5KgON+JJCQUqur08baq6UR6mDVneEz0W29WTt7nrM63gVY9qb1VJLq\nsRaEOWpRSEQkeYoUxHZWTq38uCdZdOT8ZgnsGj3tgPzucJcf9LOjbFLdLKGNMj0C\nAwEAAQ==\n-----END PUBLIC KEY-----\n',
  },
  'P-256': {
    privateKey:
      '-----BEGIN PRIVATE KEY-----\nMIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgDWWQhKsBhXz/Nr8s\nTHJPwhW3Ma05i0IRg9xjJBs3pNuhRANCAAR84SJzhOkjOQgf7k9QPiG6yC5Awd9t\nAQNMmDqxX1pqs+0xhMfFT1lvV/Skvr/g5sMalElhCYx05JnXI8VOpTZi\n-----END PRIVATE KEY-----\n',
    publicKey:
      '-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEfOEic4TpIzkIH+5PUD4husguQMHf\nbQEDTJg6sV9aarPtMYTHxU9Zb1f0pL6/4ObDGpRJYQmMdOSZ1yPFTqU2Yg==\n-----END PUBLIC KEY-----\n',
    certificate:
      '-----BEGIN CERTIFICATE-----\nMIIBXjCCAQSgAwIBAgIGAXvykuMKMAoGCCqGSM49BAMCMDYxNDAyBgNVBAMMK3Np\nQXBNOXpBdk1VaXhXVWVGaGtjZXg1NjJRRzFyQUhXaV96UlFQTVpQaG8wHhcNMjEw\nOTE3MDcwNTE3WhcNMjIwNzE0MDcwNTE3WjA2MTQwMgYDVQQDDCtzaUFwTTl6QXZN\nVWl4V1VlRmhrY2V4NTYyUUcxckFIV2lfelJRUE1aUGhvMFkwEwYHKoZIzj0CAQYI\nKoZIzj0DAQcDQgAE8PbPvCv5D5xBFHEZlBp/q5OEUymq7RIgWIi7tkl9aGSpYE35\nUH+kBKDnphJO3odpPZ5gvgKs2nwRWcrDnUjYLDAKBggqhkjOPQQDAgNIADBFAiEA\n1yyMTRe66MhEXID9+uVub7woMkNYd0LhSHwKSPMUUTkCIFQGsfm1ecXOpeGOufAh\nv+A1QWZMuTWqYt+uh/YSRNDn\n-----END CERTIFICATE-----',
  },
  'P-384': {
    privateKey:
      '-----BEGIN PRIVATE KEY-----\nMIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDBOblIt924xIsUG21PU\nWjXX+5VqUnpc851xnpjRPxouy7LBGnG+w+a1l2hpGUbRlkahZANiAASqB0UFW1tD\nzcZ0aT0eIdapYzTzbnvFuzEBhV3+zHavp4NkWIrkzE4BBbABXqkXAGdi5oqG0DXe\ned6lz6AJK1O6Y0zfATVG+T3LFXzb/dLeibuSphS4DqaiDQvSm/gXLNw=\n-----END PRIVATE KEY-----\n',
    publicKey:
      '-----BEGIN PUBLIC KEY-----\nMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEqgdFBVtbQ83GdGk9HiHWqWM08257xbsx\nAYVd/sx2r6eDZFiK5MxOAQWwAV6pFwBnYuaKhtA13nnepc+gCStTumNM3wE1Rvk9\nyxV82/3S3om7kqYUuA6mog0L0pv4Fyzc\n-----END PUBLIC KEY-----\n',
    certificate:
      '-----BEGIN CERTIFICATE-----\nMIIBmjCCASGgAwIBAgIGAXvyk31cMAoGCCqGSM49BAMCMDYxNDAyBgNVBAMMK0tL\nSWZVcUthNEZSYVRISVVmVUFSN3ZPSEpIenJlNmFVRnM3Wk9CZGczX3cwHhcNMjEw\nOTE3MDcwNTU3WhcNMjIwNzE0MDcwNTU3WjA2MTQwMgYDVQQDDCtLS0lmVXFLYTRG\nUmFUSElVZlVBUjd2T0hKSHpyZTZhVUZzN1pPQmRnM193MHYwEAYHKoZIzj0CAQYF\nK4EEACIDYgAEXGGo5mGJcpHu9Ib6PaKJURZ8inTKa/yznIqHgNew81bzbyW1wK3e\neEU637aAaHkaf+QwiEuswx4euEQ0U1xdFF8n80KopyHVB5CDXV3hv40Osuwcv2cD\n727puXzxSnWsMAoGCCqGSM49BAMCA2cAMGQCMBaN8kxQ1CUFLBhk7eyxaS6Pljzz\nXcYU0q7Uddbh3nhzfZ8rAZIVBTq7EHJMGsqS4AIwbGliZUob0PzgEXRLwz0nzBGe\nuftbcz40IGAn4bQuKVvzm5+Ivy5syf0odB8ShBh4\n-----END CERTIFICATE-----',
  },
  'P-521': {
    privateKey:
      '-----BEGIN PRIVATE KEY-----\nMIHuAgEAMBAGByqGSM49AgEGBSuBBAAjBIHWMIHTAgEBBEIBN8YVgYk+smSCRYiD\nJNgQLGBP/BAEy7oU3Kbu8xAyZyOqWO6k1fHyNqyhhGy/2PqBdI3BEttGVasq7SxC\ncTrVlMahgYkDgYYABAG2DXbhthHBTSMgeozGtLhhMz5WPhAbVY/Yx4/fzaOzJ9iI\npsODKjphlKaEDGvPByut2kbGwP3cusNOXleu50PeugE+RIHHBAwxFOx497pTvmLV\nXgYP7WCjwVIdlHXoVdFQfjMZqZXqU/vQbCSMGpA0K+5VtGwmSoF0SnDygsoSpXCL\nLg==\n-----END PRIVATE KEY-----\n',
    publicKey:
      '-----BEGIN PUBLIC KEY-----\nMIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQBtg124bYRwU0jIHqMxrS4YTM+Vj4Q\nG1WP2MeP382jsyfYiKbDgyo6YZSmhAxrzwcrrdpGxsD93LrDTl5XrudD3roBPkSB\nxwQMMRTsePe6U75i1V4GD+1go8FSHZR16FXRUH4zGamV6lP70GwkjBqQNCvuVbRs\nJkqBdEpw8oLKEqVwiy4=\n-----END PUBLIC KEY-----\n',
    certificate:
      '-----BEGIN CERTIFICATE-----\nMIIB5jCCAUegAwIBAgIGAXvyk+mAMAoGCCqGSM49BAMCMDYxNDAyBgNVBAMMK0w3\nSUVyWnlyam1jSFVLUW1saFBsbHlHRVNiRU1vUmx0bi1uamdwaTBMU2MwHhcNMjEw\nOTE3MDcwNjI1WhcNMjIwNzE0MDcwNjI1WjA2MTQwMgYDVQQDDCtMN0lFclp5cmpt\nY0hVS1FtbGhQbGx5R0VTYkVNb1JsdG4tbmpncGkwTFNjMIGbMBAGByqGSM49AgEG\nBSuBBAAjA4GGAAQAK8EaImw7EIBX+nAa3F+Ef86spagOysjlq5gIbhghnJalUW5a\nyxUvW53yXISavFQ8vQjr8Rz4FEqk5qR0klULIIYA7gD03P1sZf/Jw2ox2blryu2w\nqFA9x9zqN0c0O8fRVpXUlk0zMLK1aH1+JzTKApSykxgmC0mMx9U+aKO5Cdx1qLUw\nCgYIKoZIzj0EAwIDgYwAMIGIAkIBCjh15sgMfR0VeuIzzK8OK//XreRNQQ7ljILW\n6a38fhoswaIz5r8p68o0xzqx5eTTIfR+1C5F92W6DjoBeJjh3NkCQgHpb2t+0T2z\nw+E5scJQ/jfELHh/wjKV2mClYhjlPhq67jt4OcofENaO81b8amMBV3YhztV+gs1r\ngqI7dS9nJbq5lw==\n-----END CERTIFICATE-----',
  },
  secp256k1: {
    privateKey:
      '-----BEGIN PRIVATE KEY-----\nMIGEAgEAMBAGByqGSM49AgEGBSuBBAAKBG0wawIBAQQgN+0/OhaF7QdeNyYnVuFa\n+sAXc6g8knLyqE0pFBEebP6hRANCAATS+klnsy7giILFs9xHhEfNqavUc4BA6n8W\nNJY7fV8WMZRXR8cY6tjv2rQrBuw5ZdlRMg9W5V+K5jiaMwSMrHsv\n-----END PRIVATE KEY-----\n',
    publicKey:
      '-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAE0vpJZ7Mu4IiCxbPcR4RHzamr1HOAQOp/\nFjSWO31fFjGUV0fHGOrY79q0KwbsOWXZUTIPVuVfiuY4mjMEjKx7Lw==\n-----END PUBLIC KEY-----\n',
  },
  ed25519: {
    privateKey:
      '-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VwBCIEIOcUcmmhP080PCEg3n1MojHqLRVqksuWi/mu6IL3oqcd\n-----END PRIVATE KEY-----\n',
    publicKey:
      '-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAYPirSLK5RYui0fLnPzF/zohd13Ey7usg/ZwQmyLBkfE=\n-----END PUBLIC KEY-----\n',
    certificate:
      '-----BEGIN CERTIFICATE-----\nMIIB0zCCAYUCFEAGUxyTR1mz/XyaVnqHUA1T0bg4MAUGAytlcDCBizELMAkGA1UE\nBhMCVVMxFTATBgNVBAgMDFBlbm5zeWx2YW5pYTETMBEGA1UEBwwKUGl0dHNidXJn\naDEWMBQGA1UECgwNRXhhbXBsZSwgSW5jLjEiMCAGCSqGSIb3DQEJARYTZXhhbXBs\nZUBleGFtcGxlLmNvbTEUMBIGA1UEAwwLZXhhbXBsZS5jb20wHhcNMjExMTA1MTkz\nNTQ4WhcNMjMxMDA2MTkzNTQ4WjCBizELMAkGA1UEBhMCVVMxFTATBgNVBAgMDFBl\nbm5zeWx2YW5pYTETMBEGA1UEBwwKUGl0dHNidXJnaDEWMBQGA1UECgwNRXhhbXBs\nZSwgSW5jLjEiMCAGCSqGSIb3DQEJARYTZXhhbXBsZUBleGFtcGxlLmNvbTEUMBIG\nA1UEAwwLZXhhbXBsZS5jb20wKjAFBgMrZXADIQCuVl9VNLFAflCTZDKRtWjGLqsD\ne/E5r+zIN1H6rWkE/DAFBgMrZXADQQDet6id3ZIBqQ4RP1GBRHN19epkb7euezw6\nYlmU09Tsz1j7utsNgs6ztF43GyzzVWrBtHkjne7qtnIONDqSvJoC\n-----END CERTIFICATE-----',
  },
  ed448: {
    privateKey:
      '-----BEGIN PRIVATE KEY-----\nMEcCAQAwBQYDK2VxBDsEOZH8HCMLkTP3rNcQH/ZZsOCUdKPTFDUnfkF9ytoKKE9D\ne27L5gPte5Nw2uvJv3cFPIo+UvBF2ih8Tg==\n-----END PRIVATE KEY-----\n',
    publicKey:
      '-----BEGIN PUBLIC KEY-----\nMEMwBQYDK2VxAzoAKyg7ZuCoHEcVK/J+IYX82pG2Cn83HDq+Vz1OotlPF6Q2VIrM\n2WCGhydehGrnGieV2ysTfMTTIC6A\n-----END PUBLIC KEY-----\n',
  },
  x25519: {
    privateKey:
      '-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VuBCIEIHDP/1UF43oNuTKvxDY2gNe6gJTPhdYeoXpd+ufNsyFl\n-----END PRIVATE KEY-----\n',
    publicKey:
      '-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VuAyEACQgvSpBWGONHe9r7+/0z/uUTJgydI/fcWR8REUqqGC4=\n-----END PUBLIC KEY-----\n',
  },
  x448: {
    privateKey:
      '-----BEGIN PRIVATE KEY-----\nMEYCAQAwBQYDK2VvBDoEOFAfUMe2Yxtjg/a8C95o73SU6JsphoyKY8ZupKxKSrzc\ngn37kyK794dhIAFHXES9vLJF5ImOIZ+q\n-----END PRIVATE KEY-----\n',
    publicKey:
      '-----BEGIN PUBLIC KEY-----\nMEIwBQYDK2VvAzkAiGwV8Vh450I0cq0eEGLNz6SSkSJHbdDZ718xfi57qy816aIW\nW/OYjf111Kyzu/2hnQGseMOXn8U=\n-----END PUBLIC KEY-----\n',
  },
}

const testSPKI = async (t, pem, alg) => {
  const key = await jose.importSPKI(pem, alg, { extractable: true })
  t.is((await jose.exportSPKI(key)).trim(), pem.trim())
}
const testPKCS8 = async (t, pem, alg) => {
  const key = await jose.importPKCS8(pem, alg, { extractable: true })
  t.is((await jose.exportPKCS8(key)).trim(), pem.trim())
}
const testX509 = async (t, x509, alg) => {
  await jose.importX509(x509, alg, { extractable: true })
  t.pass()
}

for (const alg of [
  'RS256',
  'RS384',
  'RS512',
  'PS256',
  'PS384',
  'PS512',
  'RSA-OAEP',
  'RSA-OAEP-256',
  'RSA-OAEP-384',
  'RSA-OAEP-512',
  'RSA1_5',
]) {
  conditional({ webcrypto: alg !== 'RSA1_5', electron: 1 })(
    `import SPKI RSA for ${alg}`,
    testSPKI,
    keys.rsa.publicKey,
    alg,
  )
  conditional({ webcrypto: alg !== 'RSA1_5', electron: 1 })(
    `import X509 RSA for ${alg}`,
    testX509,
    keys.rsa.certificate,
    alg,
  )
  conditional({ webcrypto: alg !== 'RSA1_5', electron: 1 })(
    `import PKCS8 RSA for ${alg}`,
    testPKCS8,
    keys.rsa.privateKey,
    alg,
  )
}

for (const alg of ['ES256', 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW']) {
  test(`import SPKI P-256 for ${alg}`, testSPKI, keys['P-256'].publicKey, alg)
  test(`import X509 P-256 for ${alg}`, testX509, keys['P-256'].certificate, alg)
  test(`import PKCS8 P-256 for ${alg}`, testPKCS8, keys['P-256'].privateKey, alg)
}

for (const alg of ['ES384', 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW']) {
  test(`import SPKI P-384 for ${alg}`, testSPKI, keys['P-384'].publicKey, alg)
  test(`import X509 P-384 for ${alg}`, testX509, keys['P-384'].certificate, alg)
  test(`import PKCS8 P-384 for ${alg}`, testPKCS8, keys['P-384'].privateKey, alg)
}

for (const alg of ['ES512', 'ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW']) {
  test(`import SPKI P-521 for ${alg}`, testSPKI, keys['P-521'].publicKey, alg)
  test(`import X509 P-521 for ${alg}`, testX509, keys['P-521'].certificate, alg)
  test(`import PKCS8 P-521 for ${alg}`, testPKCS8, keys['P-521'].privateKey, alg)
}

for (const alg of ['ES256K']) {
  conditional({ webcrypto: 0, electron: 0 })(
    `import SPKI secp256k1 for ${alg}`,
    testSPKI,
    keys.secp256k1.publicKey,
    alg,
  )
  conditional({ webcrypto: 0, electron: 0 })(
    `import PKCS8 secp256k1 for ${alg}`,
    testPKCS8,
    keys.secp256k1.privateKey,
    alg,
  )
}

for (const alg of ['EdDSA']) {
  test(`import SPKI ed25519 for ${alg}`, testSPKI, keys.ed25519.publicKey, alg)
  test(`import X509 ed25519 for ${alg}`, testX509, keys.ed25519.certificate, alg)
  test(`import PKCS8 ed25519 for ${alg}`, testPKCS8, keys.ed25519.privateKey, alg)
  conditional({ webcrypto: 1, electron: 0 })(
    `import SPKI ed448 for ${alg}`,
    testSPKI,
    keys.ed448.publicKey,
    alg,
  )
  conditional({ webcrypto: 1, electron: 0 })(
    `import PKCS8 ed448 for ${alg}`,
    testPKCS8,
    keys.ed448.privateKey,
    alg,
  )
}

for (const alg of ['ECDH-ES', 'ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW']) {
  conditional({ webcrypto: 0, electron: 1 })(
    `import SPKI x25519 for ${alg}`,
    testSPKI,
    keys.x25519.publicKey,
    alg,
  )
  conditional({ webcrypto: 0, electron: 1 })(
    `import PKCS8 x25519 for ${alg}`,
    testPKCS8,
    keys.x25519.privateKey,
    alg,
  )
  conditional({ webcrypto: 0, electron: 0 })(
    `import SPKI x448 for ${alg}`,
    testSPKI,
    keys.x448.publicKey,
    alg,
  )
  conditional({ webcrypto: 0, electron: 0 })(
    `import PKCS8 x448 for ${alg}`,
    testPKCS8,
    keys.x448.privateKey,
    alg,
  )
}
