@pokash/n8n-nodes-ksef 0.2.15 → 0.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (645) hide show
  1. package/node_modules/@oozcitak/dom/LICENSE +21 -0
  2. package/node_modules/@oozcitak/dom/README.md +32 -0
  3. package/node_modules/@oozcitak/dom/lib/algorithm/AbortAlgorithm.d.ts +21 -0
  4. package/node_modules/@oozcitak/dom/lib/algorithm/AbortAlgorithm.js +79 -0
  5. package/node_modules/@oozcitak/dom/lib/algorithm/AbortAlgorithm.js.map +1 -0
  6. package/node_modules/@oozcitak/dom/lib/algorithm/AttrAlgorithm.d.ts +8 -0
  7. package/node_modules/@oozcitak/dom/lib/algorithm/AttrAlgorithm.js +23 -0
  8. package/node_modules/@oozcitak/dom/lib/algorithm/AttrAlgorithm.js.map +1 -0
  9. package/node_modules/@oozcitak/dom/lib/algorithm/BoundaryPointAlgorithm.d.ts +8 -0
  10. package/node_modules/@oozcitak/dom/lib/algorithm/BoundaryPointAlgorithm.js +76 -0
  11. package/node_modules/@oozcitak/dom/lib/algorithm/BoundaryPointAlgorithm.js.map +1 -0
  12. package/node_modules/@oozcitak/dom/lib/algorithm/CharacterDataAlgorithm.d.ts +19 -0
  13. package/node_modules/@oozcitak/dom/lib/algorithm/CharacterDataAlgorithm.js +140 -0
  14. package/node_modules/@oozcitak/dom/lib/algorithm/CharacterDataAlgorithm.js.map +1 -0
  15. package/node_modules/@oozcitak/dom/lib/algorithm/CreateAlgorithm.d.ts +192 -0
  16. package/node_modules/@oozcitak/dom/lib/algorithm/CreateAlgorithm.js +303 -0
  17. package/node_modules/@oozcitak/dom/lib/algorithm/CreateAlgorithm.js.map +1 -0
  18. package/node_modules/@oozcitak/dom/lib/algorithm/CustomElementAlgorithm.d.ts +61 -0
  19. package/node_modules/@oozcitak/dom/lib/algorithm/CustomElementAlgorithm.js +108 -0
  20. package/node_modules/@oozcitak/dom/lib/algorithm/CustomElementAlgorithm.js.map +1 -0
  21. package/node_modules/@oozcitak/dom/lib/algorithm/DOMAlgorithm.d.ts +72 -0
  22. package/node_modules/@oozcitak/dom/lib/algorithm/DOMAlgorithm.js +288 -0
  23. package/node_modules/@oozcitak/dom/lib/algorithm/DOMAlgorithm.js.map +1 -0
  24. package/node_modules/@oozcitak/dom/lib/algorithm/DOMTokenListAlgorithm.d.ts +21 -0
  25. package/node_modules/@oozcitak/dom/lib/algorithm/DOMTokenListAlgorithm.js +61 -0
  26. package/node_modules/@oozcitak/dom/lib/algorithm/DOMTokenListAlgorithm.js.map +1 -0
  27. package/node_modules/@oozcitak/dom/lib/algorithm/DocumentAlgorithm.d.ts +29 -0
  28. package/node_modules/@oozcitak/dom/lib/algorithm/DocumentAlgorithm.js +161 -0
  29. package/node_modules/@oozcitak/dom/lib/algorithm/DocumentAlgorithm.js.map +1 -0
  30. package/node_modules/@oozcitak/dom/lib/algorithm/ElementAlgorithm.d.ts +121 -0
  31. package/node_modules/@oozcitak/dom/lib/algorithm/ElementAlgorithm.js +608 -0
  32. package/node_modules/@oozcitak/dom/lib/algorithm/ElementAlgorithm.js.map +1 -0
  33. package/node_modules/@oozcitak/dom/lib/algorithm/EventAlgorithm.d.ts +146 -0
  34. package/node_modules/@oozcitak/dom/lib/algorithm/EventAlgorithm.js +995 -0
  35. package/node_modules/@oozcitak/dom/lib/algorithm/EventAlgorithm.js.map +1 -0
  36. package/node_modules/@oozcitak/dom/lib/algorithm/EventTargetAlgorithm.d.ts +33 -0
  37. package/node_modules/@oozcitak/dom/lib/algorithm/EventTargetAlgorithm.js +142 -0
  38. package/node_modules/@oozcitak/dom/lib/algorithm/EventTargetAlgorithm.js.map +1 -0
  39. package/node_modules/@oozcitak/dom/lib/algorithm/MutationAlgorithm.d.ts +66 -0
  40. package/node_modules/@oozcitak/dom/lib/algorithm/MutationAlgorithm.js +1173 -0
  41. package/node_modules/@oozcitak/dom/lib/algorithm/MutationAlgorithm.js.map +1 -0
  42. package/node_modules/@oozcitak/dom/lib/algorithm/MutationObserverAlgorithm.d.ts +43 -0
  43. package/node_modules/@oozcitak/dom/lib/algorithm/MutationObserverAlgorithm.js +276 -0
  44. package/node_modules/@oozcitak/dom/lib/algorithm/MutationObserverAlgorithm.js.map +1 -0
  45. package/node_modules/@oozcitak/dom/lib/algorithm/NamespaceAlgorithm.d.ts +25 -0
  46. package/node_modules/@oozcitak/dom/lib/algorithm/NamespaceAlgorithm.js +85 -0
  47. package/node_modules/@oozcitak/dom/lib/algorithm/NamespaceAlgorithm.js.map +1 -0
  48. package/node_modules/@oozcitak/dom/lib/algorithm/NodeAlgorithm.d.ts +68 -0
  49. package/node_modules/@oozcitak/dom/lib/algorithm/NodeAlgorithm.js +543 -0
  50. package/node_modules/@oozcitak/dom/lib/algorithm/NodeAlgorithm.js.map +1 -0
  51. package/node_modules/@oozcitak/dom/lib/algorithm/NodeIteratorAlgorithm.d.ts +15 -0
  52. package/node_modules/@oozcitak/dom/lib/algorithm/NodeIteratorAlgorithm.js +105 -0
  53. package/node_modules/@oozcitak/dom/lib/algorithm/NodeIteratorAlgorithm.js.map +1 -0
  54. package/node_modules/@oozcitak/dom/lib/algorithm/OrderedSetAlgorithm.d.ts +27 -0
  55. package/node_modules/@oozcitak/dom/lib/algorithm/OrderedSetAlgorithm.js +125 -0
  56. package/node_modules/@oozcitak/dom/lib/algorithm/OrderedSetAlgorithm.js.map +1 -0
  57. package/node_modules/@oozcitak/dom/lib/algorithm/ParentNodeAlgorithm.d.ts +9 -0
  58. package/node_modules/@oozcitak/dom/lib/algorithm/ParentNodeAlgorithm.js +69 -0
  59. package/node_modules/@oozcitak/dom/lib/algorithm/ParentNodeAlgorithm.js.map +1 -0
  60. package/node_modules/@oozcitak/dom/lib/algorithm/RangeAlgorithm.d.ts +82 -0
  61. package/node_modules/@oozcitak/dom/lib/algorithm/RangeAlgorithm.js +829 -0
  62. package/node_modules/@oozcitak/dom/lib/algorithm/RangeAlgorithm.js.map +1 -0
  63. package/node_modules/@oozcitak/dom/lib/algorithm/SelectorsAlgorithm.d.ts +8 -0
  64. package/node_modules/@oozcitak/dom/lib/algorithm/SelectorsAlgorithm.js +21 -0
  65. package/node_modules/@oozcitak/dom/lib/algorithm/SelectorsAlgorithm.js.map +1 -0
  66. package/node_modules/@oozcitak/dom/lib/algorithm/ShadowTreeAlgorithm.d.ts +57 -0
  67. package/node_modules/@oozcitak/dom/lib/algorithm/ShadowTreeAlgorithm.js +316 -0
  68. package/node_modules/@oozcitak/dom/lib/algorithm/ShadowTreeAlgorithm.js.map +1 -0
  69. package/node_modules/@oozcitak/dom/lib/algorithm/TextAlgorithm.d.ts +30 -0
  70. package/node_modules/@oozcitak/dom/lib/algorithm/TextAlgorithm.js +226 -0
  71. package/node_modules/@oozcitak/dom/lib/algorithm/TextAlgorithm.js.map +1 -0
  72. package/node_modules/@oozcitak/dom/lib/algorithm/TraversalAlgorithm.d.ts +8 -0
  73. package/node_modules/@oozcitak/dom/lib/algorithm/TraversalAlgorithm.js +62 -0
  74. package/node_modules/@oozcitak/dom/lib/algorithm/TraversalAlgorithm.js.map +1 -0
  75. package/node_modules/@oozcitak/dom/lib/algorithm/TreeAlgorithm.d.ts +268 -0
  76. package/node_modules/@oozcitak/dom/lib/algorithm/TreeAlgorithm.js +853 -0
  77. package/node_modules/@oozcitak/dom/lib/algorithm/TreeAlgorithm.js.map +1 -0
  78. package/node_modules/@oozcitak/dom/lib/algorithm/TreeWalkerAlgorithm.d.ts +17 -0
  79. package/node_modules/@oozcitak/dom/lib/algorithm/TreeWalkerAlgorithm.js +147 -0
  80. package/node_modules/@oozcitak/dom/lib/algorithm/TreeWalkerAlgorithm.js.map +1 -0
  81. package/node_modules/@oozcitak/dom/lib/algorithm/WebIDLAlgorithm.d.ts +8 -0
  82. package/node_modules/@oozcitak/dom/lib/algorithm/WebIDLAlgorithm.js +14 -0
  83. package/node_modules/@oozcitak/dom/lib/algorithm/WebIDLAlgorithm.js.map +1 -0
  84. package/node_modules/@oozcitak/dom/lib/algorithm/XMLAlgorithm.d.ts +25 -0
  85. package/node_modules/@oozcitak/dom/lib/algorithm/XMLAlgorithm.js +164 -0
  86. package/node_modules/@oozcitak/dom/lib/algorithm/XMLAlgorithm.js.map +1 -0
  87. package/node_modules/@oozcitak/dom/lib/algorithm/index.d.ts +28 -0
  88. package/node_modules/@oozcitak/dom/lib/algorithm/index.js +34 -0
  89. package/node_modules/@oozcitak/dom/lib/algorithm/index.js.map +1 -0
  90. package/node_modules/@oozcitak/dom/lib/dom/AbortControllerImpl.d.ts +15 -0
  91. package/node_modules/@oozcitak/dom/lib/dom/AbortControllerImpl.js +32 -0
  92. package/node_modules/@oozcitak/dom/lib/dom/AbortControllerImpl.js.map +1 -0
  93. package/node_modules/@oozcitak/dom/lib/dom/AbortSignalImpl.d.ts +23 -0
  94. package/node_modules/@oozcitak/dom/lib/dom/AbortSignalImpl.js +59 -0
  95. package/node_modules/@oozcitak/dom/lib/dom/AbortSignalImpl.js.map +1 -0
  96. package/node_modules/@oozcitak/dom/lib/dom/AbstractRangeImpl.d.ts +23 -0
  97. package/node_modules/@oozcitak/dom/lib/dom/AbstractRangeImpl.js +70 -0
  98. package/node_modules/@oozcitak/dom/lib/dom/AbstractRangeImpl.js.map +1 -0
  99. package/node_modules/@oozcitak/dom/lib/dom/AttrImpl.d.ts +45 -0
  100. package/node_modules/@oozcitak/dom/lib/dom/AttrImpl.js +118 -0
  101. package/node_modules/@oozcitak/dom/lib/dom/AttrImpl.js.map +1 -0
  102. package/node_modules/@oozcitak/dom/lib/dom/CDATASectionImpl.d.ts +21 -0
  103. package/node_modules/@oozcitak/dom/lib/dom/CDATASectionImpl.js +51 -0
  104. package/node_modules/@oozcitak/dom/lib/dom/CDATASectionImpl.js.map +1 -0
  105. package/node_modules/@oozcitak/dom/lib/dom/CharacterDataImpl.d.ts +35 -0
  106. package/node_modules/@oozcitak/dom/lib/dom/CharacterDataImpl.js +132 -0
  107. package/node_modules/@oozcitak/dom/lib/dom/CharacterDataImpl.js.map +1 -0
  108. package/node_modules/@oozcitak/dom/lib/dom/ChildNodeImpl.d.ts +16 -0
  109. package/node_modules/@oozcitak/dom/lib/dom/ChildNodeImpl.js +165 -0
  110. package/node_modules/@oozcitak/dom/lib/dom/ChildNodeImpl.js.map +1 -0
  111. package/node_modules/@oozcitak/dom/lib/dom/CommentImpl.d.ts +21 -0
  112. package/node_modules/@oozcitak/dom/lib/dom/CommentImpl.js +52 -0
  113. package/node_modules/@oozcitak/dom/lib/dom/CommentImpl.js.map +1 -0
  114. package/node_modules/@oozcitak/dom/lib/dom/CustomEventImpl.d.ts +16 -0
  115. package/node_modules/@oozcitak/dom/lib/dom/CustomEventImpl.js +60 -0
  116. package/node_modules/@oozcitak/dom/lib/dom/CustomEventImpl.js.map +1 -0
  117. package/node_modules/@oozcitak/dom/lib/dom/DOMException.d.ts +171 -0
  118. package/node_modules/@oozcitak/dom/lib/dom/DOMException.js +347 -0
  119. package/node_modules/@oozcitak/dom/lib/dom/DOMException.js.map +1 -0
  120. package/node_modules/@oozcitak/dom/lib/dom/DOMImpl.d.ts +48 -0
  121. package/node_modules/@oozcitak/dom/lib/dom/DOMImpl.js +100 -0
  122. package/node_modules/@oozcitak/dom/lib/dom/DOMImpl.js.map +1 -0
  123. package/node_modules/@oozcitak/dom/lib/dom/DOMImplementationImpl.d.ts +29 -0
  124. package/node_modules/@oozcitak/dom/lib/dom/DOMImplementationImpl.js +149 -0
  125. package/node_modules/@oozcitak/dom/lib/dom/DOMImplementationImpl.js.map +1 -0
  126. package/node_modules/@oozcitak/dom/lib/dom/DOMTokenListImpl.d.ts +46 -0
  127. package/node_modules/@oozcitak/dom/lib/dom/DOMTokenListImpl.js +312 -0
  128. package/node_modules/@oozcitak/dom/lib/dom/DOMTokenListImpl.js.map +1 -0
  129. package/node_modules/@oozcitak/dom/lib/dom/DocumentFragmentImpl.d.ts +32 -0
  130. package/node_modules/@oozcitak/dom/lib/dom/DocumentFragmentImpl.js +103 -0
  131. package/node_modules/@oozcitak/dom/lib/dom/DocumentFragmentImpl.js.map +1 -0
  132. package/node_modules/@oozcitak/dom/lib/dom/DocumentImpl.d.ts +116 -0
  133. package/node_modules/@oozcitak/dom/lib/dom/DocumentImpl.js +545 -0
  134. package/node_modules/@oozcitak/dom/lib/dom/DocumentImpl.js.map +1 -0
  135. package/node_modules/@oozcitak/dom/lib/dom/DocumentOrShadowRootImpl.d.ts +11 -0
  136. package/node_modules/@oozcitak/dom/lib/dom/DocumentOrShadowRootImpl.js +17 -0
  137. package/node_modules/@oozcitak/dom/lib/dom/DocumentOrShadowRootImpl.js.map +1 -0
  138. package/node_modules/@oozcitak/dom/lib/dom/DocumentTypeImpl.d.ts +39 -0
  139. package/node_modules/@oozcitak/dom/lib/dom/DocumentTypeImpl.js +109 -0
  140. package/node_modules/@oozcitak/dom/lib/dom/DocumentTypeImpl.js.map +1 -0
  141. package/node_modules/@oozcitak/dom/lib/dom/ElementImpl.d.ts +132 -0
  142. package/node_modules/@oozcitak/dom/lib/dom/ElementImpl.js +714 -0
  143. package/node_modules/@oozcitak/dom/lib/dom/ElementImpl.js.map +1 -0
  144. package/node_modules/@oozcitak/dom/lib/dom/EventImpl.d.ts +74 -0
  145. package/node_modules/@oozcitak/dom/lib/dom/EventImpl.js +313 -0
  146. package/node_modules/@oozcitak/dom/lib/dom/EventImpl.js.map +1 -0
  147. package/node_modules/@oozcitak/dom/lib/dom/EventTargetImpl.d.ts +30 -0
  148. package/node_modules/@oozcitak/dom/lib/dom/EventTargetImpl.js +133 -0
  149. package/node_modules/@oozcitak/dom/lib/dom/EventTargetImpl.js.map +1 -0
  150. package/node_modules/@oozcitak/dom/lib/dom/HTMLCollectionImpl.d.ts +44 -0
  151. package/node_modules/@oozcitak/dom/lib/dom/HTMLCollectionImpl.js +157 -0
  152. package/node_modules/@oozcitak/dom/lib/dom/HTMLCollectionImpl.js.map +1 -0
  153. package/node_modules/@oozcitak/dom/lib/dom/MutationObserverImpl.d.ts +22 -0
  154. package/node_modules/@oozcitak/dom/lib/dom/MutationObserverImpl.js +184 -0
  155. package/node_modules/@oozcitak/dom/lib/dom/MutationObserverImpl.js.map +1 -0
  156. package/node_modules/@oozcitak/dom/lib/dom/MutationRecordImpl.d.ts +73 -0
  157. package/node_modules/@oozcitak/dom/lib/dom/MutationRecordImpl.js +116 -0
  158. package/node_modules/@oozcitak/dom/lib/dom/MutationRecordImpl.js.map +1 -0
  159. package/node_modules/@oozcitak/dom/lib/dom/NamedNodeMapImpl.d.ts +34 -0
  160. package/node_modules/@oozcitak/dom/lib/dom/NamedNodeMapImpl.js +112 -0
  161. package/node_modules/@oozcitak/dom/lib/dom/NamedNodeMapImpl.js.map +1 -0
  162. package/node_modules/@oozcitak/dom/lib/dom/NodeFilterImpl.d.ts +50 -0
  163. package/node_modules/@oozcitak/dom/lib/dom/NodeFilterImpl.js +64 -0
  164. package/node_modules/@oozcitak/dom/lib/dom/NodeFilterImpl.js.map +1 -0
  165. package/node_modules/@oozcitak/dom/lib/dom/NodeImpl.d.ts +252 -0
  166. package/node_modules/@oozcitak/dom/lib/dom/NodeImpl.js +891 -0
  167. package/node_modules/@oozcitak/dom/lib/dom/NodeImpl.js.map +1 -0
  168. package/node_modules/@oozcitak/dom/lib/dom/NodeIteratorImpl.d.ts +34 -0
  169. package/node_modules/@oozcitak/dom/lib/dom/NodeIteratorImpl.js +86 -0
  170. package/node_modules/@oozcitak/dom/lib/dom/NodeIteratorImpl.js.map +1 -0
  171. package/node_modules/@oozcitak/dom/lib/dom/NodeListImpl.d.ts +46 -0
  172. package/node_modules/@oozcitak/dom/lib/dom/NodeListImpl.js +198 -0
  173. package/node_modules/@oozcitak/dom/lib/dom/NodeListImpl.js.map +1 -0
  174. package/node_modules/@oozcitak/dom/lib/dom/NodeListStaticImpl.d.ts +49 -0
  175. package/node_modules/@oozcitak/dom/lib/dom/NodeListStaticImpl.js +188 -0
  176. package/node_modules/@oozcitak/dom/lib/dom/NodeListStaticImpl.js.map +1 -0
  177. package/node_modules/@oozcitak/dom/lib/dom/NonDocumentTypeChildNodeImpl.d.ts +12 -0
  178. package/node_modules/@oozcitak/dom/lib/dom/NonDocumentTypeChildNodeImpl.js +53 -0
  179. package/node_modules/@oozcitak/dom/lib/dom/NonDocumentTypeChildNodeImpl.js.map +1 -0
  180. package/node_modules/@oozcitak/dom/lib/dom/NonElementParentNodeImpl.d.ts +9 -0
  181. package/node_modules/@oozcitak/dom/lib/dom/NonElementParentNodeImpl.js +31 -0
  182. package/node_modules/@oozcitak/dom/lib/dom/NonElementParentNodeImpl.js.map +1 -0
  183. package/node_modules/@oozcitak/dom/lib/dom/ParentNodeImpl.d.ts +24 -0
  184. package/node_modules/@oozcitak/dom/lib/dom/ParentNodeImpl.js +158 -0
  185. package/node_modules/@oozcitak/dom/lib/dom/ParentNodeImpl.js.map +1 -0
  186. package/node_modules/@oozcitak/dom/lib/dom/ProcessingInstructionImpl.d.ts +25 -0
  187. package/node_modules/@oozcitak/dom/lib/dom/ProcessingInstructionImpl.js +59 -0
  188. package/node_modules/@oozcitak/dom/lib/dom/ProcessingInstructionImpl.js.map +1 -0
  189. package/node_modules/@oozcitak/dom/lib/dom/RangeImpl.d.ts +71 -0
  190. package/node_modules/@oozcitak/dom/lib/dom/RangeImpl.js +649 -0
  191. package/node_modules/@oozcitak/dom/lib/dom/RangeImpl.js.map +1 -0
  192. package/node_modules/@oozcitak/dom/lib/dom/ShadowRootImpl.d.ts +33 -0
  193. package/node_modules/@oozcitak/dom/lib/dom/ShadowRootImpl.js +82 -0
  194. package/node_modules/@oozcitak/dom/lib/dom/ShadowRootImpl.js.map +1 -0
  195. package/node_modules/@oozcitak/dom/lib/dom/SlotableImpl.d.ts +16 -0
  196. package/node_modules/@oozcitak/dom/lib/dom/SlotableImpl.js +35 -0
  197. package/node_modules/@oozcitak/dom/lib/dom/SlotableImpl.js.map +1 -0
  198. package/node_modules/@oozcitak/dom/lib/dom/StaticRangeImpl.d.ts +13 -0
  199. package/node_modules/@oozcitak/dom/lib/dom/StaticRangeImpl.js +48 -0
  200. package/node_modules/@oozcitak/dom/lib/dom/StaticRangeImpl.js.map +1 -0
  201. package/node_modules/@oozcitak/dom/lib/dom/TextImpl.d.ts +28 -0
  202. package/node_modules/@oozcitak/dom/lib/dom/TextImpl.js +109 -0
  203. package/node_modules/@oozcitak/dom/lib/dom/TextImpl.js.map +1 -0
  204. package/node_modules/@oozcitak/dom/lib/dom/TraverserImpl.d.ts +23 -0
  205. package/node_modules/@oozcitak/dom/lib/dom/TraverserImpl.js +41 -0
  206. package/node_modules/@oozcitak/dom/lib/dom/TraverserImpl.js.map +1 -0
  207. package/node_modules/@oozcitak/dom/lib/dom/TreeWalkerImpl.d.ts +36 -0
  208. package/node_modules/@oozcitak/dom/lib/dom/TreeWalkerImpl.js +249 -0
  209. package/node_modules/@oozcitak/dom/lib/dom/TreeWalkerImpl.js.map +1 -0
  210. package/node_modules/@oozcitak/dom/lib/dom/WindowImpl.d.ts +26 -0
  211. package/node_modules/@oozcitak/dom/lib/dom/WindowImpl.js +57 -0
  212. package/node_modules/@oozcitak/dom/lib/dom/WindowImpl.js.map +1 -0
  213. package/node_modules/@oozcitak/dom/lib/dom/XMLDocumentImpl.d.ts +11 -0
  214. package/node_modules/@oozcitak/dom/lib/dom/XMLDocumentImpl.js +31 -0
  215. package/node_modules/@oozcitak/dom/lib/dom/XMLDocumentImpl.js.map +1 -0
  216. package/node_modules/@oozcitak/dom/lib/dom/index.d.ts +36 -0
  217. package/node_modules/@oozcitak/dom/lib/dom/index.js +102 -0
  218. package/node_modules/@oozcitak/dom/lib/dom/index.js.map +1 -0
  219. package/node_modules/@oozcitak/dom/lib/dom/interfaces.d.ts +2218 -0
  220. package/node_modules/@oozcitak/dom/lib/dom/interfaces.js +91 -0
  221. package/node_modules/@oozcitak/dom/lib/dom/interfaces.js.map +1 -0
  222. package/node_modules/@oozcitak/dom/lib/index.d.ts +3 -0
  223. package/node_modules/@oozcitak/dom/lib/index.js +11 -0
  224. package/node_modules/@oozcitak/dom/lib/index.js.map +1 -0
  225. package/node_modules/@oozcitak/dom/lib/parser/DOMParserImpl.d.ts +11 -0
  226. package/node_modules/@oozcitak/dom/lib/parser/DOMParserImpl.js +37 -0
  227. package/node_modules/@oozcitak/dom/lib/parser/DOMParserImpl.js.map +1 -0
  228. package/node_modules/@oozcitak/dom/lib/parser/XMLParserImpl.d.ts +26 -0
  229. package/node_modules/@oozcitak/dom/lib/parser/XMLParserImpl.js +240 -0
  230. package/node_modules/@oozcitak/dom/lib/parser/XMLParserImpl.js.map +1 -0
  231. package/node_modules/@oozcitak/dom/lib/parser/XMLStringLexer.d.ts +159 -0
  232. package/node_modules/@oozcitak/dom/lib/parser/XMLStringLexer.js +512 -0
  233. package/node_modules/@oozcitak/dom/lib/parser/XMLStringLexer.js.map +1 -0
  234. package/node_modules/@oozcitak/dom/lib/parser/index.d.ts +1 -0
  235. package/node_modules/@oozcitak/dom/lib/parser/index.js +6 -0
  236. package/node_modules/@oozcitak/dom/lib/parser/index.js.map +1 -0
  237. package/node_modules/@oozcitak/dom/lib/parser/interfaces.d.ts +131 -0
  238. package/node_modules/@oozcitak/dom/lib/parser/interfaces.js +18 -0
  239. package/node_modules/@oozcitak/dom/lib/parser/interfaces.js.map +1 -0
  240. package/node_modules/@oozcitak/dom/lib/serializer/LocalNameSet.d.ts +27 -0
  241. package/node_modules/@oozcitak/dom/lib/serializer/LocalNameSet.js +56 -0
  242. package/node_modules/@oozcitak/dom/lib/serializer/LocalNameSet.js.map +1 -0
  243. package/node_modules/@oozcitak/dom/lib/serializer/NamespacePrefixMap.d.ts +52 -0
  244. package/node_modules/@oozcitak/dom/lib/serializer/NamespacePrefixMap.js +151 -0
  245. package/node_modules/@oozcitak/dom/lib/serializer/NamespacePrefixMap.js.map +1 -0
  246. package/node_modules/@oozcitak/dom/lib/serializer/XMLSerializerImpl.d.ts +166 -0
  247. package/node_modules/@oozcitak/dom/lib/serializer/XMLSerializerImpl.js +1479 -0
  248. package/node_modules/@oozcitak/dom/lib/serializer/XMLSerializerImpl.js.map +1 -0
  249. package/node_modules/@oozcitak/dom/lib/serializer/index.d.ts +1 -0
  250. package/node_modules/@oozcitak/dom/lib/serializer/index.js +6 -0
  251. package/node_modules/@oozcitak/dom/lib/serializer/index.js.map +1 -0
  252. package/node_modules/@oozcitak/dom/lib/serializer/interfaces.d.ts +15 -0
  253. package/node_modules/@oozcitak/dom/lib/serializer/interfaces.js +3 -0
  254. package/node_modules/@oozcitak/dom/lib/serializer/interfaces.js.map +1 -0
  255. package/node_modules/@oozcitak/dom/lib/util/Cast.d.ts +12 -0
  256. package/node_modules/@oozcitak/dom/lib/util/Cast.js +26 -0
  257. package/node_modules/@oozcitak/dom/lib/util/Cast.js.map +1 -0
  258. package/node_modules/@oozcitak/dom/lib/util/EmptySet.d.ts +13 -0
  259. package/node_modules/@oozcitak/dom/lib/util/EmptySet.js +61 -0
  260. package/node_modules/@oozcitak/dom/lib/util/EmptySet.js.map +1 -0
  261. package/node_modules/@oozcitak/dom/lib/util/Guard.d.ts +135 -0
  262. package/node_modules/@oozcitak/dom/lib/util/Guard.js +192 -0
  263. package/node_modules/@oozcitak/dom/lib/util/Guard.js.map +1 -0
  264. package/node_modules/@oozcitak/dom/lib/util/index.d.ts +3 -0
  265. package/node_modules/@oozcitak/dom/lib/util/index.js +9 -0
  266. package/node_modules/@oozcitak/dom/lib/util/index.js.map +1 -0
  267. package/node_modules/@oozcitak/dom/package.json +72 -0
  268. package/node_modules/@oozcitak/infra/LICENSE +21 -0
  269. package/node_modules/@oozcitak/infra/README.md +13 -0
  270. package/node_modules/@oozcitak/infra/lib/Base64.d.ts +12 -0
  271. package/node_modules/@oozcitak/infra/lib/Base64.js +82 -0
  272. package/node_modules/@oozcitak/infra/lib/Base64.js.map +1 -0
  273. package/node_modules/@oozcitak/infra/lib/Byte.d.ts +6 -0
  274. package/node_modules/@oozcitak/infra/lib/Byte.js +15 -0
  275. package/node_modules/@oozcitak/infra/lib/Byte.js.map +1 -0
  276. package/node_modules/@oozcitak/infra/lib/ByteSequence.d.ts +45 -0
  277. package/node_modules/@oozcitak/infra/lib/ByteSequence.js +171 -0
  278. package/node_modules/@oozcitak/infra/lib/ByteSequence.js.map +1 -0
  279. package/node_modules/@oozcitak/infra/lib/CodePoints.d.ts +82 -0
  280. package/node_modules/@oozcitak/infra/lib/CodePoints.js +85 -0
  281. package/node_modules/@oozcitak/infra/lib/CodePoints.js.map +1 -0
  282. package/node_modules/@oozcitak/infra/lib/JSON.d.ts +24 -0
  283. package/node_modules/@oozcitak/infra/lib/JSON.js +123 -0
  284. package/node_modules/@oozcitak/infra/lib/JSON.js.map +1 -0
  285. package/node_modules/@oozcitak/infra/lib/List.d.ts +101 -0
  286. package/node_modules/@oozcitak/infra/lib/List.js +325 -0
  287. package/node_modules/@oozcitak/infra/lib/List.js.map +1 -0
  288. package/node_modules/@oozcitak/infra/lib/Map.d.ts +87 -0
  289. package/node_modules/@oozcitak/infra/lib/Map.js +308 -0
  290. package/node_modules/@oozcitak/infra/lib/Map.js.map +1 -0
  291. package/node_modules/@oozcitak/infra/lib/Namespace.d.ts +6 -0
  292. package/node_modules/@oozcitak/infra/lib/Namespace.js +9 -0
  293. package/node_modules/@oozcitak/infra/lib/Namespace.js.map +1 -0
  294. package/node_modules/@oozcitak/infra/lib/Queue.d.ts +13 -0
  295. package/node_modules/@oozcitak/infra/lib/Queue.js +22 -0
  296. package/node_modules/@oozcitak/infra/lib/Queue.js.map +1 -0
  297. package/node_modules/@oozcitak/infra/lib/Set.d.ts +136 -0
  298. package/node_modules/@oozcitak/infra/lib/Set.js +467 -0
  299. package/node_modules/@oozcitak/infra/lib/Set.js.map +1 -0
  300. package/node_modules/@oozcitak/infra/lib/Stack.d.ts +13 -0
  301. package/node_modules/@oozcitak/infra/lib/Stack.js +22 -0
  302. package/node_modules/@oozcitak/infra/lib/Stack.js.map +1 -0
  303. package/node_modules/@oozcitak/infra/lib/String.d.ts +129 -0
  304. package/node_modules/@oozcitak/infra/lib/String.js +472 -0
  305. package/node_modules/@oozcitak/infra/lib/String.js.map +1 -0
  306. package/node_modules/@oozcitak/infra/lib/index.d.ts +13 -0
  307. package/node_modules/@oozcitak/infra/lib/index.js +34 -0
  308. package/node_modules/@oozcitak/infra/lib/index.js.map +1 -0
  309. package/node_modules/@oozcitak/infra/package.json +54 -0
  310. package/node_modules/@oozcitak/url/LICENSE +21 -0
  311. package/node_modules/@oozcitak/url/README.md +27 -0
  312. package/node_modules/@oozcitak/url/lib/URLAlgorithm.d.ts +267 -0
  313. package/node_modules/@oozcitak/url/lib/URLAlgorithm.js +2758 -0
  314. package/node_modules/@oozcitak/url/lib/URLAlgorithm.js.map +1 -0
  315. package/node_modules/@oozcitak/url/lib/URLImpl.d.ts +53 -0
  316. package/node_modules/@oozcitak/url/lib/URLImpl.js +377 -0
  317. package/node_modules/@oozcitak/url/lib/URLImpl.js.map +1 -0
  318. package/node_modules/@oozcitak/url/lib/URLSearchParamsImpl.d.ts +38 -0
  319. package/node_modules/@oozcitak/url/lib/URLSearchParamsImpl.js +303 -0
  320. package/node_modules/@oozcitak/url/lib/URLSearchParamsImpl.js.map +1 -0
  321. package/node_modules/@oozcitak/url/lib/index.d.ts +2 -0
  322. package/node_modules/@oozcitak/url/lib/index.js +7 -0
  323. package/node_modules/@oozcitak/url/lib/index.js.map +1 -0
  324. package/node_modules/@oozcitak/url/lib/interfaces.d.ts +195 -0
  325. package/node_modules/@oozcitak/url/lib/interfaces.js +31 -0
  326. package/node_modules/@oozcitak/url/lib/interfaces.js.map +1 -0
  327. package/node_modules/@oozcitak/url/package.json +55 -0
  328. package/node_modules/@oozcitak/util/LICENSE +21 -0
  329. package/node_modules/@oozcitak/util/README.md +10 -0
  330. package/node_modules/@oozcitak/util/lib/CompareCache.d.ts +32 -0
  331. package/node_modules/@oozcitak/util/lib/CompareCache.js +59 -0
  332. package/node_modules/@oozcitak/util/lib/CompareCache.js.map +1 -0
  333. package/node_modules/@oozcitak/util/lib/FixedSizeSet.d.ts +64 -0
  334. package/node_modules/@oozcitak/util/lib/FixedSizeSet.js +174 -0
  335. package/node_modules/@oozcitak/util/lib/FixedSizeSet.js.map +1 -0
  336. package/node_modules/@oozcitak/util/lib/Lazy.d.ts +18 -0
  337. package/node_modules/@oozcitak/util/lib/Lazy.js +34 -0
  338. package/node_modules/@oozcitak/util/lib/Lazy.js.map +1 -0
  339. package/node_modules/@oozcitak/util/lib/ObjectCache.d.ts +71 -0
  340. package/node_modules/@oozcitak/util/lib/ObjectCache.js +181 -0
  341. package/node_modules/@oozcitak/util/lib/ObjectCache.js.map +1 -0
  342. package/node_modules/@oozcitak/util/lib/StringWalker.d.ts +49 -0
  343. package/node_modules/@oozcitak/util/lib/StringWalker.js +105 -0
  344. package/node_modules/@oozcitak/util/lib/StringWalker.js.map +1 -0
  345. package/node_modules/@oozcitak/util/lib/index.d.ts +178 -0
  346. package/node_modules/@oozcitak/util/lib/index.js +439 -0
  347. package/node_modules/@oozcitak/util/lib/index.js.map +1 -0
  348. package/node_modules/@oozcitak/util/package.json +50 -0
  349. package/node_modules/@xmldom/is-dom-node/LICENSE.md +21 -0
  350. package/node_modules/@xmldom/is-dom-node/README.md +91 -0
  351. package/node_modules/@xmldom/is-dom-node/dist/index.d.ts +33 -0
  352. package/node_modules/@xmldom/is-dom-node/dist/index.js +91 -0
  353. package/node_modules/@xmldom/is-dom-node/dist/index.js.map +1 -0
  354. package/node_modules/@xmldom/is-dom-node/package.json +69 -0
  355. package/node_modules/@xmldom/xmldom/CHANGELOG.md +468 -0
  356. package/node_modules/@xmldom/xmldom/LICENSE +8 -0
  357. package/node_modules/@xmldom/xmldom/SECURITY.md +50 -0
  358. package/node_modules/@xmldom/xmldom/index.d.ts +43 -0
  359. package/node_modules/@xmldom/xmldom/lib/.eslintrc.yml +2 -0
  360. package/node_modules/@xmldom/xmldom/lib/conventions.js +203 -0
  361. package/node_modules/@xmldom/xmldom/lib/dom-parser.js +322 -0
  362. package/node_modules/@xmldom/xmldom/lib/dom.js +1879 -0
  363. package/node_modules/@xmldom/xmldom/lib/entities.js +2166 -0
  364. package/node_modules/@xmldom/xmldom/lib/index.js +4 -0
  365. package/node_modules/@xmldom/xmldom/lib/sax.js +662 -0
  366. package/node_modules/@xmldom/xmldom/package.json +71 -0
  367. package/node_modules/@xmldom/xmldom/readme.md +356 -0
  368. package/node_modules/esprima/ChangeLog +235 -0
  369. package/node_modules/esprima/LICENSE.BSD +21 -0
  370. package/node_modules/esprima/README.md +46 -0
  371. package/node_modules/esprima/bin/esparse.js +139 -0
  372. package/node_modules/esprima/bin/esvalidate.js +236 -0
  373. package/node_modules/esprima/dist/esprima.js +6709 -0
  374. package/node_modules/esprima/package.json +112 -0
  375. package/node_modules/node-forge/LICENSE +331 -0
  376. package/node_modules/node-forge/README.md +2071 -0
  377. package/node_modules/node-forge/dist/forge.all.min.js +2 -0
  378. package/node_modules/node-forge/dist/forge.all.min.js.map +1 -0
  379. package/node_modules/node-forge/dist/forge.min.js +2 -0
  380. package/node_modules/node-forge/dist/forge.min.js.map +1 -0
  381. package/node_modules/node-forge/dist/prime.worker.min.js +2 -0
  382. package/node_modules/node-forge/dist/prime.worker.min.js.map +1 -0
  383. package/node_modules/node-forge/flash/swf/SocketPool.swf +0 -0
  384. package/node_modules/node-forge/lib/aes.js +1091 -0
  385. package/node_modules/node-forge/lib/aesCipherSuites.js +282 -0
  386. package/node_modules/node-forge/lib/asn1-validator.js +91 -0
  387. package/node_modules/node-forge/lib/asn1.js +1503 -0
  388. package/node_modules/node-forge/lib/baseN.js +186 -0
  389. package/node_modules/node-forge/lib/cipher.js +230 -0
  390. package/node_modules/node-forge/lib/cipherModes.js +999 -0
  391. package/node_modules/node-forge/lib/des.js +496 -0
  392. package/node_modules/node-forge/lib/ed25519.js +1072 -0
  393. package/node_modules/node-forge/lib/forge.js +13 -0
  394. package/node_modules/node-forge/lib/form.js +149 -0
  395. package/node_modules/node-forge/lib/hmac.js +146 -0
  396. package/node_modules/node-forge/lib/http.js +1346 -0
  397. package/node_modules/node-forge/lib/index.all.js +16 -0
  398. package/node_modules/node-forge/lib/index.js +33 -0
  399. package/node_modules/node-forge/lib/jsbn.js +1264 -0
  400. package/node_modules/node-forge/lib/kem.js +168 -0
  401. package/node_modules/node-forge/lib/log.js +319 -0
  402. package/node_modules/node-forge/lib/md.all.js +13 -0
  403. package/node_modules/node-forge/lib/md.js +11 -0
  404. package/node_modules/node-forge/lib/md5.js +289 -0
  405. package/node_modules/node-forge/lib/mgf.js +12 -0
  406. package/node_modules/node-forge/lib/mgf1.js +57 -0
  407. package/node_modules/node-forge/lib/oids.js +179 -0
  408. package/node_modules/node-forge/lib/pbe.js +1023 -0
  409. package/node_modules/node-forge/lib/pbkdf2.js +211 -0
  410. package/node_modules/node-forge/lib/pem.js +237 -0
  411. package/node_modules/node-forge/lib/pkcs1.js +276 -0
  412. package/node_modules/node-forge/lib/pkcs12.js +1078 -0
  413. package/node_modules/node-forge/lib/pkcs7.js +1260 -0
  414. package/node_modules/node-forge/lib/pkcs7asn1.js +410 -0
  415. package/node_modules/node-forge/lib/pki.js +102 -0
  416. package/node_modules/node-forge/lib/prime.js +297 -0
  417. package/node_modules/node-forge/lib/prime.worker.js +168 -0
  418. package/node_modules/node-forge/lib/prng.js +419 -0
  419. package/node_modules/node-forge/lib/pss.js +241 -0
  420. package/node_modules/node-forge/lib/random.js +191 -0
  421. package/node_modules/node-forge/lib/rc2.js +410 -0
  422. package/node_modules/node-forge/lib/rsa.js +1949 -0
  423. package/node_modules/node-forge/lib/sha1.js +319 -0
  424. package/node_modules/node-forge/lib/sha256.js +327 -0
  425. package/node_modules/node-forge/lib/sha512.js +561 -0
  426. package/node_modules/node-forge/lib/socket.js +287 -0
  427. package/node_modules/node-forge/lib/ssh.js +236 -0
  428. package/node_modules/node-forge/lib/tls.js +4282 -0
  429. package/node_modules/node-forge/lib/tlssocket.js +249 -0
  430. package/node_modules/node-forge/lib/util.js +2652 -0
  431. package/node_modules/node-forge/lib/x509.js +3242 -0
  432. package/node_modules/node-forge/lib/xhr.js +738 -0
  433. package/node_modules/node-forge/package.json +123 -0
  434. package/node_modules/sprintf-js/.npmignore +1 -0
  435. package/node_modules/sprintf-js/LICENSE +24 -0
  436. package/node_modules/sprintf-js/README.md +88 -0
  437. package/node_modules/sprintf-js/bower.json +14 -0
  438. package/node_modules/sprintf-js/demo/angular.html +20 -0
  439. package/node_modules/sprintf-js/dist/angular-sprintf.min.js +4 -0
  440. package/node_modules/sprintf-js/dist/angular-sprintf.min.js.map +1 -0
  441. package/node_modules/sprintf-js/dist/angular-sprintf.min.map +1 -0
  442. package/node_modules/sprintf-js/dist/sprintf.min.js +4 -0
  443. package/node_modules/sprintf-js/dist/sprintf.min.js.map +1 -0
  444. package/node_modules/sprintf-js/dist/sprintf.min.map +1 -0
  445. package/node_modules/sprintf-js/gruntfile.js +36 -0
  446. package/node_modules/sprintf-js/package.json +22 -0
  447. package/node_modules/sprintf-js/src/angular-sprintf.js +18 -0
  448. package/node_modules/sprintf-js/src/sprintf.js +208 -0
  449. package/node_modules/sprintf-js/test/test.js +82 -0
  450. package/node_modules/xml-crypto/LICENSE +22 -0
  451. package/node_modules/xml-crypto/README.md +557 -0
  452. package/node_modules/xml-crypto/lib/c14n-canonicalization.d.ts +39 -0
  453. package/node_modules/xml-crypto/lib/c14n-canonicalization.js +230 -0
  454. package/node_modules/xml-crypto/lib/c14n-canonicalization.js.map +1 -0
  455. package/node_modules/xml-crypto/lib/enveloped-signature.d.ts +7 -0
  456. package/node_modules/xml-crypto/lib/enveloped-signature.js +43 -0
  457. package/node_modules/xml-crypto/lib/enveloped-signature.js.map +1 -0
  458. package/node_modules/xml-crypto/lib/exclusive-canonicalization.d.ts +38 -0
  459. package/node_modules/xml-crypto/lib/exclusive-canonicalization.js +246 -0
  460. package/node_modules/xml-crypto/lib/exclusive-canonicalization.js.map +1 -0
  461. package/node_modules/xml-crypto/lib/hash-algorithms.d.ts +13 -0
  462. package/node_modules/xml-crypto/lib/hash-algorithms.js +47 -0
  463. package/node_modules/xml-crypto/lib/hash-algorithms.js.map +1 -0
  464. package/node_modules/xml-crypto/lib/index.d.ts +5 -0
  465. package/node_modules/xml-crypto/lib/index.js +28 -0
  466. package/node_modules/xml-crypto/lib/index.js.map +1 -0
  467. package/node_modules/xml-crypto/lib/signature-algorithms.d.ts +47 -0
  468. package/node_modules/xml-crypto/lib/signature-algorithms.js +86 -0
  469. package/node_modules/xml-crypto/lib/signature-algorithms.js.map +1 -0
  470. package/node_modules/xml-crypto/lib/signed-xml.d.ts +225 -0
  471. package/node_modules/xml-crypto/lib/signed-xml.js +960 -0
  472. package/node_modules/xml-crypto/lib/signed-xml.js.map +1 -0
  473. package/node_modules/xml-crypto/lib/types.d.ts +125 -0
  474. package/node_modules/xml-crypto/lib/types.js +57 -0
  475. package/node_modules/xml-crypto/lib/types.js.map +1 -0
  476. package/node_modules/xml-crypto/lib/utils.d.ts +65 -0
  477. package/node_modules/xml-crypto/lib/utils.js +256 -0
  478. package/node_modules/xml-crypto/lib/utils.js.map +1 -0
  479. package/node_modules/xml-crypto/node_modules/xpath/LICENSE +22 -0
  480. package/node_modules/xml-crypto/node_modules/xpath/README.md +133 -0
  481. package/node_modules/xml-crypto/node_modules/xpath/docs/XPathEvaluator.md +62 -0
  482. package/node_modules/xml-crypto/node_modules/xpath/docs/XPathResult.md +47 -0
  483. package/node_modules/xml-crypto/node_modules/xpath/docs/function resolvers.md +88 -0
  484. package/node_modules/xml-crypto/node_modules/xpath/docs/namespace resolvers.md +69 -0
  485. package/node_modules/xml-crypto/node_modules/xpath/docs/parsed expressions.md +21 -0
  486. package/node_modules/xml-crypto/node_modules/xpath/docs/variable resolvers.md +89 -0
  487. package/node_modules/xml-crypto/node_modules/xpath/docs/xpath methods.md +39 -0
  488. package/node_modules/xml-crypto/node_modules/xpath/package.json +39 -0
  489. package/node_modules/xml-crypto/node_modules/xpath/test.js +1186 -0
  490. package/node_modules/xml-crypto/node_modules/xpath/xpath.d.ts +51 -0
  491. package/node_modules/xml-crypto/node_modules/xpath/xpath.js +4938 -0
  492. package/node_modules/xml-crypto/package.json +73 -0
  493. package/node_modules/xmlbuilder2/CHANGELOG.md +309 -0
  494. package/node_modules/xmlbuilder2/LICENSE +21 -0
  495. package/node_modules/xmlbuilder2/README.md +183 -0
  496. package/node_modules/xmlbuilder2/lib/builder/BuilderFunctions.d.ts +236 -0
  497. package/node_modules/xmlbuilder2/lib/builder/BuilderFunctions.js +108 -0
  498. package/node_modules/xmlbuilder2/lib/builder/BuilderFunctions.js.map +1 -0
  499. package/node_modules/xmlbuilder2/lib/builder/BuilderFunctionsCB.d.ts +17 -0
  500. package/node_modules/xmlbuilder2/lib/builder/BuilderFunctionsCB.js +26 -0
  501. package/node_modules/xmlbuilder2/lib/builder/BuilderFunctionsCB.js.map +1 -0
  502. package/node_modules/xmlbuilder2/lib/builder/XMLBuilderCBImpl.d.ts +124 -0
  503. package/node_modules/xmlbuilder2/lib/builder/XMLBuilderCBImpl.js +782 -0
  504. package/node_modules/xmlbuilder2/lib/builder/XMLBuilderCBImpl.js.map +1 -0
  505. package/node_modules/xmlbuilder2/lib/builder/XMLBuilderImpl.d.ts +143 -0
  506. package/node_modules/xmlbuilder2/lib/builder/XMLBuilderImpl.js +841 -0
  507. package/node_modules/xmlbuilder2/lib/builder/XMLBuilderImpl.js.map +1 -0
  508. package/node_modules/xmlbuilder2/lib/builder/dom.d.ts +8 -0
  509. package/node_modules/xmlbuilder2/lib/builder/dom.js +67 -0
  510. package/node_modules/xmlbuilder2/lib/builder/dom.js.map +1 -0
  511. package/node_modules/xmlbuilder2/lib/builder/index.d.ts +4 -0
  512. package/node_modules/xmlbuilder2/lib/builder/index.js +15 -0
  513. package/node_modules/xmlbuilder2/lib/builder/index.js.map +1 -0
  514. package/node_modules/xmlbuilder2/lib/constants.d.ts +1 -0
  515. package/node_modules/xmlbuilder2/lib/constants.js +4 -0
  516. package/node_modules/xmlbuilder2/lib/constants.js.map +1 -0
  517. package/node_modules/xmlbuilder2/lib/index.d.ts +1 -0
  518. package/node_modules/xmlbuilder2/lib/index.js +10 -0
  519. package/node_modules/xmlbuilder2/lib/index.js.map +1 -0
  520. package/node_modules/xmlbuilder2/lib/interfaces.d.ts +1355 -0
  521. package/node_modules/xmlbuilder2/lib/interfaces.js +76 -0
  522. package/node_modules/xmlbuilder2/lib/interfaces.js.map +1 -0
  523. package/node_modules/xmlbuilder2/lib/readers/BaseReader.d.ts +109 -0
  524. package/node_modules/xmlbuilder2/lib/readers/BaseReader.js +167 -0
  525. package/node_modules/xmlbuilder2/lib/readers/BaseReader.js.map +1 -0
  526. package/node_modules/xmlbuilder2/lib/readers/JSONReader.d.ts +14 -0
  527. package/node_modules/xmlbuilder2/lib/readers/JSONReader.js +38 -0
  528. package/node_modules/xmlbuilder2/lib/readers/JSONReader.js.map +1 -0
  529. package/node_modules/xmlbuilder2/lib/readers/ObjectReader.d.ts +15 -0
  530. package/node_modules/xmlbuilder2/lib/readers/ObjectReader.js +168 -0
  531. package/node_modules/xmlbuilder2/lib/readers/ObjectReader.js.map +1 -0
  532. package/node_modules/xmlbuilder2/lib/readers/XMLReader.d.ts +14 -0
  533. package/node_modules/xmlbuilder2/lib/readers/XMLReader.js +206 -0
  534. package/node_modules/xmlbuilder2/lib/readers/XMLReader.js.map +1 -0
  535. package/node_modules/xmlbuilder2/lib/readers/YAMLReader.d.ts +14 -0
  536. package/node_modules/xmlbuilder2/lib/readers/YAMLReader.js +44 -0
  537. package/node_modules/xmlbuilder2/lib/readers/YAMLReader.js.map +1 -0
  538. package/node_modules/xmlbuilder2/lib/readers/index.d.ts +4 -0
  539. package/node_modules/xmlbuilder2/lib/readers/index.js +11 -0
  540. package/node_modules/xmlbuilder2/lib/readers/index.js.map +1 -0
  541. package/node_modules/xmlbuilder2/lib/writers/BaseCBWriter.d.ts +110 -0
  542. package/node_modules/xmlbuilder2/lib/writers/BaseCBWriter.js +23 -0
  543. package/node_modules/xmlbuilder2/lib/writers/BaseCBWriter.js.map +1 -0
  544. package/node_modules/xmlbuilder2/lib/writers/BaseWriter.d.ts +276 -0
  545. package/node_modules/xmlbuilder2/lib/writers/BaseWriter.js +1603 -0
  546. package/node_modules/xmlbuilder2/lib/writers/BaseWriter.js.map +1 -0
  547. package/node_modules/xmlbuilder2/lib/writers/JSONCBWriter.d.ts +68 -0
  548. package/node_modules/xmlbuilder2/lib/writers/JSONCBWriter.js +172 -0
  549. package/node_modules/xmlbuilder2/lib/writers/JSONCBWriter.js.map +1 -0
  550. package/node_modules/xmlbuilder2/lib/writers/JSONWriter.d.ts +67 -0
  551. package/node_modules/xmlbuilder2/lib/writers/JSONWriter.js +222 -0
  552. package/node_modules/xmlbuilder2/lib/writers/JSONWriter.js.map +1 -0
  553. package/node_modules/xmlbuilder2/lib/writers/MapWriter.d.ts +27 -0
  554. package/node_modules/xmlbuilder2/lib/writers/MapWriter.js +84 -0
  555. package/node_modules/xmlbuilder2/lib/writers/MapWriter.js.map +1 -0
  556. package/node_modules/xmlbuilder2/lib/writers/ObjectWriter.d.ts +56 -0
  557. package/node_modules/xmlbuilder2/lib/writers/ObjectWriter.js +483 -0
  558. package/node_modules/xmlbuilder2/lib/writers/ObjectWriter.js.map +1 -0
  559. package/node_modules/xmlbuilder2/lib/writers/XMLCBWriter.d.ts +51 -0
  560. package/node_modules/xmlbuilder2/lib/writers/XMLCBWriter.js +165 -0
  561. package/node_modules/xmlbuilder2/lib/writers/XMLCBWriter.js.map +1 -0
  562. package/node_modules/xmlbuilder2/lib/writers/XMLWriter.d.ts +60 -0
  563. package/node_modules/xmlbuilder2/lib/writers/XMLWriter.js +236 -0
  564. package/node_modules/xmlbuilder2/lib/writers/XMLWriter.js.map +1 -0
  565. package/node_modules/xmlbuilder2/lib/writers/YAMLCBWriter.d.ts +61 -0
  566. package/node_modules/xmlbuilder2/lib/writers/YAMLCBWriter.js +161 -0
  567. package/node_modules/xmlbuilder2/lib/writers/YAMLCBWriter.js.map +1 -0
  568. package/node_modules/xmlbuilder2/lib/writers/YAMLWriter.d.ts +55 -0
  569. package/node_modules/xmlbuilder2/lib/writers/YAMLWriter.js +186 -0
  570. package/node_modules/xmlbuilder2/lib/writers/YAMLWriter.js.map +1 -0
  571. package/node_modules/xmlbuilder2/lib/writers/index.d.ts +5 -0
  572. package/node_modules/xmlbuilder2/lib/writers/index.js +13 -0
  573. package/node_modules/xmlbuilder2/lib/writers/index.js.map +1 -0
  574. package/node_modules/xmlbuilder2/lib/xmlbuilder2.min.js +8 -0
  575. package/node_modules/xmlbuilder2/node_modules/argparse/CHANGELOG.md +185 -0
  576. package/node_modules/xmlbuilder2/node_modules/argparse/LICENSE +21 -0
  577. package/node_modules/xmlbuilder2/node_modules/argparse/README.md +257 -0
  578. package/node_modules/xmlbuilder2/node_modules/argparse/index.js +3 -0
  579. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/append/constant.js +47 -0
  580. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/append.js +53 -0
  581. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/count.js +40 -0
  582. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/help.js +47 -0
  583. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/store/constant.js +43 -0
  584. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/store/false.js +27 -0
  585. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/store/true.js +26 -0
  586. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/store.js +50 -0
  587. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/subparsers.js +149 -0
  588. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action/version.js +47 -0
  589. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action.js +146 -0
  590. package/node_modules/xmlbuilder2/node_modules/argparse/lib/action_container.js +482 -0
  591. package/node_modules/xmlbuilder2/node_modules/argparse/lib/argparse.js +14 -0
  592. package/node_modules/xmlbuilder2/node_modules/argparse/lib/argument/error.js +50 -0
  593. package/node_modules/xmlbuilder2/node_modules/argparse/lib/argument/exclusive.js +54 -0
  594. package/node_modules/xmlbuilder2/node_modules/argparse/lib/argument/group.js +75 -0
  595. package/node_modules/xmlbuilder2/node_modules/argparse/lib/argument_parser.js +1161 -0
  596. package/node_modules/xmlbuilder2/node_modules/argparse/lib/const.js +21 -0
  597. package/node_modules/xmlbuilder2/node_modules/argparse/lib/help/added_formatters.js +87 -0
  598. package/node_modules/xmlbuilder2/node_modules/argparse/lib/help/formatter.js +795 -0
  599. package/node_modules/xmlbuilder2/node_modules/argparse/lib/namespace.js +76 -0
  600. package/node_modules/xmlbuilder2/node_modules/argparse/lib/utils.js +57 -0
  601. package/node_modules/xmlbuilder2/node_modules/argparse/package.json +34 -0
  602. package/node_modules/xmlbuilder2/node_modules/js-yaml/CHANGELOG.md +557 -0
  603. package/node_modules/xmlbuilder2/node_modules/js-yaml/LICENSE +21 -0
  604. package/node_modules/xmlbuilder2/node_modules/js-yaml/README.md +299 -0
  605. package/node_modules/xmlbuilder2/node_modules/js-yaml/bin/js-yaml.js +132 -0
  606. package/node_modules/xmlbuilder2/node_modules/js-yaml/dist/js-yaml.js +3989 -0
  607. package/node_modules/xmlbuilder2/node_modules/js-yaml/dist/js-yaml.min.js +1 -0
  608. package/node_modules/xmlbuilder2/node_modules/js-yaml/index.js +7 -0
  609. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/common.js +59 -0
  610. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/dumper.js +850 -0
  611. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/exception.js +43 -0
  612. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/loader.js +1644 -0
  613. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/mark.js +76 -0
  614. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/schema/core.js +18 -0
  615. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/schema/default_full.js +25 -0
  616. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/schema/default_safe.js +28 -0
  617. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/schema/failsafe.js +17 -0
  618. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/schema/json.js +25 -0
  619. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/schema.js +108 -0
  620. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/binary.js +138 -0
  621. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/bool.js +35 -0
  622. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/float.js +116 -0
  623. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/int.js +173 -0
  624. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/js/function.js +93 -0
  625. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/js/regexp.js +60 -0
  626. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/js/undefined.js +28 -0
  627. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/map.js +8 -0
  628. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/merge.js +12 -0
  629. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/null.js +34 -0
  630. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/omap.js +44 -0
  631. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/pairs.js +53 -0
  632. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/seq.js +8 -0
  633. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/set.js +29 -0
  634. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/str.js +8 -0
  635. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type/timestamp.js +88 -0
  636. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml/type.js +61 -0
  637. package/node_modules/xmlbuilder2/node_modules/js-yaml/lib/js-yaml.js +39 -0
  638. package/node_modules/xmlbuilder2/node_modules/js-yaml/package.json +49 -0
  639. package/node_modules/xmlbuilder2/package.json +82 -0
  640. package/node_modules/xpath/LICENSE +22 -0
  641. package/node_modules/xpath/README.md +133 -0
  642. package/node_modules/xpath/package.json +43 -0
  643. package/node_modules/xpath/xpath.d.ts +51 -0
  644. package/node_modules/xpath/xpath.js +5041 -0
  645. package/package.json +9 -2
@@ -0,0 +1,1949 @@
1
+ /**
2
+ * Javascript implementation of basic RSA algorithms.
3
+ *
4
+ * @author Dave Longley
5
+ *
6
+ * Copyright (c) 2010-2014 Digital Bazaar, Inc.
7
+ *
8
+ * The only algorithm currently supported for PKI is RSA.
9
+ *
10
+ * An RSA key is often stored in ASN.1 DER format. The SubjectPublicKeyInfo
11
+ * ASN.1 structure is composed of an algorithm of type AlgorithmIdentifier
12
+ * and a subjectPublicKey of type bit string.
13
+ *
14
+ * The AlgorithmIdentifier contains an Object Identifier (OID) and parameters
15
+ * for the algorithm, if any. In the case of RSA, there aren't any.
16
+ *
17
+ * SubjectPublicKeyInfo ::= SEQUENCE {
18
+ * algorithm AlgorithmIdentifier,
19
+ * subjectPublicKey BIT STRING
20
+ * }
21
+ *
22
+ * AlgorithmIdentifer ::= SEQUENCE {
23
+ * algorithm OBJECT IDENTIFIER,
24
+ * parameters ANY DEFINED BY algorithm OPTIONAL
25
+ * }
26
+ *
27
+ * For an RSA public key, the subjectPublicKey is:
28
+ *
29
+ * RSAPublicKey ::= SEQUENCE {
30
+ * modulus INTEGER, -- n
31
+ * publicExponent INTEGER -- e
32
+ * }
33
+ *
34
+ * PrivateKeyInfo ::= SEQUENCE {
35
+ * version Version,
36
+ * privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
37
+ * privateKey PrivateKey,
38
+ * attributes [0] IMPLICIT Attributes OPTIONAL
39
+ * }
40
+ *
41
+ * Version ::= INTEGER
42
+ * PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
43
+ * PrivateKey ::= OCTET STRING
44
+ * Attributes ::= SET OF Attribute
45
+ *
46
+ * An RSA private key as the following structure:
47
+ *
48
+ * RSAPrivateKey ::= SEQUENCE {
49
+ * version Version,
50
+ * modulus INTEGER, -- n
51
+ * publicExponent INTEGER, -- e
52
+ * privateExponent INTEGER, -- d
53
+ * prime1 INTEGER, -- p
54
+ * prime2 INTEGER, -- q
55
+ * exponent1 INTEGER, -- d mod (p-1)
56
+ * exponent2 INTEGER, -- d mod (q-1)
57
+ * coefficient INTEGER -- (inverse of q) mod p
58
+ * }
59
+ *
60
+ * Version ::= INTEGER
61
+ *
62
+ * The OID for the RSA key algorithm is: 1.2.840.113549.1.1.1
63
+ */
64
+ var forge = require('./forge');
65
+ require('./asn1');
66
+ require('./jsbn');
67
+ require('./oids');
68
+ require('./pkcs1');
69
+ require('./prime');
70
+ require('./random');
71
+ require('./util');
72
+
73
+ if(typeof BigInteger === 'undefined') {
74
+ var BigInteger = forge.jsbn.BigInteger;
75
+ }
76
+
77
+ var _crypto = forge.util.isNodejs ? require('crypto') : null;
78
+
79
+ // shortcut for asn.1 API
80
+ var asn1 = forge.asn1;
81
+
82
+ // shortcut for util API
83
+ var util = forge.util;
84
+
85
+ /*
86
+ * RSA encryption and decryption, see RFC 2313.
87
+ */
88
+ forge.pki = forge.pki || {};
89
+ module.exports = forge.pki.rsa = forge.rsa = forge.rsa || {};
90
+ var pki = forge.pki;
91
+
92
+ // for finding primes, which are 30k+i for i = 1, 7, 11, 13, 17, 19, 23, 29
93
+ var GCD_30_DELTA = [6, 4, 2, 4, 2, 4, 6, 2];
94
+
95
+ // validator for a PrivateKeyInfo structure
96
+ var privateKeyValidator = {
97
+ // PrivateKeyInfo
98
+ name: 'PrivateKeyInfo',
99
+ tagClass: asn1.Class.UNIVERSAL,
100
+ type: asn1.Type.SEQUENCE,
101
+ constructed: true,
102
+ value: [{
103
+ // Version (INTEGER)
104
+ name: 'PrivateKeyInfo.version',
105
+ tagClass: asn1.Class.UNIVERSAL,
106
+ type: asn1.Type.INTEGER,
107
+ constructed: false,
108
+ capture: 'privateKeyVersion'
109
+ }, {
110
+ // privateKeyAlgorithm
111
+ name: 'PrivateKeyInfo.privateKeyAlgorithm',
112
+ tagClass: asn1.Class.UNIVERSAL,
113
+ type: asn1.Type.SEQUENCE,
114
+ constructed: true,
115
+ value: [{
116
+ name: 'AlgorithmIdentifier.algorithm',
117
+ tagClass: asn1.Class.UNIVERSAL,
118
+ type: asn1.Type.OID,
119
+ constructed: false,
120
+ capture: 'privateKeyOid'
121
+ }]
122
+ }, {
123
+ // PrivateKey
124
+ name: 'PrivateKeyInfo',
125
+ tagClass: asn1.Class.UNIVERSAL,
126
+ type: asn1.Type.OCTETSTRING,
127
+ constructed: false,
128
+ capture: 'privateKey'
129
+ }]
130
+ };
131
+
132
+ // validator for an RSA private key
133
+ var rsaPrivateKeyValidator = {
134
+ // RSAPrivateKey
135
+ name: 'RSAPrivateKey',
136
+ tagClass: asn1.Class.UNIVERSAL,
137
+ type: asn1.Type.SEQUENCE,
138
+ constructed: true,
139
+ value: [{
140
+ // Version (INTEGER)
141
+ name: 'RSAPrivateKey.version',
142
+ tagClass: asn1.Class.UNIVERSAL,
143
+ type: asn1.Type.INTEGER,
144
+ constructed: false,
145
+ capture: 'privateKeyVersion'
146
+ }, {
147
+ // modulus (n)
148
+ name: 'RSAPrivateKey.modulus',
149
+ tagClass: asn1.Class.UNIVERSAL,
150
+ type: asn1.Type.INTEGER,
151
+ constructed: false,
152
+ capture: 'privateKeyModulus'
153
+ }, {
154
+ // publicExponent (e)
155
+ name: 'RSAPrivateKey.publicExponent',
156
+ tagClass: asn1.Class.UNIVERSAL,
157
+ type: asn1.Type.INTEGER,
158
+ constructed: false,
159
+ capture: 'privateKeyPublicExponent'
160
+ }, {
161
+ // privateExponent (d)
162
+ name: 'RSAPrivateKey.privateExponent',
163
+ tagClass: asn1.Class.UNIVERSAL,
164
+ type: asn1.Type.INTEGER,
165
+ constructed: false,
166
+ capture: 'privateKeyPrivateExponent'
167
+ }, {
168
+ // prime1 (p)
169
+ name: 'RSAPrivateKey.prime1',
170
+ tagClass: asn1.Class.UNIVERSAL,
171
+ type: asn1.Type.INTEGER,
172
+ constructed: false,
173
+ capture: 'privateKeyPrime1'
174
+ }, {
175
+ // prime2 (q)
176
+ name: 'RSAPrivateKey.prime2',
177
+ tagClass: asn1.Class.UNIVERSAL,
178
+ type: asn1.Type.INTEGER,
179
+ constructed: false,
180
+ capture: 'privateKeyPrime2'
181
+ }, {
182
+ // exponent1 (d mod (p-1))
183
+ name: 'RSAPrivateKey.exponent1',
184
+ tagClass: asn1.Class.UNIVERSAL,
185
+ type: asn1.Type.INTEGER,
186
+ constructed: false,
187
+ capture: 'privateKeyExponent1'
188
+ }, {
189
+ // exponent2 (d mod (q-1))
190
+ name: 'RSAPrivateKey.exponent2',
191
+ tagClass: asn1.Class.UNIVERSAL,
192
+ type: asn1.Type.INTEGER,
193
+ constructed: false,
194
+ capture: 'privateKeyExponent2'
195
+ }, {
196
+ // coefficient ((inverse of q) mod p)
197
+ name: 'RSAPrivateKey.coefficient',
198
+ tagClass: asn1.Class.UNIVERSAL,
199
+ type: asn1.Type.INTEGER,
200
+ constructed: false,
201
+ capture: 'privateKeyCoefficient'
202
+ }]
203
+ };
204
+
205
+ // validator for an RSA public key
206
+ var rsaPublicKeyValidator = {
207
+ // RSAPublicKey
208
+ name: 'RSAPublicKey',
209
+ tagClass: asn1.Class.UNIVERSAL,
210
+ type: asn1.Type.SEQUENCE,
211
+ constructed: true,
212
+ value: [{
213
+ // modulus (n)
214
+ name: 'RSAPublicKey.modulus',
215
+ tagClass: asn1.Class.UNIVERSAL,
216
+ type: asn1.Type.INTEGER,
217
+ constructed: false,
218
+ capture: 'publicKeyModulus'
219
+ }, {
220
+ // publicExponent (e)
221
+ name: 'RSAPublicKey.exponent',
222
+ tagClass: asn1.Class.UNIVERSAL,
223
+ type: asn1.Type.INTEGER,
224
+ constructed: false,
225
+ capture: 'publicKeyExponent'
226
+ }]
227
+ };
228
+
229
+ // validator for an SubjectPublicKeyInfo structure
230
+ // Note: Currently only works with an RSA public key
231
+ var publicKeyValidator = forge.pki.rsa.publicKeyValidator = {
232
+ name: 'SubjectPublicKeyInfo',
233
+ tagClass: asn1.Class.UNIVERSAL,
234
+ type: asn1.Type.SEQUENCE,
235
+ constructed: true,
236
+ captureAsn1: 'subjectPublicKeyInfo',
237
+ value: [{
238
+ name: 'SubjectPublicKeyInfo.AlgorithmIdentifier',
239
+ tagClass: asn1.Class.UNIVERSAL,
240
+ type: asn1.Type.SEQUENCE,
241
+ constructed: true,
242
+ value: [{
243
+ name: 'AlgorithmIdentifier.algorithm',
244
+ tagClass: asn1.Class.UNIVERSAL,
245
+ type: asn1.Type.OID,
246
+ constructed: false,
247
+ capture: 'publicKeyOid'
248
+ }]
249
+ }, {
250
+ // subjectPublicKey
251
+ name: 'SubjectPublicKeyInfo.subjectPublicKey',
252
+ tagClass: asn1.Class.UNIVERSAL,
253
+ type: asn1.Type.BITSTRING,
254
+ constructed: false,
255
+ value: [{
256
+ // RSAPublicKey
257
+ name: 'SubjectPublicKeyInfo.subjectPublicKey.RSAPublicKey',
258
+ tagClass: asn1.Class.UNIVERSAL,
259
+ type: asn1.Type.SEQUENCE,
260
+ constructed: true,
261
+ optional: true,
262
+ captureAsn1: 'rsaPublicKey'
263
+ }]
264
+ }]
265
+ };
266
+
267
+ // validator for a DigestInfo structure
268
+ var digestInfoValidator = {
269
+ name: 'DigestInfo',
270
+ tagClass: asn1.Class.UNIVERSAL,
271
+ type: asn1.Type.SEQUENCE,
272
+ constructed: true,
273
+ value: [{
274
+ name: 'DigestInfo.DigestAlgorithm',
275
+ tagClass: asn1.Class.UNIVERSAL,
276
+ type: asn1.Type.SEQUENCE,
277
+ constructed: true,
278
+ value: [{
279
+ name: 'DigestInfo.DigestAlgorithm.algorithmIdentifier',
280
+ tagClass: asn1.Class.UNIVERSAL,
281
+ type: asn1.Type.OID,
282
+ constructed: false,
283
+ capture: 'algorithmIdentifier'
284
+ }, {
285
+ // NULL parameters
286
+ name: 'DigestInfo.DigestAlgorithm.parameters',
287
+ tagClass: asn1.Class.UNIVERSAL,
288
+ type: asn1.Type.NULL,
289
+ // captured only to check existence for md2 and md5
290
+ capture: 'parameters',
291
+ optional: true,
292
+ constructed: false
293
+ }]
294
+ }, {
295
+ // digest
296
+ name: 'DigestInfo.digest',
297
+ tagClass: asn1.Class.UNIVERSAL,
298
+ type: asn1.Type.OCTETSTRING,
299
+ constructed: false,
300
+ capture: 'digest'
301
+ }]
302
+ };
303
+
304
+ /**
305
+ * Wrap digest in DigestInfo object.
306
+ *
307
+ * This function implements EMSA-PKCS1-v1_5-ENCODE as per RFC 3447.
308
+ *
309
+ * DigestInfo ::= SEQUENCE {
310
+ * digestAlgorithm DigestAlgorithmIdentifier,
311
+ * digest Digest
312
+ * }
313
+ *
314
+ * DigestAlgorithmIdentifier ::= AlgorithmIdentifier
315
+ * Digest ::= OCTET STRING
316
+ *
317
+ * @param md the message digest object with the hash to sign.
318
+ *
319
+ * @return the encoded message (ready for RSA encryption)
320
+ */
321
+ var emsaPkcs1v15encode = function(md) {
322
+ // get the oid for the algorithm
323
+ var oid;
324
+ if(md.algorithm in pki.oids) {
325
+ oid = pki.oids[md.algorithm];
326
+ } else {
327
+ var error = new Error('Unknown message digest algorithm.');
328
+ error.algorithm = md.algorithm;
329
+ throw error;
330
+ }
331
+ var oidBytes = asn1.oidToDer(oid).getBytes();
332
+
333
+ // create the digest info
334
+ var digestInfo = asn1.create(
335
+ asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, []);
336
+ var digestAlgorithm = asn1.create(
337
+ asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, []);
338
+ digestAlgorithm.value.push(asn1.create(
339
+ asn1.Class.UNIVERSAL, asn1.Type.OID, false, oidBytes));
340
+ digestAlgorithm.value.push(asn1.create(
341
+ asn1.Class.UNIVERSAL, asn1.Type.NULL, false, ''));
342
+ var digest = asn1.create(
343
+ asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING,
344
+ false, md.digest().getBytes());
345
+ digestInfo.value.push(digestAlgorithm);
346
+ digestInfo.value.push(digest);
347
+
348
+ // encode digest info
349
+ return asn1.toDer(digestInfo).getBytes();
350
+ };
351
+
352
+ /**
353
+ * Performs x^c mod n (RSA encryption or decryption operation).
354
+ *
355
+ * @param x the number to raise and mod.
356
+ * @param key the key to use.
357
+ * @param pub true if the key is public, false if private.
358
+ *
359
+ * @return the result of x^c mod n.
360
+ */
361
+ var _modPow = function(x, key, pub) {
362
+ if(pub) {
363
+ return x.modPow(key.e, key.n);
364
+ }
365
+
366
+ if(!key.p || !key.q) {
367
+ // allow calculation without CRT params (slow)
368
+ return x.modPow(key.d, key.n);
369
+ }
370
+
371
+ // pre-compute dP, dQ, and qInv if necessary
372
+ if(!key.dP) {
373
+ key.dP = key.d.mod(key.p.subtract(BigInteger.ONE));
374
+ }
375
+ if(!key.dQ) {
376
+ key.dQ = key.d.mod(key.q.subtract(BigInteger.ONE));
377
+ }
378
+ if(!key.qInv) {
379
+ key.qInv = key.q.modInverse(key.p);
380
+ }
381
+
382
+ /* Chinese remainder theorem (CRT) states:
383
+
384
+ Suppose n1, n2, ..., nk are positive integers which are pairwise
385
+ coprime (n1 and n2 have no common factors other than 1). For any
386
+ integers x1, x2, ..., xk there exists an integer x solving the
387
+ system of simultaneous congruences (where ~= means modularly
388
+ congruent so a ~= b mod n means a mod n = b mod n):
389
+
390
+ x ~= x1 mod n1
391
+ x ~= x2 mod n2
392
+ ...
393
+ x ~= xk mod nk
394
+
395
+ This system of congruences has a single simultaneous solution x
396
+ between 0 and n - 1. Furthermore, each xk solution and x itself
397
+ is congruent modulo the product n = n1*n2*...*nk.
398
+ So x1 mod n = x2 mod n = xk mod n = x mod n.
399
+
400
+ The single simultaneous solution x can be solved with the following
401
+ equation:
402
+
403
+ x = sum(xi*ri*si) mod n where ri = n/ni and si = ri^-1 mod ni.
404
+
405
+ Where x is less than n, xi = x mod ni.
406
+
407
+ For RSA we are only concerned with k = 2. The modulus n = pq, where
408
+ p and q are coprime. The RSA decryption algorithm is:
409
+
410
+ y = x^d mod n
411
+
412
+ Given the above:
413
+
414
+ x1 = x^d mod p
415
+ r1 = n/p = q
416
+ s1 = q^-1 mod p
417
+ x2 = x^d mod q
418
+ r2 = n/q = p
419
+ s2 = p^-1 mod q
420
+
421
+ So y = (x1r1s1 + x2r2s2) mod n
422
+ = ((x^d mod p)q(q^-1 mod p) + (x^d mod q)p(p^-1 mod q)) mod n
423
+
424
+ According to Fermat's Little Theorem, if the modulus P is prime,
425
+ for any integer A not evenly divisible by P, A^(P-1) ~= 1 mod P.
426
+ Since A is not divisible by P it follows that if:
427
+ N ~= M mod (P - 1), then A^N mod P = A^M mod P. Therefore:
428
+
429
+ A^N mod P = A^(M mod (P - 1)) mod P. (The latter takes less effort
430
+ to calculate). In order to calculate x^d mod p more quickly the
431
+ exponent d mod (p - 1) is stored in the RSA private key (the same
432
+ is done for x^d mod q). These values are referred to as dP and dQ
433
+ respectively. Therefore we now have:
434
+
435
+ y = ((x^dP mod p)q(q^-1 mod p) + (x^dQ mod q)p(p^-1 mod q)) mod n
436
+
437
+ Since we'll be reducing x^dP by modulo p (same for q) we can also
438
+ reduce x by p (and q respectively) before hand. Therefore, let
439
+
440
+ xp = ((x mod p)^dP mod p), and
441
+ xq = ((x mod q)^dQ mod q), yielding:
442
+
443
+ y = (xp*q*(q^-1 mod p) + xq*p*(p^-1 mod q)) mod n
444
+
445
+ This can be further reduced to a simple algorithm that only
446
+ requires 1 inverse (the q inverse is used) to be used and stored.
447
+ The algorithm is called Garner's algorithm. If qInv is the
448
+ inverse of q, we simply calculate:
449
+
450
+ y = (qInv*(xp - xq) mod p) * q + xq
451
+
452
+ However, there are two further complications. First, we need to
453
+ ensure that xp > xq to prevent signed BigIntegers from being used
454
+ so we add p until this is true (since we will be mod'ing with
455
+ p anyway). Then, there is a known timing attack on algorithms
456
+ using the CRT. To mitigate this risk, "cryptographic blinding"
457
+ should be used. This requires simply generating a random number r
458
+ between 0 and n-1 and its inverse and multiplying x by r^e before
459
+ calculating y and then multiplying y by r^-1 afterwards. Note that
460
+ r must be coprime with n (gcd(r, n) === 1) in order to have an
461
+ inverse.
462
+ */
463
+
464
+ // cryptographic blinding
465
+ var r;
466
+ do {
467
+ r = new BigInteger(
468
+ forge.util.bytesToHex(forge.random.getBytes(key.n.bitLength() / 8)),
469
+ 16);
470
+ } while(r.compareTo(key.n) >= 0 || !r.gcd(key.n).equals(BigInteger.ONE));
471
+ x = x.multiply(r.modPow(key.e, key.n)).mod(key.n);
472
+
473
+ // calculate xp and xq
474
+ var xp = x.mod(key.p).modPow(key.dP, key.p);
475
+ var xq = x.mod(key.q).modPow(key.dQ, key.q);
476
+
477
+ // xp must be larger than xq to avoid signed bit usage
478
+ while(xp.compareTo(xq) < 0) {
479
+ xp = xp.add(key.p);
480
+ }
481
+
482
+ // do last step
483
+ var y = xp.subtract(xq)
484
+ .multiply(key.qInv).mod(key.p)
485
+ .multiply(key.q).add(xq);
486
+
487
+ // remove effect of random for cryptographic blinding
488
+ y = y.multiply(r.modInverse(key.n)).mod(key.n);
489
+
490
+ return y;
491
+ };
492
+
493
+ /**
494
+ * NOTE: THIS METHOD IS DEPRECATED, use 'sign' on a private key object or
495
+ * 'encrypt' on a public key object instead.
496
+ *
497
+ * Performs RSA encryption.
498
+ *
499
+ * The parameter bt controls whether to put padding bytes before the
500
+ * message passed in. Set bt to either true or false to disable padding
501
+ * completely (in order to handle e.g. EMSA-PSS encoding separately before),
502
+ * signaling whether the encryption operation is a public key operation
503
+ * (i.e. encrypting data) or not, i.e. private key operation (data signing).
504
+ *
505
+ * For PKCS#1 v1.5 padding pass in the block type to use, i.e. either 0x01
506
+ * (for signing) or 0x02 (for encryption). The key operation mode (private
507
+ * or public) is derived from this flag in that case).
508
+ *
509
+ * @param m the message to encrypt as a byte string.
510
+ * @param key the RSA key to use.
511
+ * @param bt for PKCS#1 v1.5 padding, the block type to use
512
+ * (0x01 for private key, 0x02 for public),
513
+ * to disable padding: true = public key, false = private key.
514
+ *
515
+ * @return the encrypted bytes as a string.
516
+ */
517
+ pki.rsa.encrypt = function(m, key, bt) {
518
+ var pub = bt;
519
+ var eb;
520
+
521
+ // get the length of the modulus in bytes
522
+ var k = Math.ceil(key.n.bitLength() / 8);
523
+
524
+ if(bt !== false && bt !== true) {
525
+ // legacy, default to PKCS#1 v1.5 padding
526
+ pub = (bt === 0x02);
527
+ eb = _encodePkcs1_v1_5(m, key, bt);
528
+ } else {
529
+ eb = forge.util.createBuffer();
530
+ eb.putBytes(m);
531
+ }
532
+
533
+ // load encryption block as big integer 'x'
534
+ // FIXME: hex conversion inefficient, get BigInteger w/byte strings
535
+ var x = new BigInteger(eb.toHex(), 16);
536
+
537
+ // do RSA encryption
538
+ var y = _modPow(x, key, pub);
539
+
540
+ // convert y into the encrypted data byte string, if y is shorter in
541
+ // bytes than k, then prepend zero bytes to fill up ed
542
+ // FIXME: hex conversion inefficient, get BigInteger w/byte strings
543
+ var yhex = y.toString(16);
544
+ var ed = forge.util.createBuffer();
545
+ var zeros = k - Math.ceil(yhex.length / 2);
546
+ while(zeros > 0) {
547
+ ed.putByte(0x00);
548
+ --zeros;
549
+ }
550
+ ed.putBytes(forge.util.hexToBytes(yhex));
551
+ return ed.getBytes();
552
+ };
553
+
554
+ /**
555
+ * NOTE: THIS METHOD IS DEPRECATED, use 'decrypt' on a private key object or
556
+ * 'verify' on a public key object instead.
557
+ *
558
+ * Performs RSA decryption.
559
+ *
560
+ * The parameter ml controls whether to apply PKCS#1 v1.5 padding
561
+ * or not. Set ml = false to disable padding removal completely
562
+ * (in order to handle e.g. EMSA-PSS later on) and simply pass back
563
+ * the RSA encryption block.
564
+ *
565
+ * @param ed the encrypted data to decrypt in as a byte string.
566
+ * @param key the RSA key to use.
567
+ * @param pub true for a public key operation, false for private.
568
+ * @param ml the message length, if known, false to disable padding.
569
+ *
570
+ * @return the decrypted message as a byte string.
571
+ */
572
+ pki.rsa.decrypt = function(ed, key, pub, ml) {
573
+ // get the length of the modulus in bytes
574
+ var k = Math.ceil(key.n.bitLength() / 8);
575
+
576
+ // error if the length of the encrypted data ED is not k
577
+ if(ed.length !== k) {
578
+ var error = new Error('Encrypted message length is invalid.');
579
+ error.length = ed.length;
580
+ error.expected = k;
581
+ throw error;
582
+ }
583
+
584
+ // convert encrypted data into a big integer
585
+ // FIXME: hex conversion inefficient, get BigInteger w/byte strings
586
+ var y = new BigInteger(forge.util.createBuffer(ed).toHex(), 16);
587
+
588
+ // y must be less than the modulus or it wasn't the result of
589
+ // a previous mod operation (encryption) using that modulus
590
+ if(y.compareTo(key.n) >= 0) {
591
+ throw new Error('Encrypted message is invalid.');
592
+ }
593
+
594
+ // do RSA decryption
595
+ var x = _modPow(y, key, pub);
596
+
597
+ // create the encryption block, if x is shorter in bytes than k, then
598
+ // prepend zero bytes to fill up eb
599
+ // FIXME: hex conversion inefficient, get BigInteger w/byte strings
600
+ var xhex = x.toString(16);
601
+ var eb = forge.util.createBuffer();
602
+ var zeros = k - Math.ceil(xhex.length / 2);
603
+ while(zeros > 0) {
604
+ eb.putByte(0x00);
605
+ --zeros;
606
+ }
607
+ eb.putBytes(forge.util.hexToBytes(xhex));
608
+
609
+ if(ml !== false) {
610
+ // legacy, default to PKCS#1 v1.5 padding
611
+ return _decodePkcs1_v1_5(eb.getBytes(), key, pub);
612
+ }
613
+
614
+ // return message
615
+ return eb.getBytes();
616
+ };
617
+
618
+ /**
619
+ * Creates an RSA key-pair generation state object. It is used to allow
620
+ * key-generation to be performed in steps. It also allows for a UI to
621
+ * display progress updates.
622
+ *
623
+ * @param bits the size for the private key in bits, defaults to 2048.
624
+ * @param e the public exponent to use, defaults to 65537 (0x10001).
625
+ * @param [options] the options to use.
626
+ * prng a custom crypto-secure pseudo-random number generator to use,
627
+ * that must define "getBytesSync".
628
+ * algorithm the algorithm to use (default: 'PRIMEINC').
629
+ *
630
+ * @return the state object to use to generate the key-pair.
631
+ */
632
+ pki.rsa.createKeyPairGenerationState = function(bits, e, options) {
633
+ // TODO: migrate step-based prime generation code to forge.prime
634
+
635
+ // set default bits
636
+ if(typeof(bits) === 'string') {
637
+ bits = parseInt(bits, 10);
638
+ }
639
+ bits = bits || 2048;
640
+
641
+ // create prng with api that matches BigInteger secure random
642
+ options = options || {};
643
+ var prng = options.prng || forge.random;
644
+ var rng = {
645
+ // x is an array to fill with bytes
646
+ nextBytes: function(x) {
647
+ var b = prng.getBytesSync(x.length);
648
+ for(var i = 0; i < x.length; ++i) {
649
+ x[i] = b.charCodeAt(i);
650
+ }
651
+ }
652
+ };
653
+
654
+ var algorithm = options.algorithm || 'PRIMEINC';
655
+
656
+ // create PRIMEINC algorithm state
657
+ var rval;
658
+ if(algorithm === 'PRIMEINC') {
659
+ rval = {
660
+ algorithm: algorithm,
661
+ state: 0,
662
+ bits: bits,
663
+ rng: rng,
664
+ eInt: e || 65537,
665
+ e: new BigInteger(null),
666
+ p: null,
667
+ q: null,
668
+ qBits: bits >> 1,
669
+ pBits: bits - (bits >> 1),
670
+ pqState: 0,
671
+ num: null,
672
+ keys: null
673
+ };
674
+ rval.e.fromInt(rval.eInt);
675
+ } else {
676
+ throw new Error('Invalid key generation algorithm: ' + algorithm);
677
+ }
678
+
679
+ return rval;
680
+ };
681
+
682
+ /**
683
+ * Attempts to runs the key-generation algorithm for at most n seconds
684
+ * (approximately) using the given state. When key-generation has completed,
685
+ * the keys will be stored in state.keys.
686
+ *
687
+ * To use this function to update a UI while generating a key or to prevent
688
+ * causing browser lockups/warnings, set "n" to a value other than 0. A
689
+ * simple pattern for generating a key and showing a progress indicator is:
690
+ *
691
+ * var state = pki.rsa.createKeyPairGenerationState(2048);
692
+ * var step = function() {
693
+ * // step key-generation, run algorithm for 100 ms, repeat
694
+ * if(!forge.pki.rsa.stepKeyPairGenerationState(state, 100)) {
695
+ * setTimeout(step, 1);
696
+ * } else {
697
+ * // key-generation complete
698
+ * // TODO: turn off progress indicator here
699
+ * // TODO: use the generated key-pair in "state.keys"
700
+ * }
701
+ * };
702
+ * // TODO: turn on progress indicator here
703
+ * setTimeout(step, 0);
704
+ *
705
+ * @param state the state to use.
706
+ * @param n the maximum number of milliseconds to run the algorithm for, 0
707
+ * to run the algorithm to completion.
708
+ *
709
+ * @return true if the key-generation completed, false if not.
710
+ */
711
+ pki.rsa.stepKeyPairGenerationState = function(state, n) {
712
+ // set default algorithm if not set
713
+ if(!('algorithm' in state)) {
714
+ state.algorithm = 'PRIMEINC';
715
+ }
716
+
717
+ // TODO: migrate step-based prime generation code to forge.prime
718
+ // TODO: abstract as PRIMEINC algorithm
719
+
720
+ // do key generation (based on Tom Wu's rsa.js, see jsbn.js license)
721
+ // with some minor optimizations and designed to run in steps
722
+
723
+ // local state vars
724
+ var THIRTY = new BigInteger(null);
725
+ THIRTY.fromInt(30);
726
+ var deltaIdx = 0;
727
+ var op_or = function(x, y) {return x | y;};
728
+
729
+ // keep stepping until time limit is reached or done
730
+ var t1 = +new Date();
731
+ var t2;
732
+ var total = 0;
733
+ while(state.keys === null && (n <= 0 || total < n)) {
734
+ // generate p or q
735
+ if(state.state === 0) {
736
+ /* Note: All primes are of the form:
737
+
738
+ 30k+i, for i < 30 and gcd(30, i)=1, where there are 8 values for i
739
+
740
+ When we generate a random number, we always align it at 30k + 1. Each
741
+ time the number is determined not to be prime we add to get to the
742
+ next 'i', eg: if the number was at 30k + 1 we add 6. */
743
+ var bits = (state.p === null) ? state.pBits : state.qBits;
744
+ var bits1 = bits - 1;
745
+
746
+ // get a random number
747
+ if(state.pqState === 0) {
748
+ state.num = new BigInteger(bits, state.rng);
749
+ // force MSB set
750
+ if(!state.num.testBit(bits1)) {
751
+ state.num.bitwiseTo(
752
+ BigInteger.ONE.shiftLeft(bits1), op_or, state.num);
753
+ }
754
+ // align number on 30k+1 boundary
755
+ state.num.dAddOffset(31 - state.num.mod(THIRTY).byteValue(), 0);
756
+ deltaIdx = 0;
757
+
758
+ ++state.pqState;
759
+ } else if(state.pqState === 1) {
760
+ // try to make the number a prime
761
+ if(state.num.bitLength() > bits) {
762
+ // overflow, try again
763
+ state.pqState = 0;
764
+ // do primality test
765
+ } else if(state.num.isProbablePrime(
766
+ _getMillerRabinTests(state.num.bitLength()))) {
767
+ ++state.pqState;
768
+ } else {
769
+ // get next potential prime
770
+ state.num.dAddOffset(GCD_30_DELTA[deltaIdx++ % 8], 0);
771
+ }
772
+ } else if(state.pqState === 2) {
773
+ // ensure number is coprime with e
774
+ state.pqState =
775
+ (state.num.subtract(BigInteger.ONE).gcd(state.e)
776
+ .compareTo(BigInteger.ONE) === 0) ? 3 : 0;
777
+ } else if(state.pqState === 3) {
778
+ // store p or q
779
+ state.pqState = 0;
780
+ if(state.p === null) {
781
+ state.p = state.num;
782
+ } else {
783
+ state.q = state.num;
784
+ }
785
+
786
+ // advance state if both p and q are ready
787
+ if(state.p !== null && state.q !== null) {
788
+ ++state.state;
789
+ }
790
+ state.num = null;
791
+ }
792
+ } else if(state.state === 1) {
793
+ // ensure p is larger than q (swap them if not)
794
+ if(state.p.compareTo(state.q) < 0) {
795
+ state.num = state.p;
796
+ state.p = state.q;
797
+ state.q = state.num;
798
+ }
799
+ ++state.state;
800
+ } else if(state.state === 2) {
801
+ // compute phi: (p - 1)(q - 1) (Euler's totient function)
802
+ state.p1 = state.p.subtract(BigInteger.ONE);
803
+ state.q1 = state.q.subtract(BigInteger.ONE);
804
+ state.phi = state.p1.multiply(state.q1);
805
+ ++state.state;
806
+ } else if(state.state === 3) {
807
+ // ensure e and phi are coprime
808
+ if(state.phi.gcd(state.e).compareTo(BigInteger.ONE) === 0) {
809
+ // phi and e are coprime, advance
810
+ ++state.state;
811
+ } else {
812
+ // phi and e aren't coprime, so generate a new p and q
813
+ state.p = null;
814
+ state.q = null;
815
+ state.state = 0;
816
+ }
817
+ } else if(state.state === 4) {
818
+ // create n, ensure n is has the right number of bits
819
+ state.n = state.p.multiply(state.q);
820
+
821
+ // ensure n is right number of bits
822
+ if(state.n.bitLength() === state.bits) {
823
+ // success, advance
824
+ ++state.state;
825
+ } else {
826
+ // failed, get new q
827
+ state.q = null;
828
+ state.state = 0;
829
+ }
830
+ } else if(state.state === 5) {
831
+ // set keys
832
+ var d = state.e.modInverse(state.phi);
833
+ state.keys = {
834
+ privateKey: pki.rsa.setPrivateKey(
835
+ state.n, state.e, d, state.p, state.q,
836
+ d.mod(state.p1), d.mod(state.q1),
837
+ state.q.modInverse(state.p)),
838
+ publicKey: pki.rsa.setPublicKey(state.n, state.e)
839
+ };
840
+ }
841
+
842
+ // update timing
843
+ t2 = +new Date();
844
+ total += t2 - t1;
845
+ t1 = t2;
846
+ }
847
+
848
+ return state.keys !== null;
849
+ };
850
+
851
+ /**
852
+ * Generates an RSA public-private key pair in a single call.
853
+ *
854
+ * To generate a key-pair in steps (to allow for progress updates and to
855
+ * prevent blocking or warnings in slow browsers) then use the key-pair
856
+ * generation state functions.
857
+ *
858
+ * To generate a key-pair asynchronously (either through web-workers, if
859
+ * available, or by breaking up the work on the main thread), pass a
860
+ * callback function.
861
+ *
862
+ * @param [bits] the size for the private key in bits, defaults to 2048.
863
+ * @param [e] the public exponent to use, defaults to 65537.
864
+ * @param [options] options for key-pair generation, if given then 'bits'
865
+ * and 'e' must *not* be given:
866
+ * bits the size for the private key in bits, (default: 2048).
867
+ * e the public exponent to use, (default: 65537 (0x10001)).
868
+ * workerScript the worker script URL.
869
+ * workers the number of web workers (if supported) to use,
870
+ * (default: 2).
871
+ * workLoad the size of the work load, ie: number of possible prime
872
+ * numbers for each web worker to check per work assignment,
873
+ * (default: 100).
874
+ * prng a custom crypto-secure pseudo-random number generator to use,
875
+ * that must define "getBytesSync". Disables use of native APIs.
876
+ * algorithm the algorithm to use (default: 'PRIMEINC').
877
+ * @param [callback(err, keypair)] called once the operation completes.
878
+ *
879
+ * @return an object with privateKey and publicKey properties.
880
+ */
881
+ pki.rsa.generateKeyPair = function(bits, e, options, callback) {
882
+ // (bits), (options), (callback)
883
+ if(arguments.length === 1) {
884
+ if(typeof bits === 'object') {
885
+ options = bits;
886
+ bits = undefined;
887
+ } else if(typeof bits === 'function') {
888
+ callback = bits;
889
+ bits = undefined;
890
+ }
891
+ } else if(arguments.length === 2) {
892
+ // (bits, e), (bits, options), (bits, callback), (options, callback)
893
+ if(typeof bits === 'number') {
894
+ if(typeof e === 'function') {
895
+ callback = e;
896
+ e = undefined;
897
+ } else if(typeof e !== 'number') {
898
+ options = e;
899
+ e = undefined;
900
+ }
901
+ } else {
902
+ options = bits;
903
+ callback = e;
904
+ bits = undefined;
905
+ e = undefined;
906
+ }
907
+ } else if(arguments.length === 3) {
908
+ // (bits, e, options), (bits, e, callback), (bits, options, callback)
909
+ if(typeof e === 'number') {
910
+ if(typeof options === 'function') {
911
+ callback = options;
912
+ options = undefined;
913
+ }
914
+ } else {
915
+ callback = options;
916
+ options = e;
917
+ e = undefined;
918
+ }
919
+ }
920
+ options = options || {};
921
+ if(bits === undefined) {
922
+ bits = options.bits || 2048;
923
+ }
924
+ if(e === undefined) {
925
+ e = options.e || 0x10001;
926
+ }
927
+
928
+ // use native code if permitted, available, and parameters are acceptable
929
+ if(!forge.options.usePureJavaScript && !options.prng &&
930
+ bits >= 256 && bits <= 16384 && (e === 0x10001 || e === 3)) {
931
+ if(callback) {
932
+ // try native async
933
+ if(_detectNodeCrypto('generateKeyPair')) {
934
+ return _crypto.generateKeyPair('rsa', {
935
+ modulusLength: bits,
936
+ publicExponent: e,
937
+ publicKeyEncoding: {
938
+ type: 'spki',
939
+ format: 'pem'
940
+ },
941
+ privateKeyEncoding: {
942
+ type: 'pkcs8',
943
+ format: 'pem'
944
+ }
945
+ }, function(err, pub, priv) {
946
+ if(err) {
947
+ return callback(err);
948
+ }
949
+ callback(null, {
950
+ privateKey: pki.privateKeyFromPem(priv),
951
+ publicKey: pki.publicKeyFromPem(pub)
952
+ });
953
+ });
954
+ }
955
+ if(_detectSubtleCrypto('generateKey') &&
956
+ _detectSubtleCrypto('exportKey')) {
957
+ // use standard native generateKey
958
+ return util.globalScope.crypto.subtle.generateKey({
959
+ name: 'RSASSA-PKCS1-v1_5',
960
+ modulusLength: bits,
961
+ publicExponent: _intToUint8Array(e),
962
+ hash: {name: 'SHA-256'}
963
+ }, true /* key can be exported*/, ['sign', 'verify'])
964
+ .then(function(pair) {
965
+ return util.globalScope.crypto.subtle.exportKey(
966
+ 'pkcs8', pair.privateKey);
967
+ // avoiding catch(function(err) {...}) to support IE <= 8
968
+ }).then(undefined, function(err) {
969
+ callback(err);
970
+ }).then(function(pkcs8) {
971
+ if(pkcs8) {
972
+ var privateKey = pki.privateKeyFromAsn1(
973
+ asn1.fromDer(forge.util.createBuffer(pkcs8)));
974
+ callback(null, {
975
+ privateKey: privateKey,
976
+ publicKey: pki.setRsaPublicKey(privateKey.n, privateKey.e)
977
+ });
978
+ }
979
+ });
980
+ }
981
+ if(_detectSubtleMsCrypto('generateKey') &&
982
+ _detectSubtleMsCrypto('exportKey')) {
983
+ var genOp = util.globalScope.msCrypto.subtle.generateKey({
984
+ name: 'RSASSA-PKCS1-v1_5',
985
+ modulusLength: bits,
986
+ publicExponent: _intToUint8Array(e),
987
+ hash: {name: 'SHA-256'}
988
+ }, true /* key can be exported*/, ['sign', 'verify']);
989
+ genOp.oncomplete = function(e) {
990
+ var pair = e.target.result;
991
+ var exportOp = util.globalScope.msCrypto.subtle.exportKey(
992
+ 'pkcs8', pair.privateKey);
993
+ exportOp.oncomplete = function(e) {
994
+ var pkcs8 = e.target.result;
995
+ var privateKey = pki.privateKeyFromAsn1(
996
+ asn1.fromDer(forge.util.createBuffer(pkcs8)));
997
+ callback(null, {
998
+ privateKey: privateKey,
999
+ publicKey: pki.setRsaPublicKey(privateKey.n, privateKey.e)
1000
+ });
1001
+ };
1002
+ exportOp.onerror = function(err) {
1003
+ callback(err);
1004
+ };
1005
+ };
1006
+ genOp.onerror = function(err) {
1007
+ callback(err);
1008
+ };
1009
+ return;
1010
+ }
1011
+ } else {
1012
+ // try native sync
1013
+ if(_detectNodeCrypto('generateKeyPairSync')) {
1014
+ var keypair = _crypto.generateKeyPairSync('rsa', {
1015
+ modulusLength: bits,
1016
+ publicExponent: e,
1017
+ publicKeyEncoding: {
1018
+ type: 'spki',
1019
+ format: 'pem'
1020
+ },
1021
+ privateKeyEncoding: {
1022
+ type: 'pkcs8',
1023
+ format: 'pem'
1024
+ }
1025
+ });
1026
+ return {
1027
+ privateKey: pki.privateKeyFromPem(keypair.privateKey),
1028
+ publicKey: pki.publicKeyFromPem(keypair.publicKey)
1029
+ };
1030
+ }
1031
+ }
1032
+ }
1033
+
1034
+ // use JavaScript implementation
1035
+ var state = pki.rsa.createKeyPairGenerationState(bits, e, options);
1036
+ if(!callback) {
1037
+ pki.rsa.stepKeyPairGenerationState(state, 0);
1038
+ return state.keys;
1039
+ }
1040
+ _generateKeyPair(state, options, callback);
1041
+ };
1042
+
1043
+ /**
1044
+ * Sets an RSA public key from BigIntegers modulus and exponent.
1045
+ *
1046
+ * @param n the modulus.
1047
+ * @param e the exponent.
1048
+ *
1049
+ * @return the public key.
1050
+ */
1051
+ pki.setRsaPublicKey = pki.rsa.setPublicKey = function(n, e) {
1052
+ var key = {
1053
+ n: n,
1054
+ e: e
1055
+ };
1056
+
1057
+ /**
1058
+ * Encrypts the given data with this public key. Newer applications
1059
+ * should use the 'RSA-OAEP' decryption scheme, 'RSAES-PKCS1-V1_5' is for
1060
+ * legacy applications.
1061
+ *
1062
+ * @param data the byte string to encrypt.
1063
+ * @param scheme the encryption scheme to use:
1064
+ * 'RSAES-PKCS1-V1_5' (default),
1065
+ * 'RSA-OAEP',
1066
+ * 'RAW', 'NONE', or null to perform raw RSA encryption,
1067
+ * an object with an 'encode' property set to a function
1068
+ * with the signature 'function(data, key)' that returns
1069
+ * a binary-encoded string representing the encoded data.
1070
+ * @param schemeOptions any scheme-specific options.
1071
+ *
1072
+ * @return the encrypted byte string.
1073
+ */
1074
+ key.encrypt = function(data, scheme, schemeOptions) {
1075
+ if(typeof scheme === 'string') {
1076
+ scheme = scheme.toUpperCase();
1077
+ } else if(scheme === undefined) {
1078
+ scheme = 'RSAES-PKCS1-V1_5';
1079
+ }
1080
+
1081
+ if(scheme === 'RSAES-PKCS1-V1_5') {
1082
+ scheme = {
1083
+ encode: function(m, key, pub) {
1084
+ return _encodePkcs1_v1_5(m, key, 0x02).getBytes();
1085
+ }
1086
+ };
1087
+ } else if(scheme === 'RSA-OAEP' || scheme === 'RSAES-OAEP') {
1088
+ scheme = {
1089
+ encode: function(m, key) {
1090
+ return forge.pkcs1.encode_rsa_oaep(key, m, schemeOptions);
1091
+ }
1092
+ };
1093
+ } else if(['RAW', 'NONE', 'NULL', null].indexOf(scheme) !== -1) {
1094
+ scheme = {encode: function(e) {return e;}};
1095
+ } else if(typeof scheme === 'string') {
1096
+ throw new Error('Unsupported encryption scheme: "' + scheme + '".');
1097
+ }
1098
+
1099
+ // do scheme-based encoding then rsa encryption
1100
+ var e = scheme.encode(data, key, true);
1101
+ return pki.rsa.encrypt(e, key, true);
1102
+ };
1103
+
1104
+ /**
1105
+ * Verifies the given signature against the given digest.
1106
+ *
1107
+ * PKCS#1 supports multiple (currently two) signature schemes:
1108
+ * RSASSA-PKCS1-V1_5 and RSASSA-PSS.
1109
+ *
1110
+ * By default this implementation uses the "old scheme", i.e.
1111
+ * RSASSA-PKCS1-V1_5, in which case once RSA-decrypted, the
1112
+ * signature is an OCTET STRING that holds a DigestInfo.
1113
+ *
1114
+ * DigestInfo ::= SEQUENCE {
1115
+ * digestAlgorithm DigestAlgorithmIdentifier,
1116
+ * digest Digest
1117
+ * }
1118
+ * DigestAlgorithmIdentifier ::= AlgorithmIdentifier
1119
+ * Digest ::= OCTET STRING
1120
+ *
1121
+ * To perform PSS signature verification, provide an instance
1122
+ * of Forge PSS object as the scheme parameter.
1123
+ *
1124
+ * @param digest the message digest hash to compare against the signature,
1125
+ * as a binary-encoded string.
1126
+ * @param signature the signature to verify, as a binary-encoded string.
1127
+ * @param scheme signature verification scheme to use:
1128
+ * 'RSASSA-PKCS1-V1_5' or undefined for RSASSA PKCS#1 v1.5,
1129
+ * a Forge PSS object for RSASSA-PSS,
1130
+ * 'NONE' or null for none, DigestInfo will not be expected, but
1131
+ * PKCS#1 v1.5 padding will still be used.
1132
+ * @param options optional verify options
1133
+ * _parseAllDigestBytes testing flag to control parsing of all
1134
+ * digest bytes. Unsupported and not for general usage.
1135
+ * (default: true)
1136
+ *
1137
+ * @return true if the signature was verified, false if not.
1138
+ */
1139
+ key.verify = function(digest, signature, scheme, options) {
1140
+ if(typeof scheme === 'string') {
1141
+ scheme = scheme.toUpperCase();
1142
+ } else if(scheme === undefined) {
1143
+ scheme = 'RSASSA-PKCS1-V1_5';
1144
+ }
1145
+ if(options === undefined) {
1146
+ options = {
1147
+ _parseAllDigestBytes: true
1148
+ };
1149
+ }
1150
+ if(!('_parseAllDigestBytes' in options)) {
1151
+ options._parseAllDigestBytes = true;
1152
+ }
1153
+
1154
+ if(scheme === 'RSASSA-PKCS1-V1_5') {
1155
+ scheme = {
1156
+ verify: function(digest, d) {
1157
+ // remove padding
1158
+ d = _decodePkcs1_v1_5(d, key, true);
1159
+ // d is ASN.1 BER-encoded DigestInfo
1160
+ var obj = asn1.fromDer(d, {
1161
+ parseAllBytes: options._parseAllDigestBytes
1162
+ });
1163
+
1164
+ // validate DigestInfo
1165
+ var capture = {};
1166
+ var errors = [];
1167
+ if(!asn1.validate(obj, digestInfoValidator, capture, errors)) {
1168
+ var error = new Error(
1169
+ 'ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 ' +
1170
+ 'DigestInfo value.');
1171
+ error.errors = errors;
1172
+ throw error;
1173
+ }
1174
+ // check hash algorithm identifier
1175
+ // see PKCS1-v1-5DigestAlgorithms in RFC 8017
1176
+ // FIXME: add support to validator for strict value choices
1177
+ var oid = asn1.derToOid(capture.algorithmIdentifier);
1178
+ if(!(oid === forge.oids.md2 ||
1179
+ oid === forge.oids.md5 ||
1180
+ oid === forge.oids.sha1 ||
1181
+ oid === forge.oids.sha224 ||
1182
+ oid === forge.oids.sha256 ||
1183
+ oid === forge.oids.sha384 ||
1184
+ oid === forge.oids.sha512 ||
1185
+ oid === forge.oids['sha512-224'] ||
1186
+ oid === forge.oids['sha512-256'])) {
1187
+ var error = new Error(
1188
+ 'Unknown RSASSA-PKCS1-v1_5 DigestAlgorithm identifier.');
1189
+ error.oid = oid;
1190
+ throw error;
1191
+ }
1192
+
1193
+ // special check for md2 and md5 that NULL parameters exist
1194
+ if(oid === forge.oids.md2 || oid === forge.oids.md5) {
1195
+ if(!('parameters' in capture)) {
1196
+ throw new Error(
1197
+ 'ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 ' +
1198
+ 'DigestInfo value. ' +
1199
+ 'Missing algorithm identifier NULL parameters.');
1200
+ }
1201
+ }
1202
+
1203
+ // compare the given digest to the decrypted one
1204
+ return digest === capture.digest;
1205
+ }
1206
+ };
1207
+ } else if(scheme === 'NONE' || scheme === 'NULL' || scheme === null) {
1208
+ scheme = {
1209
+ verify: function(digest, d) {
1210
+ // remove padding
1211
+ d = _decodePkcs1_v1_5(d, key, true);
1212
+ return digest === d;
1213
+ }
1214
+ };
1215
+ }
1216
+
1217
+ // do rsa decryption w/o any decoding, then verify -- which does decoding
1218
+ var d = pki.rsa.decrypt(signature, key, true, false);
1219
+ return scheme.verify(digest, d, key.n.bitLength());
1220
+ };
1221
+
1222
+ return key;
1223
+ };
1224
+
1225
+ /**
1226
+ * Sets an RSA private key from BigIntegers modulus, exponent, primes,
1227
+ * prime exponents, and modular multiplicative inverse.
1228
+ *
1229
+ * @param n the modulus.
1230
+ * @param e the public exponent.
1231
+ * @param d the private exponent ((inverse of e) mod n).
1232
+ * @param p the first prime.
1233
+ * @param q the second prime.
1234
+ * @param dP exponent1 (d mod (p-1)).
1235
+ * @param dQ exponent2 (d mod (q-1)).
1236
+ * @param qInv ((inverse of q) mod p)
1237
+ *
1238
+ * @return the private key.
1239
+ */
1240
+ pki.setRsaPrivateKey = pki.rsa.setPrivateKey = function(
1241
+ n, e, d, p, q, dP, dQ, qInv) {
1242
+ var key = {
1243
+ n: n,
1244
+ e: e,
1245
+ d: d,
1246
+ p: p,
1247
+ q: q,
1248
+ dP: dP,
1249
+ dQ: dQ,
1250
+ qInv: qInv
1251
+ };
1252
+
1253
+ /**
1254
+ * Decrypts the given data with this private key. The decryption scheme
1255
+ * must match the one used to encrypt the data.
1256
+ *
1257
+ * @param data the byte string to decrypt.
1258
+ * @param scheme the decryption scheme to use:
1259
+ * 'RSAES-PKCS1-V1_5' (default),
1260
+ * 'RSA-OAEP',
1261
+ * 'RAW', 'NONE', or null to perform raw RSA decryption.
1262
+ * @param schemeOptions any scheme-specific options.
1263
+ *
1264
+ * @return the decrypted byte string.
1265
+ */
1266
+ key.decrypt = function(data, scheme, schemeOptions) {
1267
+ if(typeof scheme === 'string') {
1268
+ scheme = scheme.toUpperCase();
1269
+ } else if(scheme === undefined) {
1270
+ scheme = 'RSAES-PKCS1-V1_5';
1271
+ }
1272
+
1273
+ // do rsa decryption w/o any decoding
1274
+ var d = pki.rsa.decrypt(data, key, false, false);
1275
+
1276
+ if(scheme === 'RSAES-PKCS1-V1_5') {
1277
+ scheme = {decode: _decodePkcs1_v1_5};
1278
+ } else if(scheme === 'RSA-OAEP' || scheme === 'RSAES-OAEP') {
1279
+ scheme = {
1280
+ decode: function(d, key) {
1281
+ return forge.pkcs1.decode_rsa_oaep(key, d, schemeOptions);
1282
+ }
1283
+ };
1284
+ } else if(['RAW', 'NONE', 'NULL', null].indexOf(scheme) !== -1) {
1285
+ scheme = {decode: function(d) {return d;}};
1286
+ } else {
1287
+ throw new Error('Unsupported encryption scheme: "' + scheme + '".');
1288
+ }
1289
+
1290
+ // decode according to scheme
1291
+ return scheme.decode(d, key, false);
1292
+ };
1293
+
1294
+ /**
1295
+ * Signs the given digest, producing a signature.
1296
+ *
1297
+ * PKCS#1 supports multiple (currently two) signature schemes:
1298
+ * RSASSA-PKCS1-V1_5 and RSASSA-PSS.
1299
+ *
1300
+ * By default this implementation uses the "old scheme", i.e.
1301
+ * RSASSA-PKCS1-V1_5. In order to generate a PSS signature, provide
1302
+ * an instance of Forge PSS object as the scheme parameter.
1303
+ *
1304
+ * @param md the message digest object with the hash to sign.
1305
+ * @param scheme the signature scheme to use:
1306
+ * 'RSASSA-PKCS1-V1_5' or undefined for RSASSA PKCS#1 v1.5,
1307
+ * a Forge PSS object for RSASSA-PSS,
1308
+ * 'NONE' or null for none, DigestInfo will not be used but
1309
+ * PKCS#1 v1.5 padding will still be used.
1310
+ *
1311
+ * @return the signature as a byte string.
1312
+ */
1313
+ key.sign = function(md, scheme) {
1314
+ /* Note: The internal implementation of RSA operations is being
1315
+ transitioned away from a PKCS#1 v1.5 hard-coded scheme. Some legacy
1316
+ code like the use of an encoding block identifier 'bt' will eventually
1317
+ be removed. */
1318
+
1319
+ // private key operation
1320
+ var bt = false;
1321
+
1322
+ if(typeof scheme === 'string') {
1323
+ scheme = scheme.toUpperCase();
1324
+ }
1325
+
1326
+ if(scheme === undefined || scheme === 'RSASSA-PKCS1-V1_5') {
1327
+ scheme = {encode: emsaPkcs1v15encode};
1328
+ bt = 0x01;
1329
+ } else if(scheme === 'NONE' || scheme === 'NULL' || scheme === null) {
1330
+ scheme = {encode: function() {return md;}};
1331
+ bt = 0x01;
1332
+ }
1333
+
1334
+ // encode and then encrypt
1335
+ var d = scheme.encode(md, key.n.bitLength());
1336
+ return pki.rsa.encrypt(d, key, bt);
1337
+ };
1338
+
1339
+ return key;
1340
+ };
1341
+
1342
+ /**
1343
+ * Wraps an RSAPrivateKey ASN.1 object in an ASN.1 PrivateKeyInfo object.
1344
+ *
1345
+ * @param rsaKey the ASN.1 RSAPrivateKey.
1346
+ *
1347
+ * @return the ASN.1 PrivateKeyInfo.
1348
+ */
1349
+ pki.wrapRsaPrivateKey = function(rsaKey) {
1350
+ // PrivateKeyInfo
1351
+ return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
1352
+ // version (0)
1353
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
1354
+ asn1.integerToDer(0).getBytes()),
1355
+ // privateKeyAlgorithm
1356
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
1357
+ asn1.create(
1358
+ asn1.Class.UNIVERSAL, asn1.Type.OID, false,
1359
+ asn1.oidToDer(pki.oids.rsaEncryption).getBytes()),
1360
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
1361
+ ]),
1362
+ // PrivateKey
1363
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false,
1364
+ asn1.toDer(rsaKey).getBytes())
1365
+ ]);
1366
+ };
1367
+
1368
+ /**
1369
+ * Converts a private key from an ASN.1 object.
1370
+ *
1371
+ * @param obj the ASN.1 representation of a PrivateKeyInfo containing an
1372
+ * RSAPrivateKey or an RSAPrivateKey.
1373
+ *
1374
+ * @return the private key.
1375
+ */
1376
+ pki.privateKeyFromAsn1 = function(obj) {
1377
+ // get PrivateKeyInfo
1378
+ var capture = {};
1379
+ var errors = [];
1380
+ if(asn1.validate(obj, privateKeyValidator, capture, errors)) {
1381
+ obj = asn1.fromDer(forge.util.createBuffer(capture.privateKey));
1382
+ }
1383
+
1384
+ // get RSAPrivateKey
1385
+ capture = {};
1386
+ errors = [];
1387
+ if(!asn1.validate(obj, rsaPrivateKeyValidator, capture, errors)) {
1388
+ var error = new Error('Cannot read private key. ' +
1389
+ 'ASN.1 object does not contain an RSAPrivateKey.');
1390
+ error.errors = errors;
1391
+ throw error;
1392
+ }
1393
+
1394
+ // Note: Version is currently ignored.
1395
+ // capture.privateKeyVersion
1396
+ // FIXME: inefficient, get a BigInteger that uses byte strings
1397
+ var n, e, d, p, q, dP, dQ, qInv;
1398
+ n = forge.util.createBuffer(capture.privateKeyModulus).toHex();
1399
+ e = forge.util.createBuffer(capture.privateKeyPublicExponent).toHex();
1400
+ d = forge.util.createBuffer(capture.privateKeyPrivateExponent).toHex();
1401
+ p = forge.util.createBuffer(capture.privateKeyPrime1).toHex();
1402
+ q = forge.util.createBuffer(capture.privateKeyPrime2).toHex();
1403
+ dP = forge.util.createBuffer(capture.privateKeyExponent1).toHex();
1404
+ dQ = forge.util.createBuffer(capture.privateKeyExponent2).toHex();
1405
+ qInv = forge.util.createBuffer(capture.privateKeyCoefficient).toHex();
1406
+
1407
+ // set private key
1408
+ return pki.setRsaPrivateKey(
1409
+ new BigInteger(n, 16),
1410
+ new BigInteger(e, 16),
1411
+ new BigInteger(d, 16),
1412
+ new BigInteger(p, 16),
1413
+ new BigInteger(q, 16),
1414
+ new BigInteger(dP, 16),
1415
+ new BigInteger(dQ, 16),
1416
+ new BigInteger(qInv, 16));
1417
+ };
1418
+
1419
+ /**
1420
+ * Converts a private key to an ASN.1 RSAPrivateKey.
1421
+ *
1422
+ * @param key the private key.
1423
+ *
1424
+ * @return the ASN.1 representation of an RSAPrivateKey.
1425
+ */
1426
+ pki.privateKeyToAsn1 = pki.privateKeyToRSAPrivateKey = function(key) {
1427
+ // RSAPrivateKey
1428
+ return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
1429
+ // version (0 = only 2 primes, 1 multiple primes)
1430
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
1431
+ asn1.integerToDer(0).getBytes()),
1432
+ // modulus (n)
1433
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
1434
+ _bnToBytes(key.n)),
1435
+ // publicExponent (e)
1436
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
1437
+ _bnToBytes(key.e)),
1438
+ // privateExponent (d)
1439
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
1440
+ _bnToBytes(key.d)),
1441
+ // privateKeyPrime1 (p)
1442
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
1443
+ _bnToBytes(key.p)),
1444
+ // privateKeyPrime2 (q)
1445
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
1446
+ _bnToBytes(key.q)),
1447
+ // privateKeyExponent1 (dP)
1448
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
1449
+ _bnToBytes(key.dP)),
1450
+ // privateKeyExponent2 (dQ)
1451
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
1452
+ _bnToBytes(key.dQ)),
1453
+ // coefficient (qInv)
1454
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
1455
+ _bnToBytes(key.qInv))
1456
+ ]);
1457
+ };
1458
+
1459
+ /**
1460
+ * Converts a public key from an ASN.1 SubjectPublicKeyInfo or RSAPublicKey.
1461
+ *
1462
+ * @param obj the asn1 representation of a SubjectPublicKeyInfo or RSAPublicKey.
1463
+ *
1464
+ * @return the public key.
1465
+ */
1466
+ pki.publicKeyFromAsn1 = function(obj) {
1467
+ // get SubjectPublicKeyInfo
1468
+ var capture = {};
1469
+ var errors = [];
1470
+ if(asn1.validate(obj, publicKeyValidator, capture, errors)) {
1471
+ // get oid
1472
+ var oid = asn1.derToOid(capture.publicKeyOid);
1473
+ if(oid !== pki.oids.rsaEncryption) {
1474
+ var error = new Error('Cannot read public key. Unknown OID.');
1475
+ error.oid = oid;
1476
+ throw error;
1477
+ }
1478
+ obj = capture.rsaPublicKey;
1479
+ }
1480
+
1481
+ // get RSA params
1482
+ errors = [];
1483
+ if(!asn1.validate(obj, rsaPublicKeyValidator, capture, errors)) {
1484
+ var error = new Error('Cannot read public key. ' +
1485
+ 'ASN.1 object does not contain an RSAPublicKey.');
1486
+ error.errors = errors;
1487
+ throw error;
1488
+ }
1489
+
1490
+ // FIXME: inefficient, get a BigInteger that uses byte strings
1491
+ var n = forge.util.createBuffer(capture.publicKeyModulus).toHex();
1492
+ var e = forge.util.createBuffer(capture.publicKeyExponent).toHex();
1493
+
1494
+ // set public key
1495
+ return pki.setRsaPublicKey(
1496
+ new BigInteger(n, 16),
1497
+ new BigInteger(e, 16));
1498
+ };
1499
+
1500
+ /**
1501
+ * Converts a public key to an ASN.1 SubjectPublicKeyInfo.
1502
+ *
1503
+ * @param key the public key.
1504
+ *
1505
+ * @return the asn1 representation of a SubjectPublicKeyInfo.
1506
+ */
1507
+ pki.publicKeyToAsn1 = pki.publicKeyToSubjectPublicKeyInfo = function(key) {
1508
+ // SubjectPublicKeyInfo
1509
+ return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
1510
+ // AlgorithmIdentifier
1511
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
1512
+ // algorithm
1513
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OID, false,
1514
+ asn1.oidToDer(pki.oids.rsaEncryption).getBytes()),
1515
+ // parameters (null)
1516
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, '')
1517
+ ]),
1518
+ // subjectPublicKey
1519
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.BITSTRING, false, [
1520
+ pki.publicKeyToRSAPublicKey(key)
1521
+ ])
1522
+ ]);
1523
+ };
1524
+
1525
+ /**
1526
+ * Converts a public key to an ASN.1 RSAPublicKey.
1527
+ *
1528
+ * @param key the public key.
1529
+ *
1530
+ * @return the asn1 representation of a RSAPublicKey.
1531
+ */
1532
+ pki.publicKeyToRSAPublicKey = function(key) {
1533
+ // RSAPublicKey
1534
+ return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [
1535
+ // modulus (n)
1536
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
1537
+ _bnToBytes(key.n)),
1538
+ // publicExponent (e)
1539
+ asn1.create(asn1.Class.UNIVERSAL, asn1.Type.INTEGER, false,
1540
+ _bnToBytes(key.e))
1541
+ ]);
1542
+ };
1543
+
1544
+ /**
1545
+ * Encodes a message using PKCS#1 v1.5 padding.
1546
+ *
1547
+ * @param m the message to encode.
1548
+ * @param key the RSA key to use.
1549
+ * @param bt the block type to use, i.e. either 0x01 (for signing) or 0x02
1550
+ * (for encryption).
1551
+ *
1552
+ * @return the padded byte buffer.
1553
+ */
1554
+ function _encodePkcs1_v1_5(m, key, bt) {
1555
+ var eb = forge.util.createBuffer();
1556
+
1557
+ // get the length of the modulus in bytes
1558
+ var k = Math.ceil(key.n.bitLength() / 8);
1559
+
1560
+ /* use PKCS#1 v1.5 padding */
1561
+ if(m.length > (k - 11)) {
1562
+ var error = new Error('Message is too long for PKCS#1 v1.5 padding.');
1563
+ error.length = m.length;
1564
+ error.max = k - 11;
1565
+ throw error;
1566
+ }
1567
+
1568
+ /* A block type BT, a padding string PS, and the data D shall be
1569
+ formatted into an octet string EB, the encryption block:
1570
+
1571
+ EB = 00 || BT || PS || 00 || D
1572
+
1573
+ The block type BT shall be a single octet indicating the structure of
1574
+ the encryption block. For this version of the document it shall have
1575
+ value 00, 01, or 02. For a private-key operation, the block type
1576
+ shall be 00 or 01. For a public-key operation, it shall be 02.
1577
+
1578
+ The padding string PS shall consist of k-3-||D|| octets. For block
1579
+ type 00, the octets shall have value 00; for block type 01, they
1580
+ shall have value FF; and for block type 02, they shall be
1581
+ pseudorandomly generated and nonzero. This makes the length of the
1582
+ encryption block EB equal to k. */
1583
+
1584
+ // build the encryption block
1585
+ eb.putByte(0x00);
1586
+ eb.putByte(bt);
1587
+
1588
+ // create the padding
1589
+ var padNum = k - 3 - m.length;
1590
+ var padByte;
1591
+ // private key op
1592
+ if(bt === 0x00 || bt === 0x01) {
1593
+ padByte = (bt === 0x00) ? 0x00 : 0xFF;
1594
+ for(var i = 0; i < padNum; ++i) {
1595
+ eb.putByte(padByte);
1596
+ }
1597
+ } else {
1598
+ // public key op
1599
+ // pad with random non-zero values
1600
+ while(padNum > 0) {
1601
+ var numZeros = 0;
1602
+ var padBytes = forge.random.getBytes(padNum);
1603
+ for(var i = 0; i < padNum; ++i) {
1604
+ padByte = padBytes.charCodeAt(i);
1605
+ if(padByte === 0) {
1606
+ ++numZeros;
1607
+ } else {
1608
+ eb.putByte(padByte);
1609
+ }
1610
+ }
1611
+ padNum = numZeros;
1612
+ }
1613
+ }
1614
+
1615
+ // zero followed by message
1616
+ eb.putByte(0x00);
1617
+ eb.putBytes(m);
1618
+
1619
+ return eb;
1620
+ }
1621
+
1622
+ /**
1623
+ * Decodes a message using PKCS#1 v1.5 padding.
1624
+ *
1625
+ * @param em the message to decode.
1626
+ * @param key the RSA key to use.
1627
+ * @param pub true if the key is a public key, false if it is private.
1628
+ * @param ml the message length, if specified.
1629
+ *
1630
+ * @return the decoded bytes.
1631
+ */
1632
+ function _decodePkcs1_v1_5(em, key, pub, ml) {
1633
+ // get the length of the modulus in bytes
1634
+ var k = Math.ceil(key.n.bitLength() / 8);
1635
+
1636
+ /* It is an error if any of the following conditions occurs:
1637
+
1638
+ 1. The encryption block EB cannot be parsed unambiguously.
1639
+ 2. The padding string PS consists of fewer than eight octets
1640
+ or is inconsistent with the block type BT.
1641
+ 3. The decryption process is a public-key operation and the block
1642
+ type BT is not 00 or 01, or the decryption process is a
1643
+ private-key operation and the block type is not 02.
1644
+ */
1645
+
1646
+ // parse the encryption block
1647
+ var eb = forge.util.createBuffer(em);
1648
+ var first = eb.getByte();
1649
+ var bt = eb.getByte();
1650
+ if(first !== 0x00 ||
1651
+ (pub && bt !== 0x00 && bt !== 0x01) ||
1652
+ (!pub && bt != 0x02) ||
1653
+ (pub && bt === 0x00 && typeof(ml) === 'undefined')) {
1654
+ throw new Error('Encryption block is invalid.');
1655
+ }
1656
+
1657
+ var padNum = 0;
1658
+ if(bt === 0x00) {
1659
+ // check all padding bytes for 0x00
1660
+ padNum = k - 3 - ml;
1661
+ for(var i = 0; i < padNum; ++i) {
1662
+ if(eb.getByte() !== 0x00) {
1663
+ throw new Error('Encryption block is invalid.');
1664
+ }
1665
+ }
1666
+ } else if(bt === 0x01) {
1667
+ // find the first byte that isn't 0xFF, should be after all padding
1668
+ padNum = 0;
1669
+ while(eb.length() > 1) {
1670
+ if(eb.getByte() !== 0xFF) {
1671
+ --eb.read;
1672
+ break;
1673
+ }
1674
+ ++padNum;
1675
+ }
1676
+ } else if(bt === 0x02) {
1677
+ // look for 0x00 byte
1678
+ padNum = 0;
1679
+ while(eb.length() > 1) {
1680
+ if(eb.getByte() === 0x00) {
1681
+ --eb.read;
1682
+ break;
1683
+ }
1684
+ ++padNum;
1685
+ }
1686
+ }
1687
+
1688
+ // zero must be 0x00 and padNum must be (k - 3 - message length)
1689
+ var zero = eb.getByte();
1690
+ if(zero !== 0x00 || padNum !== (k - 3 - eb.length())) {
1691
+ throw new Error('Encryption block is invalid.');
1692
+ }
1693
+
1694
+ return eb.getBytes();
1695
+ }
1696
+
1697
+ /**
1698
+ * Runs the key-generation algorithm asynchronously, either in the background
1699
+ * via Web Workers, or using the main thread and setImmediate.
1700
+ *
1701
+ * @param state the key-pair generation state.
1702
+ * @param [options] options for key-pair generation:
1703
+ * workerScript the worker script URL.
1704
+ * workers the number of web workers (if supported) to use,
1705
+ * (default: 2, -1 to use estimated cores minus one).
1706
+ * workLoad the size of the work load, ie: number of possible prime
1707
+ * numbers for each web worker to check per work assignment,
1708
+ * (default: 100).
1709
+ * @param callback(err, keypair) called once the operation completes.
1710
+ */
1711
+ function _generateKeyPair(state, options, callback) {
1712
+ if(typeof options === 'function') {
1713
+ callback = options;
1714
+ options = {};
1715
+ }
1716
+ options = options || {};
1717
+
1718
+ var opts = {
1719
+ algorithm: {
1720
+ name: options.algorithm || 'PRIMEINC',
1721
+ options: {
1722
+ workers: options.workers || 2,
1723
+ workLoad: options.workLoad || 100,
1724
+ workerScript: options.workerScript
1725
+ }
1726
+ }
1727
+ };
1728
+ if('prng' in options) {
1729
+ opts.prng = options.prng;
1730
+ }
1731
+
1732
+ generate();
1733
+
1734
+ function generate() {
1735
+ // find p and then q (done in series to simplify)
1736
+ getPrime(state.pBits, function(err, num) {
1737
+ if(err) {
1738
+ return callback(err);
1739
+ }
1740
+ state.p = num;
1741
+ if(state.q !== null) {
1742
+ return finish(err, state.q);
1743
+ }
1744
+ getPrime(state.qBits, finish);
1745
+ });
1746
+ }
1747
+
1748
+ function getPrime(bits, callback) {
1749
+ forge.prime.generateProbablePrime(bits, opts, callback);
1750
+ }
1751
+
1752
+ function finish(err, num) {
1753
+ if(err) {
1754
+ return callback(err);
1755
+ }
1756
+
1757
+ // set q
1758
+ state.q = num;
1759
+
1760
+ // ensure p is larger than q (swap them if not)
1761
+ if(state.p.compareTo(state.q) < 0) {
1762
+ var tmp = state.p;
1763
+ state.p = state.q;
1764
+ state.q = tmp;
1765
+ }
1766
+
1767
+ // ensure p is coprime with e
1768
+ if(state.p.subtract(BigInteger.ONE).gcd(state.e)
1769
+ .compareTo(BigInteger.ONE) !== 0) {
1770
+ state.p = null;
1771
+ generate();
1772
+ return;
1773
+ }
1774
+
1775
+ // ensure q is coprime with e
1776
+ if(state.q.subtract(BigInteger.ONE).gcd(state.e)
1777
+ .compareTo(BigInteger.ONE) !== 0) {
1778
+ state.q = null;
1779
+ getPrime(state.qBits, finish);
1780
+ return;
1781
+ }
1782
+
1783
+ // compute phi: (p - 1)(q - 1) (Euler's totient function)
1784
+ state.p1 = state.p.subtract(BigInteger.ONE);
1785
+ state.q1 = state.q.subtract(BigInteger.ONE);
1786
+ state.phi = state.p1.multiply(state.q1);
1787
+
1788
+ // ensure e and phi are coprime
1789
+ if(state.phi.gcd(state.e).compareTo(BigInteger.ONE) !== 0) {
1790
+ // phi and e aren't coprime, so generate a new p and q
1791
+ state.p = state.q = null;
1792
+ generate();
1793
+ return;
1794
+ }
1795
+
1796
+ // create n, ensure n is has the right number of bits
1797
+ state.n = state.p.multiply(state.q);
1798
+ if(state.n.bitLength() !== state.bits) {
1799
+ // failed, get new q
1800
+ state.q = null;
1801
+ getPrime(state.qBits, finish);
1802
+ return;
1803
+ }
1804
+
1805
+ // set keys
1806
+ var d = state.e.modInverse(state.phi);
1807
+ state.keys = {
1808
+ privateKey: pki.rsa.setPrivateKey(
1809
+ state.n, state.e, d, state.p, state.q,
1810
+ d.mod(state.p1), d.mod(state.q1),
1811
+ state.q.modInverse(state.p)),
1812
+ publicKey: pki.rsa.setPublicKey(state.n, state.e)
1813
+ };
1814
+
1815
+ callback(null, state.keys);
1816
+ }
1817
+ }
1818
+
1819
+ /**
1820
+ * Converts a positive BigInteger into 2's-complement big-endian bytes.
1821
+ *
1822
+ * @param b the big integer to convert.
1823
+ *
1824
+ * @return the bytes.
1825
+ */
1826
+ function _bnToBytes(b) {
1827
+ // prepend 0x00 if first byte >= 0x80
1828
+ var hex = b.toString(16);
1829
+ if(hex[0] >= '8') {
1830
+ hex = '00' + hex;
1831
+ }
1832
+ var bytes = forge.util.hexToBytes(hex);
1833
+
1834
+ // ensure integer is minimally-encoded
1835
+ if(bytes.length > 1 &&
1836
+ // leading 0x00 for positive integer
1837
+ ((bytes.charCodeAt(0) === 0 &&
1838
+ (bytes.charCodeAt(1) & 0x80) === 0) ||
1839
+ // leading 0xFF for negative integer
1840
+ (bytes.charCodeAt(0) === 0xFF &&
1841
+ (bytes.charCodeAt(1) & 0x80) === 0x80))) {
1842
+ return bytes.substr(1);
1843
+ }
1844
+ return bytes;
1845
+ }
1846
+
1847
+ /**
1848
+ * Returns the required number of Miller-Rabin tests to generate a
1849
+ * prime with an error probability of (1/2)^80.
1850
+ *
1851
+ * See Handbook of Applied Cryptography Chapter 4, Table 4.4.
1852
+ *
1853
+ * @param bits the bit size.
1854
+ *
1855
+ * @return the required number of iterations.
1856
+ */
1857
+ function _getMillerRabinTests(bits) {
1858
+ if(bits <= 100) return 27;
1859
+ if(bits <= 150) return 18;
1860
+ if(bits <= 200) return 15;
1861
+ if(bits <= 250) return 12;
1862
+ if(bits <= 300) return 9;
1863
+ if(bits <= 350) return 8;
1864
+ if(bits <= 400) return 7;
1865
+ if(bits <= 500) return 6;
1866
+ if(bits <= 600) return 5;
1867
+ if(bits <= 800) return 4;
1868
+ if(bits <= 1250) return 3;
1869
+ return 2;
1870
+ }
1871
+
1872
+ /**
1873
+ * Performs feature detection on the Node crypto interface.
1874
+ *
1875
+ * @param fn the feature (function) to detect.
1876
+ *
1877
+ * @return true if detected, false if not.
1878
+ */
1879
+ function _detectNodeCrypto(fn) {
1880
+ return forge.util.isNodejs && typeof _crypto[fn] === 'function';
1881
+ }
1882
+
1883
+ /**
1884
+ * Performs feature detection on the SubtleCrypto interface.
1885
+ *
1886
+ * @param fn the feature (function) to detect.
1887
+ *
1888
+ * @return true if detected, false if not.
1889
+ */
1890
+ function _detectSubtleCrypto(fn) {
1891
+ return (typeof util.globalScope !== 'undefined' &&
1892
+ typeof util.globalScope.crypto === 'object' &&
1893
+ typeof util.globalScope.crypto.subtle === 'object' &&
1894
+ typeof util.globalScope.crypto.subtle[fn] === 'function');
1895
+ }
1896
+
1897
+ /**
1898
+ * Performs feature detection on the deprecated Microsoft Internet Explorer
1899
+ * outdated SubtleCrypto interface. This function should only be used after
1900
+ * checking for the modern, standard SubtleCrypto interface.
1901
+ *
1902
+ * @param fn the feature (function) to detect.
1903
+ *
1904
+ * @return true if detected, false if not.
1905
+ */
1906
+ function _detectSubtleMsCrypto(fn) {
1907
+ return (typeof util.globalScope !== 'undefined' &&
1908
+ typeof util.globalScope.msCrypto === 'object' &&
1909
+ typeof util.globalScope.msCrypto.subtle === 'object' &&
1910
+ typeof util.globalScope.msCrypto.subtle[fn] === 'function');
1911
+ }
1912
+
1913
+ function _intToUint8Array(x) {
1914
+ var bytes = forge.util.hexToBytes(x.toString(16));
1915
+ var buffer = new Uint8Array(bytes.length);
1916
+ for(var i = 0; i < bytes.length; ++i) {
1917
+ buffer[i] = bytes.charCodeAt(i);
1918
+ }
1919
+ return buffer;
1920
+ }
1921
+
1922
+ function _privateKeyFromJwk(jwk) {
1923
+ if(jwk.kty !== 'RSA') {
1924
+ throw new Error(
1925
+ 'Unsupported key algorithm "' + jwk.kty + '"; algorithm must be "RSA".');
1926
+ }
1927
+ return pki.setRsaPrivateKey(
1928
+ _base64ToBigInt(jwk.n),
1929
+ _base64ToBigInt(jwk.e),
1930
+ _base64ToBigInt(jwk.d),
1931
+ _base64ToBigInt(jwk.p),
1932
+ _base64ToBigInt(jwk.q),
1933
+ _base64ToBigInt(jwk.dp),
1934
+ _base64ToBigInt(jwk.dq),
1935
+ _base64ToBigInt(jwk.qi));
1936
+ }
1937
+
1938
+ function _publicKeyFromJwk(jwk) {
1939
+ if(jwk.kty !== 'RSA') {
1940
+ throw new Error('Key algorithm must be "RSA".');
1941
+ }
1942
+ return pki.setRsaPublicKey(
1943
+ _base64ToBigInt(jwk.n),
1944
+ _base64ToBigInt(jwk.e));
1945
+ }
1946
+
1947
+ function _base64ToBigInt(b64) {
1948
+ return new BigInteger(forge.util.bytesToHex(forge.util.decode64(b64)), 16);
1949
+ }