asn1.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. (function() {
  2. var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
  3. var __module = nodeEnv ? module : {exports:{}};
  4. var __filename = 'preview-scripts/__node_modules/parse-asn1/asn1.js';
  5. var __require = nodeEnv ? function (request) {
  6. return cc.require(request);
  7. } : function (request) {
  8. return __quick_compile_project__.require(request, __filename);
  9. };
  10. function __define (exports, require, module) {
  11. if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}// from https://github.com/indutny/self-signed/blob/gh-pages/lib/asn1.js
  12. // Fedor, you are amazing.
  13. 'use strict'
  14. var asn1 = require('asn1.js')
  15. exports.certificate = require('./certificate')
  16. var RSAPrivateKey = asn1.define('RSAPrivateKey', function () {
  17. this.seq().obj(
  18. this.key('version').int(),
  19. this.key('modulus').int(),
  20. this.key('publicExponent').int(),
  21. this.key('privateExponent').int(),
  22. this.key('prime1').int(),
  23. this.key('prime2').int(),
  24. this.key('exponent1').int(),
  25. this.key('exponent2').int(),
  26. this.key('coefficient').int()
  27. )
  28. })
  29. exports.RSAPrivateKey = RSAPrivateKey
  30. var RSAPublicKey = asn1.define('RSAPublicKey', function () {
  31. this.seq().obj(
  32. this.key('modulus').int(),
  33. this.key('publicExponent').int()
  34. )
  35. })
  36. exports.RSAPublicKey = RSAPublicKey
  37. var PublicKey = asn1.define('SubjectPublicKeyInfo', function () {
  38. this.seq().obj(
  39. this.key('algorithm').use(AlgorithmIdentifier),
  40. this.key('subjectPublicKey').bitstr()
  41. )
  42. })
  43. exports.PublicKey = PublicKey
  44. var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function () {
  45. this.seq().obj(
  46. this.key('algorithm').objid(),
  47. this.key('none').null_().optional(),
  48. this.key('curve').objid().optional(),
  49. this.key('params').seq().obj(
  50. this.key('p').int(),
  51. this.key('q').int(),
  52. this.key('g').int()
  53. ).optional()
  54. )
  55. })
  56. var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function () {
  57. this.seq().obj(
  58. this.key('version').int(),
  59. this.key('algorithm').use(AlgorithmIdentifier),
  60. this.key('subjectPrivateKey').octstr()
  61. )
  62. })
  63. exports.PrivateKey = PrivateKeyInfo
  64. var EncryptedPrivateKeyInfo = asn1.define('EncryptedPrivateKeyInfo', function () {
  65. this.seq().obj(
  66. this.key('algorithm').seq().obj(
  67. this.key('id').objid(),
  68. this.key('decrypt').seq().obj(
  69. this.key('kde').seq().obj(
  70. this.key('id').objid(),
  71. this.key('kdeparams').seq().obj(
  72. this.key('salt').octstr(),
  73. this.key('iters').int()
  74. )
  75. ),
  76. this.key('cipher').seq().obj(
  77. this.key('algo').objid(),
  78. this.key('iv').octstr()
  79. )
  80. )
  81. ),
  82. this.key('subjectPrivateKey').octstr()
  83. )
  84. })
  85. exports.EncryptedPrivateKey = EncryptedPrivateKeyInfo
  86. var DSAPrivateKey = asn1.define('DSAPrivateKey', function () {
  87. this.seq().obj(
  88. this.key('version').int(),
  89. this.key('p').int(),
  90. this.key('q').int(),
  91. this.key('g').int(),
  92. this.key('pub_key').int(),
  93. this.key('priv_key').int()
  94. )
  95. })
  96. exports.DSAPrivateKey = DSAPrivateKey
  97. exports.DSAparam = asn1.define('DSAparam', function () {
  98. this.int()
  99. })
  100. var ECPrivateKey = asn1.define('ECPrivateKey', function () {
  101. this.seq().obj(
  102. this.key('version').int(),
  103. this.key('privateKey').octstr(),
  104. this.key('parameters').optional().explicit(0).use(ECParameters),
  105. this.key('publicKey').optional().explicit(1).bitstr()
  106. )
  107. })
  108. exports.ECPrivateKey = ECPrivateKey
  109. var ECParameters = asn1.define('ECParameters', function () {
  110. this.choice({
  111. namedCurve: this.objid()
  112. })
  113. })
  114. exports.signature = asn1.define('signature', function () {
  115. this.seq().obj(
  116. this.key('r').int(),
  117. this.key('s').int()
  118. )
  119. })
  120. }
  121. if (nodeEnv) {
  122. __define(__module.exports, __require, __module);
  123. }
  124. else {
  125. __quick_compile_project__.registerModuleFunc(__filename, function () {
  126. __define(__module.exports, __require, __module);
  127. });
  128. }
  129. })();