asn1-validator.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * Copyright (c) 2019 Digital Bazaar, Inc.
  3. */
  4. var forge = require('./forge');
  5. require('./asn1');
  6. var asn1 = forge.asn1;
  7. exports.privateKeyValidator = {
  8. // PrivateKeyInfo
  9. name: 'PrivateKeyInfo',
  10. tagClass: asn1.Class.UNIVERSAL,
  11. type: asn1.Type.SEQUENCE,
  12. constructed: true,
  13. value: [{
  14. // Version (INTEGER)
  15. name: 'PrivateKeyInfo.version',
  16. tagClass: asn1.Class.UNIVERSAL,
  17. type: asn1.Type.INTEGER,
  18. constructed: false,
  19. capture: 'privateKeyVersion'
  20. }, {
  21. // privateKeyAlgorithm
  22. name: 'PrivateKeyInfo.privateKeyAlgorithm',
  23. tagClass: asn1.Class.UNIVERSAL,
  24. type: asn1.Type.SEQUENCE,
  25. constructed: true,
  26. value: [{
  27. name: 'AlgorithmIdentifier.algorithm',
  28. tagClass: asn1.Class.UNIVERSAL,
  29. type: asn1.Type.OID,
  30. constructed: false,
  31. capture: 'privateKeyOid'
  32. }]
  33. }, {
  34. // PrivateKey
  35. name: 'PrivateKeyInfo',
  36. tagClass: asn1.Class.UNIVERSAL,
  37. type: asn1.Type.OCTETSTRING,
  38. constructed: false,
  39. capture: 'privateKey'
  40. }]
  41. };
  42. exports.publicKeyValidator = {
  43. name: 'SubjectPublicKeyInfo',
  44. tagClass: asn1.Class.UNIVERSAL,
  45. type: asn1.Type.SEQUENCE,
  46. constructed: true,
  47. captureAsn1: 'subjectPublicKeyInfo',
  48. value: [{
  49. name: 'SubjectPublicKeyInfo.AlgorithmIdentifier',
  50. tagClass: asn1.Class.UNIVERSAL,
  51. type: asn1.Type.SEQUENCE,
  52. constructed: true,
  53. value: [{
  54. name: 'AlgorithmIdentifier.algorithm',
  55. tagClass: asn1.Class.UNIVERSAL,
  56. type: asn1.Type.OID,
  57. constructed: false,
  58. capture: 'publicKeyOid'
  59. }]
  60. },
  61. // capture group for ed25519PublicKey
  62. {
  63. tagClass: asn1.Class.UNIVERSAL,
  64. type: asn1.Type.BITSTRING,
  65. constructed: false,
  66. composed: true,
  67. captureBitStringValue: 'ed25519PublicKey'
  68. }
  69. // FIXME: this is capture group for rsaPublicKey, use it in this API or
  70. // discard?
  71. /* {
  72. // subjectPublicKey
  73. name: 'SubjectPublicKeyInfo.subjectPublicKey',
  74. tagClass: asn1.Class.UNIVERSAL,
  75. type: asn1.Type.BITSTRING,
  76. constructed: false,
  77. value: [{
  78. // RSAPublicKey
  79. name: 'SubjectPublicKeyInfo.subjectPublicKey.RSAPublicKey',
  80. tagClass: asn1.Class.UNIVERSAL,
  81. type: asn1.Type.SEQUENCE,
  82. constructed: true,
  83. optional: true,
  84. captureAsn1: 'rsaPublicKey'
  85. }]
  86. } */
  87. ]
  88. };