SPB Git forge

spb/admin-ka

Public
41commits 1branches 0releases
172.9 MBsize
maindefault branch
19 days agolast push
JavaScript 65.5% Python 17.8% CSS 13% HTML 3.7%
4.5 KB · 109 lines javascript
Raw Blame History
1"use strict";23Object.defineProperty(exports, "__esModule", {4  value: true5});6exports["default"] = void 0;7var _aes = require("./aes.js");8var _des = require("./des.js");9var _rsa = require("./rsa.js");10var _dh = require("./dh.js");11var _md = require("./md5.js");12function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }13function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }14function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }15function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }16function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }17function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }18// A single interface for the cryptographic algorithms not supported by SubtleCrypto.19// Both synchronous and asynchronous implmentations are allowed.20var LegacyCrypto = /*#__PURE__*/function () {21  function LegacyCrypto() {22    _classCallCheck(this, LegacyCrypto);23    this._algorithms = {24      "AES-ECB": _aes.AESECBCipher,25      "AES-EAX": _aes.AESEAXCipher,26      "DES-ECB": _des.DESECBCipher,27      "DES-CBC": _des.DESCBCCipher,28      "RSA-PKCS1-v1_5": _rsa.RSACipher,29      "DH": _dh.DHCipher,30      "MD5": _md.MD531    };32  }33  return _createClass(LegacyCrypto, [{34    key: "encrypt",35    value: function encrypt(algorithm, key, data) {36      if (key.algorithm.name !== algorithm.name) {37        throw new Error("algorithm does not match");38      }39      if (typeof key.encrypt !== "function") {40        throw new Error("key does not support encryption");41      }42      return key.encrypt(algorithm, data);43    }44  }, {45    key: "decrypt",46    value: function decrypt(algorithm, key, data) {47      if (key.algorithm.name !== algorithm.name) {48        throw new Error("algorithm does not match");49      }50      if (typeof key.decrypt !== "function") {51        throw new Error("key does not support encryption");52      }53      return key.decrypt(algorithm, data);54    }55  }, {56    key: "importKey",57    value: function importKey(format, keyData, algorithm, extractable, keyUsages) {58      if (format !== "raw") {59        throw new Error("key format is not supported");60      }61      var alg = this._algorithms[algorithm.name];62      if (typeof alg === "undefined" || typeof alg.importKey !== "function") {63        throw new Error("algorithm is not supported");64      }65      return alg.importKey(keyData, algorithm, extractable, keyUsages);66    }67  }, {68    key: "generateKey",69    value: function generateKey(algorithm, extractable, keyUsages) {70      var alg = this._algorithms[algorithm.name];71      if (typeof alg === "undefined" || typeof alg.generateKey !== "function") {72        throw new Error("algorithm is not supported");73      }74      return alg.generateKey(algorithm, extractable, keyUsages);75    }76  }, {77    key: "exportKey",78    value: function exportKey(format, key) {79      if (format !== "raw") {80        throw new Error("key format is not supported");81      }82      if (typeof key.exportKey !== "function") {83        throw new Error("key does not support exportKey");84      }85      return key.exportKey();86    }87  }, {88    key: "digest",89    value: function digest(algorithm, data) {90      var alg = this._algorithms[algorithm];91      if (typeof alg !== "function") {92        throw new Error("algorithm is not supported");93      }94      return alg(data);95    }96  }, {97    key: "deriveBits",98    value: function deriveBits(algorithm, key, length) {99      if (key.algorithm.name !== algorithm.name) {100        throw new Error("algorithm does not match");101      }102      if (typeof key.deriveBits !== "function") {103        throw new Error("key does not support deriveBits");104      }105      return key.deriveBits(algorithm, length);106    }107  }]);108}();109var _default = exports["default"] = new LegacyCrypto();