微信小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511
  1. module.exports = (function() {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
  4. var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
  5. var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
  6. var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
  7. __DEFINE__(1709513243594, function(require, module, exports) {
  8. var __TEMP__ = require('./JSEncrypt');var JSEncrypt = __TEMP__['JSEncrypt'];
  9. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, 'JSEncrypt', { enumerable: true, configurable: true, get: function() { return JSEncrypt; } });
  10. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });exports.default = JSEncrypt;
  11. }, function(modId) {var map = {"./JSEncrypt":1709513243595}; return __REQUIRE__(map[modId], modId); })
  12. __DEFINE__(1709513243595, function(require, module, exports) {
  13. var __TEMP__ = require('./lib/jsbn/base64');var b64tohex = __TEMP__['b64tohex'];var hex2b64 = __TEMP__['hex2b64'];
  14. var __TEMP__ = require('./JSEncryptRSAKey');var JSEncryptRSAKey = __TEMP__['JSEncryptRSAKey'];
  15. var __TEMP__ = require('./version.json');var version = __REQUIRE_DEFAULT__(__TEMP__);
  16. /**
  17. *
  18. * @param {Object} [options = {}] - An object to customize JSEncrypt behaviour
  19. * possible parameters are:
  20. * - default_key_size {number} default: 1024 the key size in bit
  21. * - default_public_exponent {string} default: '010001' the hexadecimal representation of the public exponent
  22. * - log {boolean} default: false whether log warn/error or not
  23. * @constructor
  24. */
  25. var JSEncrypt = /** @class */ (function () {
  26. function JSEncrypt(options) {
  27. if (options === void 0) { options = {}; }
  28. options = options || {};
  29. this.default_key_size = options.default_key_size ? parseInt(options.default_key_size, 10) : 1024;
  30. this.default_public_exponent = options.default_public_exponent || "010001"; // 65537 default openssl public exponent for rsa key type
  31. this.log = options.log || false;
  32. // The private and public key.
  33. this.key = null;
  34. }
  35. /**
  36. * Method to set the rsa key parameter (one method is enough to set both the public
  37. * and the private key, since the private key contains the public key paramenters)
  38. * Log a warning if logs are enabled
  39. * @param {Object|string} key the pem encoded string or an object (with or without header/footer)
  40. * @public
  41. */
  42. JSEncrypt.prototype.setKey = function (key) {
  43. if (this.log && this.key) {
  44. console.warn("A key was already set, overriding existing.");
  45. }
  46. this.key = new JSEncryptRSAKey(key);
  47. };
  48. /**
  49. * Proxy method for setKey, for api compatibility
  50. * @see setKey
  51. * @public
  52. */
  53. JSEncrypt.prototype.setPrivateKey = function (privkey) {
  54. // Create the key.
  55. this.setKey(privkey);
  56. };
  57. /**
  58. * Proxy method for setKey, for api compatibility
  59. * @see setKey
  60. * @public
  61. */
  62. JSEncrypt.prototype.setPublicKey = function (pubkey) {
  63. // Sets the public key.
  64. this.setKey(pubkey);
  65. };
  66. /**
  67. * Proxy method for RSAKey object's decrypt, decrypt the string using the private
  68. * components of the rsa key object. Note that if the object was not set will be created
  69. * on the fly (by the getKey method) using the parameters passed in the JSEncrypt constructor
  70. * @param {string} str base64 encoded crypted string to decrypt
  71. * @return {string} the decrypted string
  72. * @public
  73. */
  74. JSEncrypt.prototype.decrypt = function (str) {
  75. // Return the decrypted string.
  76. try {
  77. return this.getKey().decrypt(b64tohex(str));
  78. }
  79. catch (ex) {
  80. return false;
  81. }
  82. };
  83. /**
  84. * Proxy method for RSAKey object's encrypt, encrypt the string using the public
  85. * components of the rsa key object. Note that if the object was not set will be created
  86. * on the fly (by the getKey method) using the parameters passed in the JSEncrypt constructor
  87. * @param {string} str the string to encrypt
  88. * @return {string} the encrypted string encoded in base64
  89. * @public
  90. */
  91. JSEncrypt.prototype.encrypt = function (str) {
  92. // Return the encrypted string.
  93. try {
  94. return hex2b64(this.getKey().encrypt(str));
  95. }
  96. catch (ex) {
  97. return false;
  98. }
  99. };
  100. // 超长文本加密
  101. JSEncrypt.prototype.encryptLong = function (str) {
  102. try {
  103. return hex2b64(this.getKey().encryptLong(str));
  104. }
  105. catch (ex) {
  106. return false;
  107. }
  108. };
  109. // 超长文本解密
  110. JSEncrypt.prototype.decryptLong = function (str) {
  111. try {
  112. return this.getKey().decryptLong(b64tohex(str));
  113. }
  114. catch (ex) {
  115. return false;
  116. }
  117. };
  118. /**
  119. * Proxy method for RSAKey object's sign.
  120. * @param {string} str the string to sign
  121. * @param {function} digestMethod hash method
  122. * @param {string} digestName the name of the hash algorithm
  123. * @return {string} the signature encoded in base64
  124. * @public
  125. */
  126. JSEncrypt.prototype.sign = function (str, digestMethod, digestName) {
  127. // return the RSA signature of 'str' in 'hex' format.
  128. try {
  129. return hex2b64(this.getKey().sign(str, digestMethod, digestName));
  130. }
  131. catch (ex) {
  132. return false;
  133. }
  134. };
  135. /**
  136. * Proxy method for RSAKey object's verify.
  137. * @param {string} str the string to verify
  138. * @param {string} signature the signature encoded in base64 to compare the string to
  139. * @param {function} digestMethod hash method
  140. * @return {boolean} whether the data and signature match
  141. * @public
  142. */
  143. JSEncrypt.prototype.verify = function (str, signature, digestMethod) {
  144. // Return the decrypted 'digest' of the signature.
  145. try {
  146. return this.getKey().verify(str, b64tohex(signature), digestMethod);
  147. }
  148. catch (ex) {
  149. return false;
  150. }
  151. };
  152. /**
  153. * Getter for the current JSEncryptRSAKey object. If it doesn't exists a new object
  154. * will be created and returned
  155. * @param {callback} [cb] the callback to be called if we want the key to be generated
  156. * in an async fashion
  157. * @returns {JSEncryptRSAKey} the JSEncryptRSAKey object
  158. * @public
  159. */
  160. JSEncrypt.prototype.getKey = function (cb) {
  161. // Only create new if it does not exist.
  162. if (!this.key) {
  163. // Get a new private key.
  164. this.key = new JSEncryptRSAKey();
  165. if (cb && {}.toString.call(cb) === "[object Function]") {
  166. this.key.generateAsync(this.default_key_size, this.default_public_exponent, cb);
  167. return;
  168. }
  169. // Generate the key.
  170. this.key.generate(this.default_key_size, this.default_public_exponent);
  171. }
  172. return this.key;
  173. };
  174. /**
  175. * Returns the pem encoded representation of the private key
  176. * If the key doesn't exists a new key will be created
  177. * @returns {string} pem encoded representation of the private key WITH header and footer
  178. * @public
  179. */
  180. JSEncrypt.prototype.getPrivateKey = function () {
  181. // Return the private representation of this key.
  182. return this.getKey().getPrivateKey();
  183. };
  184. /**
  185. * Returns the pem encoded representation of the private key
  186. * If the key doesn't exists a new key will be created
  187. * @returns {string} pem encoded representation of the private key WITHOUT header and footer
  188. * @public
  189. */
  190. JSEncrypt.prototype.getPrivateKeyB64 = function () {
  191. // Return the private representation of this key.
  192. return this.getKey().getPrivateBaseKeyB64();
  193. };
  194. /**
  195. * Returns the pem encoded representation of the public key
  196. * If the key doesn't exists a new key will be created
  197. * @returns {string} pem encoded representation of the public key WITH header and footer
  198. * @public
  199. */
  200. JSEncrypt.prototype.getPublicKey = function () {
  201. // Return the private representation of this key.
  202. return this.getKey().getPublicKey();
  203. };
  204. /**
  205. * Returns the pem encoded representation of the public key
  206. * If the key doesn't exists a new key will be created
  207. * @returns {string} pem encoded representation of the public key WITHOUT header and footer
  208. * @public
  209. */
  210. JSEncrypt.prototype.getPublicKeyB64 = function () {
  211. // Return the private representation of this key.
  212. return this.getKey().getPublicBaseKeyB64();
  213. };
  214. JSEncrypt.version = version.version;
  215. return JSEncrypt;
  216. }());
  217. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, 'JSEncrypt', { enumerable: true, configurable: true, get: function() { return JSEncrypt; } });
  218. }, function(modId) { var map = {"./lib/jsbn/base64":1709513243596,"./JSEncryptRSAKey":1709513243598,"./version.json":1709513243609}; return __REQUIRE__(map[modId], modId); })
  219. __DEFINE__(1709513243596, function(require, module, exports) {
  220. var __TEMP__ = require('./util');var int2char = __TEMP__['int2char'];
  221. var b64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  222. var b64pad = "=";
  223. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function hex2b64(h) {
  224. var i;
  225. var c;
  226. var ret = "";
  227. for (i = 0; i + 3 <= h.length; i += 3) {
  228. c = parseInt(h.substring(i, i + 3), 16);
  229. ret += b64map.charAt(c >> 6) + b64map.charAt(c & 63);
  230. }
  231. if (i + 1 == h.length) {
  232. c = parseInt(h.substring(i, i + 1), 16);
  233. ret += b64map.charAt(c << 2);
  234. }
  235. else if (i + 2 == h.length) {
  236. c = parseInt(h.substring(i, i + 2), 16);
  237. ret += b64map.charAt(c >> 2) + b64map.charAt((c & 3) << 4);
  238. }
  239. while ((ret.length & 3) > 0) {
  240. ret += b64pad;
  241. }
  242. return ret;
  243. };exports.hex2b64 = hex2b64
  244. // convert a base64 string to hex
  245. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function b64tohex(s) {
  246. var ret = "";
  247. var i;
  248. var k = 0; // b64 state, 0-3
  249. var slop = 0;
  250. for (i = 0; i < s.length; ++i) {
  251. if (s.charAt(i) == b64pad) {
  252. break;
  253. }
  254. var v = b64map.indexOf(s.charAt(i));
  255. if (v < 0) {
  256. continue;
  257. }
  258. if (k == 0) {
  259. ret += int2char(v >> 2);
  260. slop = v & 3;
  261. k = 1;
  262. }
  263. else if (k == 1) {
  264. ret += int2char((slop << 2) | (v >> 4));
  265. slop = v & 0xf;
  266. k = 2;
  267. }
  268. else if (k == 2) {
  269. ret += int2char(slop);
  270. ret += int2char(v >> 2);
  271. slop = v & 3;
  272. k = 3;
  273. }
  274. else {
  275. ret += int2char((slop << 2) | (v >> 4));
  276. ret += int2char(v & 0xf);
  277. k = 0;
  278. }
  279. }
  280. if (k == 1) {
  281. ret += int2char(slop << 2);
  282. }
  283. return ret;
  284. };exports.b64tohex = b64tohex
  285. // convert a base64 string to a byte/number array
  286. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function b64toBA(s) {
  287. // piggyback on b64tohex for now, optimize later
  288. var h = b64tohex(s);
  289. var i;
  290. var a = [];
  291. for (i = 0; 2 * i < h.length; ++i) {
  292. a[i] = parseInt(h.substring(2 * i, 2 * i + 2), 16);
  293. }
  294. return a;
  295. };exports.b64toBA = b64toBA
  296. }, function(modId) { var map = {"./util":1709513243597}; return __REQUIRE__(map[modId], modId); })
  297. __DEFINE__(1709513243597, function(require, module, exports) {
  298. var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
  299. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function int2char(n) {
  300. return BI_RM.charAt(n);
  301. };exports.int2char = int2char
  302. //#region BIT_OPERATIONS
  303. // (public) this & a
  304. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function op_and(x, y) {
  305. return x & y;
  306. };exports.op_and = op_and
  307. // (public) this | a
  308. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function op_or(x, y) {
  309. return x | y;
  310. };exports.op_or = op_or
  311. // (public) this ^ a
  312. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function op_xor(x, y) {
  313. return x ^ y;
  314. };exports.op_xor = op_xor
  315. // (public) this & ~a
  316. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function op_andnot(x, y) {
  317. return x & ~y;
  318. };exports.op_andnot = op_andnot
  319. // return index of lowest 1-bit in x, x < 2^31
  320. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function lbit(x) {
  321. if (x == 0) {
  322. return -1;
  323. }
  324. var r = 0;
  325. if ((x & 0xffff) == 0) {
  326. x >>= 16;
  327. r += 16;
  328. }
  329. if ((x & 0xff) == 0) {
  330. x >>= 8;
  331. r += 8;
  332. }
  333. if ((x & 0xf) == 0) {
  334. x >>= 4;
  335. r += 4;
  336. }
  337. if ((x & 3) == 0) {
  338. x >>= 2;
  339. r += 2;
  340. }
  341. if ((x & 1) == 0) {
  342. ++r;
  343. }
  344. return r;
  345. };exports.lbit = lbit
  346. // return number of 1 bits in x
  347. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function cbit(x) {
  348. var r = 0;
  349. while (x != 0) {
  350. x &= x - 1;
  351. ++r;
  352. }
  353. return r;
  354. };exports.cbit = cbit
  355. //#endregion BIT_OPERATIONS
  356. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  357. __DEFINE__(1709513243598, function(require, module, exports) {
  358. var __extends = (this && this.__extends) || (function () {
  359. var extendStatics = function (d, b) {
  360. extendStatics = Object.setPrototypeOf ||
  361. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  362. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  363. return extendStatics(d, b);
  364. };
  365. return function (d, b) {
  366. if (typeof b !== "function" && b !== null)
  367. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  368. extendStatics(d, b);
  369. function __() { this.constructor = d; }
  370. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  371. };
  372. })();
  373. var __TEMP__ = require('./lib/jsbn/base64');var hex2b64 = __TEMP__['hex2b64'];
  374. var __TEMP__ = require('./lib/asn1js/hex');var Hex = __TEMP__['Hex'];
  375. var __TEMP__ = require('./lib/asn1js/base64');var Base64 = __TEMP__['Base64'];
  376. var __TEMP__ = require('./lib/asn1js/asn1');var ASN1 = __TEMP__['ASN1'];
  377. var __TEMP__ = require('./lib/jsbn/rsa');var RSAKey = __TEMP__['RSAKey'];
  378. var __TEMP__ = require('./lib/jsbn/jsbn');var parseBigInt = __TEMP__['parseBigInt'];
  379. var __TEMP__ = require('./lib/jsrsasign/asn1-1.0');var KJUR = __TEMP__['KJUR'];
  380. /**
  381. * Create a new JSEncryptRSAKey that extends Tom Wu's RSA key object.
  382. * This object is just a decorator for parsing the key parameter
  383. * @param {string|Object} key - The key in string format, or an object containing
  384. * the parameters needed to build a RSAKey object.
  385. * @constructor
  386. */
  387. var JSEncryptRSAKey = /** @class */ (function (_super) {
  388. __extends(JSEncryptRSAKey, _super);
  389. function JSEncryptRSAKey(key) {
  390. var _this = _super.call(this) || this;
  391. // Call the super constructor.
  392. // RSAKey.call(this);
  393. // If a key key was provided.
  394. if (key) {
  395. // If this is a string...
  396. if (typeof key === "string") {
  397. _this.parseKey(key);
  398. }
  399. else if (JSEncryptRSAKey.hasPrivateKeyProperty(key) ||
  400. JSEncryptRSAKey.hasPublicKeyProperty(key)) {
  401. // Set the values for the key.
  402. _this.parsePropertiesFrom(key);
  403. }
  404. }
  405. return _this;
  406. }
  407. /**
  408. * Method to parse a pem encoded string containing both a public or private key.
  409. * The method will translate the pem encoded string in a der encoded string and
  410. * will parse private key and public key parameters. This method accepts public key
  411. * in the rsaencryption pkcs #1 format (oid: 1.2.840.113549.1.1.1).
  412. *
  413. * @todo Check how many rsa formats use the same format of pkcs #1.
  414. *
  415. * The format is defined as:
  416. * PublicKeyInfo ::= SEQUENCE {
  417. * algorithm AlgorithmIdentifier,
  418. * PublicKey BIT STRING
  419. * }
  420. * Where AlgorithmIdentifier is:
  421. * AlgorithmIdentifier ::= SEQUENCE {
  422. * algorithm OBJECT IDENTIFIER, the OID of the enc algorithm
  423. * parameters ANY DEFINED BY algorithm OPTIONAL (NULL for PKCS #1)
  424. * }
  425. * and PublicKey is a SEQUENCE encapsulated in a BIT STRING
  426. * RSAPublicKey ::= SEQUENCE {
  427. * modulus INTEGER, -- n
  428. * publicExponent INTEGER -- e
  429. * }
  430. * it's possible to examine the structure of the keys obtained from openssl using
  431. * an asn.1 dumper as the one used here to parse the components: http://lapo.it/asn1js/
  432. * @argument {string} pem the pem encoded string, can include the BEGIN/END header/footer
  433. * @private
  434. */
  435. JSEncryptRSAKey.prototype.parseKey = function (pem) {
  436. try {
  437. var modulus = 0;
  438. var public_exponent = 0;
  439. var reHex = /^\s*(?:[0-9A-Fa-f][0-9A-Fa-f]\s*)+$/;
  440. var der = reHex.test(pem) ? Hex.decode(pem) : Base64.unarmor(pem);
  441. var asn1 = ASN1.decode(der);
  442. // Fixes a bug with OpenSSL 1.0+ private keys
  443. if (asn1.sub.length === 3) {
  444. asn1 = asn1.sub[2].sub[0];
  445. }
  446. if (asn1.sub.length === 9) {
  447. // Parse the private key.
  448. modulus = asn1.sub[1].getHexStringValue(); // bigint
  449. this.n = parseBigInt(modulus, 16);
  450. public_exponent = asn1.sub[2].getHexStringValue(); // int
  451. this.e = parseInt(public_exponent, 16);
  452. var private_exponent = asn1.sub[3].getHexStringValue(); // bigint
  453. this.d = parseBigInt(private_exponent, 16);
  454. var prime1 = asn1.sub[4].getHexStringValue(); // bigint
  455. this.p = parseBigInt(prime1, 16);
  456. var prime2 = asn1.sub[5].getHexStringValue(); // bigint
  457. this.q = parseBigInt(prime2, 16);
  458. var exponent1 = asn1.sub[6].getHexStringValue(); // bigint
  459. this.dmp1 = parseBigInt(exponent1, 16);
  460. var exponent2 = asn1.sub[7].getHexStringValue(); // bigint
  461. this.dmq1 = parseBigInt(exponent2, 16);
  462. var coefficient = asn1.sub[8].getHexStringValue(); // bigint
  463. this.coeff = parseBigInt(coefficient, 16);
  464. }
  465. else if (asn1.sub.length === 2) {
  466. // Parse the public key.
  467. var bit_string = asn1.sub[1];
  468. var sequence = bit_string.sub[0];
  469. modulus = sequence.sub[0].getHexStringValue();
  470. this.n = parseBigInt(modulus, 16);
  471. public_exponent = sequence.sub[1].getHexStringValue();
  472. this.e = parseInt(public_exponent, 16);
  473. }
  474. else {
  475. return false;
  476. }
  477. return true;
  478. }
  479. catch (ex) {
  480. return false;
  481. }
  482. };
  483. /**
  484. * Translate rsa parameters in a hex encoded string representing the rsa key.
  485. *
  486. * The translation follow the ASN.1 notation :
  487. * RSAPrivateKey ::= SEQUENCE {
  488. * version Version,
  489. * modulus INTEGER, -- n
  490. * publicExponent INTEGER, -- e
  491. * privateExponent INTEGER, -- d
  492. * prime1 INTEGER, -- p
  493. * prime2 INTEGER, -- q
  494. * exponent1 INTEGER, -- d mod (p1)
  495. * exponent2 INTEGER, -- d mod (q-1)
  496. * coefficient INTEGER, -- (inverse of q) mod p
  497. * }
  498. * @returns {string} DER Encoded String representing the rsa private key
  499. * @private
  500. */
  501. JSEncryptRSAKey.prototype.getPrivateBaseKey = function () {
  502. var options = {
  503. array: [
  504. new KJUR.asn1.DERInteger({ int: 0 }),
  505. new KJUR.asn1.DERInteger({ bigint: this.n }),
  506. new KJUR.asn1.DERInteger({ int: this.e }),
  507. new KJUR.asn1.DERInteger({ bigint: this.d }),
  508. new KJUR.asn1.DERInteger({ bigint: this.p }),
  509. new KJUR.asn1.DERInteger({ bigint: this.q }),
  510. new KJUR.asn1.DERInteger({ bigint: this.dmp1 }),
  511. new KJUR.asn1.DERInteger({ bigint: this.dmq1 }),
  512. new KJUR.asn1.DERInteger({ bigint: this.coeff })
  513. ]
  514. };
  515. var seq = new KJUR.asn1.DERSequence(options);
  516. return seq.getEncodedHex();
  517. };
  518. /**
  519. * base64 (pem) encoded version of the DER encoded representation
  520. * @returns {string} pem encoded representation without header and footer
  521. * @public
  522. */
  523. JSEncryptRSAKey.prototype.getPrivateBaseKeyB64 = function () {
  524. return hex2b64(this.getPrivateBaseKey());
  525. };
  526. /**
  527. * Translate rsa parameters in a hex encoded string representing the rsa public key.
  528. * The representation follow the ASN.1 notation :
  529. * PublicKeyInfo ::= SEQUENCE {
  530. * algorithm AlgorithmIdentifier,
  531. * PublicKey BIT STRING
  532. * }
  533. * Where AlgorithmIdentifier is:
  534. * AlgorithmIdentifier ::= SEQUENCE {
  535. * algorithm OBJECT IDENTIFIER, the OID of the enc algorithm
  536. * parameters ANY DEFINED BY algorithm OPTIONAL (NULL for PKCS #1)
  537. * }
  538. * and PublicKey is a SEQUENCE encapsulated in a BIT STRING
  539. * RSAPublicKey ::= SEQUENCE {
  540. * modulus INTEGER, -- n
  541. * publicExponent INTEGER -- e
  542. * }
  543. * @returns {string} DER Encoded String representing the rsa public key
  544. * @private
  545. */
  546. JSEncryptRSAKey.prototype.getPublicBaseKey = function () {
  547. var first_sequence = new KJUR.asn1.DERSequence({
  548. array: [
  549. new KJUR.asn1.DERObjectIdentifier({ oid: "1.2.840.113549.1.1.1" }),
  550. new KJUR.asn1.DERNull()
  551. ]
  552. });
  553. var second_sequence = new KJUR.asn1.DERSequence({
  554. array: [
  555. new KJUR.asn1.DERInteger({ bigint: this.n }),
  556. new KJUR.asn1.DERInteger({ int: this.e })
  557. ]
  558. });
  559. var bit_string = new KJUR.asn1.DERBitString({
  560. hex: "00" + second_sequence.getEncodedHex()
  561. });
  562. var seq = new KJUR.asn1.DERSequence({
  563. array: [
  564. first_sequence,
  565. bit_string
  566. ]
  567. });
  568. return seq.getEncodedHex();
  569. };
  570. /**
  571. * base64 (pem) encoded version of the DER encoded representation
  572. * @returns {string} pem encoded representation without header and footer
  573. * @public
  574. */
  575. JSEncryptRSAKey.prototype.getPublicBaseKeyB64 = function () {
  576. return hex2b64(this.getPublicBaseKey());
  577. };
  578. /**
  579. * wrap the string in block of width chars. The default value for rsa keys is 64
  580. * characters.
  581. * @param {string} str the pem encoded string without header and footer
  582. * @param {Number} [width=64] - the length the string has to be wrapped at
  583. * @returns {string}
  584. * @private
  585. */
  586. JSEncryptRSAKey.wordwrap = function (str, width) {
  587. width = width || 64;
  588. if (!str) {
  589. return str;
  590. }
  591. var regex = "(.{1," + width + "})( +|$\n?)|(.{1," + width + "})";
  592. return str.match(RegExp(regex, "g")).join("\n");
  593. };
  594. /**
  595. * Retrieve the pem encoded private key
  596. * @returns {string} the pem encoded private key with header/footer
  597. * @public
  598. */
  599. JSEncryptRSAKey.prototype.getPrivateKey = function () {
  600. var key = "-----BEGIN RSA PRIVATE KEY-----\n";
  601. key += JSEncryptRSAKey.wordwrap(this.getPrivateBaseKeyB64()) + "\n";
  602. key += "-----END RSA PRIVATE KEY-----";
  603. return key;
  604. };
  605. /**
  606. * Retrieve the pem encoded public key
  607. * @returns {string} the pem encoded public key with header/footer
  608. * @public
  609. */
  610. JSEncryptRSAKey.prototype.getPublicKey = function () {
  611. var key = "-----BEGIN PUBLIC KEY-----\n";
  612. key += JSEncryptRSAKey.wordwrap(this.getPublicBaseKeyB64()) + "\n";
  613. key += "-----END PUBLIC KEY-----";
  614. return key;
  615. };
  616. /**
  617. * Check if the object contains the necessary parameters to populate the rsa modulus
  618. * and public exponent parameters.
  619. * @param {Object} [obj={}] - An object that may contain the two public key
  620. * parameters
  621. * @returns {boolean} true if the object contains both the modulus and the public exponent
  622. * properties (n and e)
  623. * @todo check for types of n and e. N should be a parseable bigInt object, E should
  624. * be a parseable integer number
  625. * @private
  626. */
  627. JSEncryptRSAKey.hasPublicKeyProperty = function (obj) {
  628. obj = obj || {};
  629. return (obj.hasOwnProperty("n") &&
  630. obj.hasOwnProperty("e"));
  631. };
  632. /**
  633. * Check if the object contains ALL the parameters of an RSA key.
  634. * @param {Object} [obj={}] - An object that may contain nine rsa key
  635. * parameters
  636. * @returns {boolean} true if the object contains all the parameters needed
  637. * @todo check for types of the parameters all the parameters but the public exponent
  638. * should be parseable bigint objects, the public exponent should be a parseable integer number
  639. * @private
  640. */
  641. JSEncryptRSAKey.hasPrivateKeyProperty = function (obj) {
  642. obj = obj || {};
  643. return (obj.hasOwnProperty("n") &&
  644. obj.hasOwnProperty("e") &&
  645. obj.hasOwnProperty("d") &&
  646. obj.hasOwnProperty("p") &&
  647. obj.hasOwnProperty("q") &&
  648. obj.hasOwnProperty("dmp1") &&
  649. obj.hasOwnProperty("dmq1") &&
  650. obj.hasOwnProperty("coeff"));
  651. };
  652. /**
  653. * Parse the properties of obj in the current rsa object. Obj should AT LEAST
  654. * include the modulus and public exponent (n, e) parameters.
  655. * @param {Object} obj - the object containing rsa parameters
  656. * @private
  657. */
  658. JSEncryptRSAKey.prototype.parsePropertiesFrom = function (obj) {
  659. this.n = obj.n;
  660. this.e = obj.e;
  661. if (obj.hasOwnProperty("d")) {
  662. this.d = obj.d;
  663. this.p = obj.p;
  664. this.q = obj.q;
  665. this.dmp1 = obj.dmp1;
  666. this.dmq1 = obj.dmq1;
  667. this.coeff = obj.coeff;
  668. }
  669. };
  670. return JSEncryptRSAKey;
  671. }(RSAKey));
  672. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, 'JSEncryptRSAKey', { enumerable: true, configurable: true, get: function() { return JSEncryptRSAKey; } });
  673. }, function(modId) { var map = {"./lib/jsbn/base64":1709513243596,"./lib/asn1js/hex":1709513243599,"./lib/asn1js/base64":1709513243600,"./lib/asn1js/asn1":1709513243601,"./lib/jsbn/rsa":1709513243603,"./lib/jsbn/jsbn":1709513243604,"./lib/jsrsasign/asn1-1.0":1709513243607}; return __REQUIRE__(map[modId], modId); })
  674. __DEFINE__(1709513243599, function(require, module, exports) {
  675. // Hex JavaScript decoder
  676. // Copyright (c) 2008-2013 Lapo Luchini <lapo@lapo.it>
  677. // Permission to use, copy, modify, and/or distribute this software for any
  678. // purpose with or without fee is hereby granted, provided that the above
  679. // copyright notice and this permission notice appear in all copies.
  680. //
  681. // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  682. // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  683. // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  684. // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  685. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  686. // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  687. // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  688. /*jshint browser: true, strict: true, immed: true, latedef: true, undef: true, regexdash: false */
  689. var decoder;
  690. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });var Hex = exports.Hex = {
  691. decode: function (a) {
  692. var i;
  693. if (decoder === undefined) {
  694. var hex = "0123456789ABCDEF";
  695. var ignore = " \f\n\r\t\u00A0\u2028\u2029";
  696. decoder = {};
  697. for (i = 0; i < 16; ++i) {
  698. decoder[hex.charAt(i)] = i;
  699. }
  700. hex = hex.toLowerCase();
  701. for (i = 10; i < 16; ++i) {
  702. decoder[hex.charAt(i)] = i;
  703. }
  704. for (i = 0; i < ignore.length; ++i) {
  705. decoder[ignore.charAt(i)] = -1;
  706. }
  707. }
  708. var out = [];
  709. var bits = 0;
  710. var char_count = 0;
  711. for (i = 0; i < a.length; ++i) {
  712. var c = a.charAt(i);
  713. if (c == "=") {
  714. break;
  715. }
  716. c = decoder[c];
  717. if (c == -1) {
  718. continue;
  719. }
  720. if (c === undefined) {
  721. throw new Error("Illegal character at offset " + i);
  722. }
  723. bits |= c;
  724. if (++char_count >= 2) {
  725. out[out.length] = bits;
  726. bits = 0;
  727. char_count = 0;
  728. }
  729. else {
  730. bits <<= 4;
  731. }
  732. }
  733. if (char_count) {
  734. throw new Error("Hex encoding incomplete: 4 bits missing");
  735. }
  736. return out;
  737. }
  738. };
  739. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  740. __DEFINE__(1709513243600, function(require, module, exports) {
  741. // Base64 JavaScript decoder
  742. // Copyright (c) 2008-2013 Lapo Luchini <lapo@lapo.it>
  743. // Permission to use, copy, modify, and/or distribute this software for any
  744. // purpose with or without fee is hereby granted, provided that the above
  745. // copyright notice and this permission notice appear in all copies.
  746. //
  747. // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  748. // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  749. // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  750. // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  751. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  752. // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  753. // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  754. /*jshint browser: true, strict: true, immed: true, latedef: true, undef: true, regexdash: false */
  755. var decoder;
  756. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });var Base64 = exports.Base64 = {
  757. decode: function (a) {
  758. var i;
  759. if (decoder === undefined) {
  760. var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  761. var ignore = "= \f\n\r\t\u00A0\u2028\u2029";
  762. decoder = Object.create(null);
  763. for (i = 0; i < 64; ++i) {
  764. decoder[b64.charAt(i)] = i;
  765. }
  766. decoder['-'] = 62; //+
  767. decoder['_'] = 63; //-
  768. for (i = 0; i < ignore.length; ++i) {
  769. decoder[ignore.charAt(i)] = -1;
  770. }
  771. }
  772. var out = [];
  773. var bits = 0;
  774. var char_count = 0;
  775. for (i = 0; i < a.length; ++i) {
  776. var c = a.charAt(i);
  777. if (c == "=") {
  778. break;
  779. }
  780. c = decoder[c];
  781. if (c == -1) {
  782. continue;
  783. }
  784. if (c === undefined) {
  785. throw new Error("Illegal character at offset " + i);
  786. }
  787. bits |= c;
  788. if (++char_count >= 4) {
  789. out[out.length] = (bits >> 16);
  790. out[out.length] = (bits >> 8) & 0xFF;
  791. out[out.length] = bits & 0xFF;
  792. bits = 0;
  793. char_count = 0;
  794. }
  795. else {
  796. bits <<= 6;
  797. }
  798. }
  799. switch (char_count) {
  800. case 1:
  801. throw new Error("Base64 encoding incomplete: at least 2 bits missing");
  802. case 2:
  803. out[out.length] = (bits >> 10);
  804. break;
  805. case 3:
  806. out[out.length] = (bits >> 16);
  807. out[out.length] = (bits >> 8) & 0xFF;
  808. break;
  809. }
  810. return out;
  811. },
  812. re: /-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,
  813. unarmor: function (a) {
  814. var m = Base64.re.exec(a);
  815. if (m) {
  816. if (m[1]) {
  817. a = m[1];
  818. }
  819. else if (m[2]) {
  820. a = m[2];
  821. }
  822. else {
  823. throw new Error("RegExp out of sync");
  824. }
  825. }
  826. return Base64.decode(a);
  827. }
  828. };
  829. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  830. __DEFINE__(1709513243601, function(require, module, exports) {
  831. // ASN.1 JavaScript decoder
  832. // Copyright (c) 2008-2014 Lapo Luchini <lapo@lapo.it>
  833. // Permission to use, copy, modify, and/or distribute this software for any
  834. // purpose with or without fee is hereby granted, provided that the above
  835. // copyright notice and this permission notice appear in all copies.
  836. //
  837. // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  838. // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  839. // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  840. // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  841. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  842. // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  843. // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  844. /*jshint browser: true, strict: true, immed: true, latedef: true, undef: true, regexdash: false */
  845. /*global oids */
  846. var __TEMP__ = require('./int10');var Int10 = __TEMP__['Int10'];
  847. var ellipsis = "\u2026";
  848. var reTimeS = /^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;
  849. var reTimeL = /^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;
  850. function stringCut(str, len) {
  851. if (str.length > len) {
  852. str = str.substring(0, len) + ellipsis;
  853. }
  854. return str;
  855. }
  856. var Stream = /** @class */ (function () {
  857. function Stream(enc, pos) {
  858. this.hexDigits = "0123456789ABCDEF";
  859. if (enc instanceof Stream) {
  860. this.enc = enc.enc;
  861. this.pos = enc.pos;
  862. }
  863. else {
  864. // enc should be an array or a binary string
  865. this.enc = enc;
  866. this.pos = pos;
  867. }
  868. }
  869. Stream.prototype.get = function (pos) {
  870. if (pos === undefined) {
  871. pos = this.pos++;
  872. }
  873. if (pos >= this.enc.length) {
  874. throw new Error("Requesting byte offset " + pos + " on a stream of length " + this.enc.length);
  875. }
  876. return ("string" === typeof this.enc) ? this.enc.charCodeAt(pos) : this.enc[pos];
  877. };
  878. Stream.prototype.hexByte = function (b) {
  879. return this.hexDigits.charAt((b >> 4) & 0xF) + this.hexDigits.charAt(b & 0xF);
  880. };
  881. Stream.prototype.hexDump = function (start, end, raw) {
  882. var s = "";
  883. for (var i = start; i < end; ++i) {
  884. s += this.hexByte(this.get(i));
  885. if (raw !== true) {
  886. switch (i & 0xF) {
  887. case 0x7:
  888. s += " ";
  889. break;
  890. case 0xF:
  891. s += "\n";
  892. break;
  893. default:
  894. s += " ";
  895. }
  896. }
  897. }
  898. return s;
  899. };
  900. Stream.prototype.isASCII = function (start, end) {
  901. for (var i = start; i < end; ++i) {
  902. var c = this.get(i);
  903. if (c < 32 || c > 176) {
  904. return false;
  905. }
  906. }
  907. return true;
  908. };
  909. Stream.prototype.parseStringISO = function (start, end) {
  910. var s = "";
  911. for (var i = start; i < end; ++i) {
  912. s += String.fromCharCode(this.get(i));
  913. }
  914. return s;
  915. };
  916. Stream.prototype.parseStringUTF = function (start, end) {
  917. var s = "";
  918. for (var i = start; i < end;) {
  919. var c = this.get(i++);
  920. if (c < 128) {
  921. s += String.fromCharCode(c);
  922. }
  923. else if ((c > 191) && (c < 224)) {
  924. s += String.fromCharCode(((c & 0x1F) << 6) | (this.get(i++) & 0x3F));
  925. }
  926. else {
  927. s += String.fromCharCode(((c & 0x0F) << 12) | ((this.get(i++) & 0x3F) << 6) | (this.get(i++) & 0x3F));
  928. }
  929. }
  930. return s;
  931. };
  932. Stream.prototype.parseStringBMP = function (start, end) {
  933. var str = "";
  934. var hi;
  935. var lo;
  936. for (var i = start; i < end;) {
  937. hi = this.get(i++);
  938. lo = this.get(i++);
  939. str += String.fromCharCode((hi << 8) | lo);
  940. }
  941. return str;
  942. };
  943. Stream.prototype.parseTime = function (start, end, shortYear) {
  944. var s = this.parseStringISO(start, end);
  945. var m = (shortYear ? reTimeS : reTimeL).exec(s);
  946. if (!m) {
  947. return "Unrecognized time: " + s;
  948. }
  949. if (shortYear) {
  950. // to avoid querying the timer, use the fixed range [1970, 2069]
  951. // it will conform with ITU X.400 [-10, +40] sliding window until 2030
  952. m[1] = +m[1];
  953. m[1] += (+m[1] < 70) ? 2000 : 1900;
  954. }
  955. s = m[1] + "-" + m[2] + "-" + m[3] + " " + m[4];
  956. if (m[5]) {
  957. s += ":" + m[5];
  958. if (m[6]) {
  959. s += ":" + m[6];
  960. if (m[7]) {
  961. s += "." + m[7];
  962. }
  963. }
  964. }
  965. if (m[8]) {
  966. s += " UTC";
  967. if (m[8] != "Z") {
  968. s += m[8];
  969. if (m[9]) {
  970. s += ":" + m[9];
  971. }
  972. }
  973. }
  974. return s;
  975. };
  976. Stream.prototype.parseInteger = function (start, end) {
  977. var v = this.get(start);
  978. var neg = (v > 127);
  979. var pad = neg ? 255 : 0;
  980. var len;
  981. var s = "";
  982. // skip unuseful bits (not allowed in DER)
  983. while (v == pad && ++start < end) {
  984. v = this.get(start);
  985. }
  986. len = end - start;
  987. if (len === 0) {
  988. return neg ? -1 : 0;
  989. }
  990. // show bit length of huge integers
  991. if (len > 4) {
  992. s = v;
  993. len <<= 3;
  994. while (((+s ^ pad) & 0x80) == 0) {
  995. s = +s << 1;
  996. --len;
  997. }
  998. s = "(" + len + " bit)\n";
  999. }
  1000. // decode the integer
  1001. if (neg) {
  1002. v = v - 256;
  1003. }
  1004. var n = new Int10(v);
  1005. for (var i = start + 1; i < end; ++i) {
  1006. n.mulAdd(256, this.get(i));
  1007. }
  1008. return s + n.toString();
  1009. };
  1010. Stream.prototype.parseBitString = function (start, end, maxLength) {
  1011. var unusedBit = this.get(start);
  1012. var lenBit = ((end - start - 1) << 3) - unusedBit;
  1013. var intro = "(" + lenBit + " bit)\n";
  1014. var s = "";
  1015. for (var i = start + 1; i < end; ++i) {
  1016. var b = this.get(i);
  1017. var skip = (i == end - 1) ? unusedBit : 0;
  1018. for (var j = 7; j >= skip; --j) {
  1019. s += (b >> j) & 1 ? "1" : "0";
  1020. }
  1021. if (s.length > maxLength) {
  1022. return intro + stringCut(s, maxLength);
  1023. }
  1024. }
  1025. return intro + s;
  1026. };
  1027. Stream.prototype.parseOctetString = function (start, end, maxLength) {
  1028. if (this.isASCII(start, end)) {
  1029. return stringCut(this.parseStringISO(start, end), maxLength);
  1030. }
  1031. var len = end - start;
  1032. var s = "(" + len + " byte)\n";
  1033. maxLength /= 2; // we work in bytes
  1034. if (len > maxLength) {
  1035. end = start + maxLength;
  1036. }
  1037. for (var i = start; i < end; ++i) {
  1038. s += this.hexByte(this.get(i));
  1039. }
  1040. if (len > maxLength) {
  1041. s += ellipsis;
  1042. }
  1043. return s;
  1044. };
  1045. Stream.prototype.parseOID = function (start, end, maxLength) {
  1046. var s = "";
  1047. var n = new Int10();
  1048. var bits = 0;
  1049. for (var i = start; i < end; ++i) {
  1050. var v = this.get(i);
  1051. n.mulAdd(128, v & 0x7F);
  1052. bits += 7;
  1053. if (!(v & 0x80)) { // finished
  1054. if (s === "") {
  1055. n = n.simplify();
  1056. if (n instanceof Int10) {
  1057. n.sub(80);
  1058. s = "2." + n.toString();
  1059. }
  1060. else {
  1061. var m = n < 80 ? n < 40 ? 0 : 1 : 2;
  1062. s = m + "." + (n - m * 40);
  1063. }
  1064. }
  1065. else {
  1066. s += "." + n.toString();
  1067. }
  1068. if (s.length > maxLength) {
  1069. return stringCut(s, maxLength);
  1070. }
  1071. n = new Int10();
  1072. bits = 0;
  1073. }
  1074. }
  1075. if (bits > 0) {
  1076. s += ".incomplete";
  1077. }
  1078. return s;
  1079. };
  1080. return Stream;
  1081. }());
  1082. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, 'Stream', { enumerable: true, configurable: true, get: function() { return Stream; } });
  1083. var ASN1 = /** @class */ (function () {
  1084. function ASN1(stream, header, length, tag, sub) {
  1085. if (!(tag instanceof ASN1Tag)) {
  1086. throw new Error("Invalid tag value.");
  1087. }
  1088. this.stream = stream;
  1089. this.header = header;
  1090. this.length = length;
  1091. this.tag = tag;
  1092. this.sub = sub;
  1093. }
  1094. ASN1.prototype.typeName = function () {
  1095. switch (this.tag.tagClass) {
  1096. case 0: // universal
  1097. switch (this.tag.tagNumber) {
  1098. case 0x00:
  1099. return "EOC";
  1100. case 0x01:
  1101. return "BOOLEAN";
  1102. case 0x02:
  1103. return "INTEGER";
  1104. case 0x03:
  1105. return "BIT_STRING";
  1106. case 0x04:
  1107. return "OCTET_STRING";
  1108. case 0x05:
  1109. return "NULL";
  1110. case 0x06:
  1111. return "OBJECT_IDENTIFIER";
  1112. case 0x07:
  1113. return "ObjectDescriptor";
  1114. case 0x08:
  1115. return "EXTERNAL";
  1116. case 0x09:
  1117. return "REAL";
  1118. case 0x0A:
  1119. return "ENUMERATED";
  1120. case 0x0B:
  1121. return "EMBEDDED_PDV";
  1122. case 0x0C:
  1123. return "UTF8String";
  1124. case 0x10:
  1125. return "SEQUENCE";
  1126. case 0x11:
  1127. return "SET";
  1128. case 0x12:
  1129. return "NumericString";
  1130. case 0x13:
  1131. return "PrintableString"; // ASCII subset
  1132. case 0x14:
  1133. return "TeletexString"; // aka T61String
  1134. case 0x15:
  1135. return "VideotexString";
  1136. case 0x16:
  1137. return "IA5String"; // ASCII
  1138. case 0x17:
  1139. return "UTCTime";
  1140. case 0x18:
  1141. return "GeneralizedTime";
  1142. case 0x19:
  1143. return "GraphicString";
  1144. case 0x1A:
  1145. return "VisibleString"; // ASCII subset
  1146. case 0x1B:
  1147. return "GeneralString";
  1148. case 0x1C:
  1149. return "UniversalString";
  1150. case 0x1E:
  1151. return "BMPString";
  1152. }
  1153. return "Universal_" + this.tag.tagNumber.toString();
  1154. case 1:
  1155. return "Application_" + this.tag.tagNumber.toString();
  1156. case 2:
  1157. return "[" + this.tag.tagNumber.toString() + "]"; // Context
  1158. case 3:
  1159. return "Private_" + this.tag.tagNumber.toString();
  1160. }
  1161. };
  1162. ASN1.prototype.content = function (maxLength) {
  1163. if (this.tag === undefined) {
  1164. return null;
  1165. }
  1166. if (maxLength === undefined) {
  1167. maxLength = Infinity;
  1168. }
  1169. var content = this.posContent();
  1170. var len = Math.abs(this.length);
  1171. if (!this.tag.isUniversal()) {
  1172. if (this.sub !== null) {
  1173. return "(" + this.sub.length + " elem)";
  1174. }
  1175. return this.stream.parseOctetString(content, content + len, maxLength);
  1176. }
  1177. switch (this.tag.tagNumber) {
  1178. case 0x01: // BOOLEAN
  1179. return (this.stream.get(content) === 0) ? "false" : "true";
  1180. case 0x02: // INTEGER
  1181. return this.stream.parseInteger(content, content + len);
  1182. case 0x03: // BIT_STRING
  1183. return this.sub ? "(" + this.sub.length + " elem)" :
  1184. this.stream.parseBitString(content, content + len, maxLength);
  1185. case 0x04: // OCTET_STRING
  1186. return this.sub ? "(" + this.sub.length + " elem)" :
  1187. this.stream.parseOctetString(content, content + len, maxLength);
  1188. // case 0x05: // NULL
  1189. case 0x06: // OBJECT_IDENTIFIER
  1190. return this.stream.parseOID(content, content + len, maxLength);
  1191. // case 0x07: // ObjectDescriptor
  1192. // case 0x08: // EXTERNAL
  1193. // case 0x09: // REAL
  1194. // case 0x0A: // ENUMERATED
  1195. // case 0x0B: // EMBEDDED_PDV
  1196. case 0x10: // SEQUENCE
  1197. case 0x11: // SET
  1198. if (this.sub !== null) {
  1199. return "(" + this.sub.length + " elem)";
  1200. }
  1201. else {
  1202. return "(no elem)";
  1203. }
  1204. case 0x0C: // UTF8String
  1205. return stringCut(this.stream.parseStringUTF(content, content + len), maxLength);
  1206. case 0x12: // NumericString
  1207. case 0x13: // PrintableString
  1208. case 0x14: // TeletexString
  1209. case 0x15: // VideotexString
  1210. case 0x16: // IA5String
  1211. // case 0x19: // GraphicString
  1212. case 0x1A: // VisibleString
  1213. // case 0x1B: // GeneralString
  1214. // case 0x1C: // UniversalString
  1215. return stringCut(this.stream.parseStringISO(content, content + len), maxLength);
  1216. case 0x1E: // BMPString
  1217. return stringCut(this.stream.parseStringBMP(content, content + len), maxLength);
  1218. case 0x17: // UTCTime
  1219. case 0x18: // GeneralizedTime
  1220. return this.stream.parseTime(content, content + len, (this.tag.tagNumber == 0x17));
  1221. }
  1222. return null;
  1223. };
  1224. ASN1.prototype.toString = function () {
  1225. return this.typeName() + "@" + this.stream.pos + "[header:" + this.header + ",length:" + this.length + ",sub:" + ((this.sub === null) ? "null" : this.sub.length) + "]";
  1226. };
  1227. ASN1.prototype.toPrettyString = function (indent) {
  1228. if (indent === undefined) {
  1229. indent = "";
  1230. }
  1231. var s = indent + this.typeName() + " @" + this.stream.pos;
  1232. if (this.length >= 0) {
  1233. s += "+";
  1234. }
  1235. s += this.length;
  1236. if (this.tag.tagConstructed) {
  1237. s += " (constructed)";
  1238. }
  1239. else if ((this.tag.isUniversal() && ((this.tag.tagNumber == 0x03) || (this.tag.tagNumber == 0x04))) && (this.sub !== null)) {
  1240. s += " (encapsulates)";
  1241. }
  1242. s += "\n";
  1243. if (this.sub !== null) {
  1244. indent += " ";
  1245. for (var i = 0, max = this.sub.length; i < max; ++i) {
  1246. s += this.sub[i].toPrettyString(indent);
  1247. }
  1248. }
  1249. return s;
  1250. };
  1251. ASN1.prototype.posStart = function () {
  1252. return this.stream.pos;
  1253. };
  1254. ASN1.prototype.posContent = function () {
  1255. return this.stream.pos + this.header;
  1256. };
  1257. ASN1.prototype.posEnd = function () {
  1258. return this.stream.pos + this.header + Math.abs(this.length);
  1259. };
  1260. ASN1.prototype.toHexString = function () {
  1261. return this.stream.hexDump(this.posStart(), this.posEnd(), true);
  1262. };
  1263. ASN1.decodeLength = function (stream) {
  1264. var buf = stream.get();
  1265. var len = buf & 0x7F;
  1266. if (len == buf) {
  1267. return len;
  1268. }
  1269. // no reason to use Int10, as it would be a huge buffer anyways
  1270. if (len > 6) {
  1271. throw new Error("Length over 48 bits not supported at position " + (stream.pos - 1));
  1272. }
  1273. if (len === 0) {
  1274. return null;
  1275. } // undefined
  1276. buf = 0;
  1277. for (var i = 0; i < len; ++i) {
  1278. buf = (buf * 256) + stream.get();
  1279. }
  1280. return buf;
  1281. };
  1282. /**
  1283. * Retrieve the hexadecimal value (as a string) of the current ASN.1 element
  1284. * @returns {string}
  1285. * @public
  1286. */
  1287. ASN1.prototype.getHexStringValue = function () {
  1288. var hexString = this.toHexString();
  1289. var offset = this.header * 2;
  1290. var length = this.length * 2;
  1291. return hexString.substr(offset, length);
  1292. };
  1293. ASN1.decode = function (str) {
  1294. var stream;
  1295. if (!(str instanceof Stream)) {
  1296. stream = new Stream(str, 0);
  1297. }
  1298. else {
  1299. stream = str;
  1300. }
  1301. var streamStart = new Stream(stream);
  1302. var tag = new ASN1Tag(stream);
  1303. var len = ASN1.decodeLength(stream);
  1304. var start = stream.pos;
  1305. var header = start - streamStart.pos;
  1306. var sub = null;
  1307. var getSub = function () {
  1308. var ret = [];
  1309. if (len !== null) {
  1310. // definite length
  1311. var end = start + len;
  1312. while (stream.pos < end) {
  1313. ret[ret.length] = ASN1.decode(stream);
  1314. }
  1315. if (stream.pos != end) {
  1316. throw new Error("Content size is not correct for container starting at offset " + start);
  1317. }
  1318. }
  1319. else {
  1320. // undefined length
  1321. try {
  1322. for (;;) {
  1323. var s = ASN1.decode(stream);
  1324. if (s.tag.isEOC()) {
  1325. break;
  1326. }
  1327. ret[ret.length] = s;
  1328. }
  1329. len = start - stream.pos; // undefined lengths are represented as negative values
  1330. }
  1331. catch (e) {
  1332. throw new Error("Exception while decoding undefined length content: " + e);
  1333. }
  1334. }
  1335. return ret;
  1336. };
  1337. if (tag.tagConstructed) {
  1338. // must have valid content
  1339. sub = getSub();
  1340. }
  1341. else if (tag.isUniversal() && ((tag.tagNumber == 0x03) || (tag.tagNumber == 0x04))) {
  1342. // sometimes BitString and OctetString are used to encapsulate ASN.1
  1343. try {
  1344. if (tag.tagNumber == 0x03) {
  1345. if (stream.get() != 0) {
  1346. throw new Error("BIT STRINGs with unused bits cannot encapsulate.");
  1347. }
  1348. }
  1349. sub = getSub();
  1350. for (var i = 0; i < sub.length; ++i) {
  1351. if (sub[i].tag.isEOC()) {
  1352. throw new Error("EOC is not supposed to be actual content.");
  1353. }
  1354. }
  1355. }
  1356. catch (e) {
  1357. // but silently ignore when they don't
  1358. sub = null;
  1359. }
  1360. }
  1361. if (sub === null) {
  1362. if (len === null) {
  1363. throw new Error("We can't skip over an invalid tag with undefined length at offset " + start);
  1364. }
  1365. stream.pos = start + Math.abs(len);
  1366. }
  1367. return new ASN1(streamStart, header, len, tag, sub);
  1368. };
  1369. return ASN1;
  1370. }());
  1371. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, 'ASN1', { enumerable: true, configurable: true, get: function() { return ASN1; } });
  1372. var ASN1Tag = /** @class */ (function () {
  1373. function ASN1Tag(stream) {
  1374. var buf = stream.get();
  1375. this.tagClass = buf >> 6;
  1376. this.tagConstructed = ((buf & 0x20) !== 0);
  1377. this.tagNumber = buf & 0x1F;
  1378. if (this.tagNumber == 0x1F) { // long tag
  1379. var n = new Int10();
  1380. do {
  1381. buf = stream.get();
  1382. n.mulAdd(128, buf & 0x7F);
  1383. } while (buf & 0x80);
  1384. this.tagNumber = n.simplify();
  1385. }
  1386. }
  1387. ASN1Tag.prototype.isUniversal = function () {
  1388. return this.tagClass === 0x00;
  1389. };
  1390. ASN1Tag.prototype.isEOC = function () {
  1391. return this.tagClass === 0x00 && this.tagNumber === 0x00;
  1392. };
  1393. return ASN1Tag;
  1394. }());
  1395. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, 'ASN1Tag', { enumerable: true, configurable: true, get: function() { return ASN1Tag; } });
  1396. }, function(modId) { var map = {"./int10":1709513243602}; return __REQUIRE__(map[modId], modId); })
  1397. __DEFINE__(1709513243602, function(require, module, exports) {
  1398. // Big integer base-10 printing library
  1399. // Copyright (c) 2014 Lapo Luchini <lapo@lapo.it>
  1400. // Permission to use, copy, modify, and/or distribute this software for any
  1401. // purpose with or without fee is hereby granted, provided that the above
  1402. // copyright notice and this permission notice appear in all copies.
  1403. //
  1404. // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  1405. // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  1406. // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  1407. // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1408. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1409. // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  1410. // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1411. /*jshint browser: true, strict: true, immed: true, latedef: true, undef: true, regexdash: false */
  1412. var max = 10000000000000; // biggest integer that can still fit 2^53 when multiplied by 256
  1413. var Int10 = /** @class */ (function () {
  1414. function Int10(value) {
  1415. this.buf = [+value || 0];
  1416. }
  1417. Int10.prototype.mulAdd = function (m, c) {
  1418. // assert(m <= 256)
  1419. var b = this.buf;
  1420. var l = b.length;
  1421. var i;
  1422. var t;
  1423. for (i = 0; i < l; ++i) {
  1424. t = b[i] * m + c;
  1425. if (t < max) {
  1426. c = 0;
  1427. }
  1428. else {
  1429. c = 0 | (t / max);
  1430. t -= c * max;
  1431. }
  1432. b[i] = t;
  1433. }
  1434. if (c > 0) {
  1435. b[i] = c;
  1436. }
  1437. };
  1438. Int10.prototype.sub = function (c) {
  1439. // assert(m <= 256)
  1440. var b = this.buf;
  1441. var l = b.length;
  1442. var i;
  1443. var t;
  1444. for (i = 0; i < l; ++i) {
  1445. t = b[i] - c;
  1446. if (t < 0) {
  1447. t += max;
  1448. c = 1;
  1449. }
  1450. else {
  1451. c = 0;
  1452. }
  1453. b[i] = t;
  1454. }
  1455. while (b[b.length - 1] === 0) {
  1456. b.pop();
  1457. }
  1458. };
  1459. Int10.prototype.toString = function (base) {
  1460. if ((base || 10) != 10) {
  1461. throw new Error("only base 10 is supported");
  1462. }
  1463. var b = this.buf;
  1464. var s = b[b.length - 1].toString();
  1465. for (var i = b.length - 2; i >= 0; --i) {
  1466. s += (max + b[i]).toString().substring(1);
  1467. }
  1468. return s;
  1469. };
  1470. Int10.prototype.valueOf = function () {
  1471. var b = this.buf;
  1472. var v = 0;
  1473. for (var i = b.length - 1; i >= 0; --i) {
  1474. v = v * max + b[i];
  1475. }
  1476. return v;
  1477. };
  1478. Int10.prototype.simplify = function () {
  1479. var b = this.buf;
  1480. return (b.length == 1) ? b[0] : this;
  1481. };
  1482. return Int10;
  1483. }());
  1484. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, 'Int10', { enumerable: true, configurable: true, get: function() { return Int10; } });
  1485. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  1486. __DEFINE__(1709513243603, function(require, module, exports) {
  1487. // Depends on jsbn.js and rng.js
  1488. // Version 1.1: support utf-8 encoding in pkcs1pad2
  1489. // convert a (hex) string to a bignum object
  1490. var __TEMP__ = require('./jsbn');var BigInteger = __TEMP__['BigInteger'];var nbi = __TEMP__['nbi'];var parseBigInt = __TEMP__['parseBigInt'];
  1491. var __TEMP__ = require('./rng');var SecureRandom = __TEMP__['SecureRandom'];
  1492. // function linebrk(s,n) {
  1493. // var ret = "";
  1494. // var i = 0;
  1495. // while(i + n < s.length) {
  1496. // ret += s.substring(i,i+n) + "\n";
  1497. // i += n;
  1498. // }
  1499. // return ret + s.substring(i,s.length);
  1500. // }
  1501. // function byte2Hex(b) {
  1502. // if(b < 0x10)
  1503. // return "0" + b.toString(16);
  1504. // else
  1505. // return b.toString(16);
  1506. // }
  1507. function pkcs1pad1(s, n) {
  1508. if (n < s.length + 22) {
  1509. console.error("Message too long for RSA");
  1510. return null;
  1511. }
  1512. var len = n - s.length - 6;
  1513. var filler = "";
  1514. for (var f = 0; f < len; f += 2) {
  1515. filler += "ff";
  1516. }
  1517. var m = "0001" + filler + "00" + s;
  1518. return parseBigInt(m, 16);
  1519. }
  1520. // PKCS#1 (type 2, random) pad input string s to n bytes, and return a bigint
  1521. function pkcs1pad2(s, n) {
  1522. if (n < s.length + 11) { // TODO: fix for utf-8
  1523. console.error("Message too long for RSA");
  1524. return null;
  1525. }
  1526. var ba = [];
  1527. var i = s.length - 1;
  1528. while (i >= 0 && n > 0) {
  1529. var c = s.charCodeAt(i--);
  1530. if (c < 128) { // encode using utf-8
  1531. ba[--n] = c;
  1532. }
  1533. else if ((c > 127) && (c < 2048)) {
  1534. ba[--n] = (c & 63) | 128;
  1535. ba[--n] = (c >> 6) | 192;
  1536. }
  1537. else {
  1538. ba[--n] = (c & 63) | 128;
  1539. ba[--n] = ((c >> 6) & 63) | 128;
  1540. ba[--n] = (c >> 12) | 224;
  1541. }
  1542. }
  1543. ba[--n] = 0;
  1544. var rng = new SecureRandom();
  1545. var x = [];
  1546. while (n > 2) { // random non-zero pad
  1547. x[0] = 0;
  1548. while (x[0] == 0) {
  1549. rng.nextBytes(x);
  1550. }
  1551. ba[--n] = x[0];
  1552. }
  1553. ba[--n] = 2;
  1554. ba[--n] = 0;
  1555. return new BigInteger(ba);
  1556. }
  1557. // "empty" RSA key constructor
  1558. var RSAKey = /** @class */ (function () {
  1559. function RSAKey() {
  1560. this.n = null;
  1561. this.e = 0;
  1562. this.d = null;
  1563. this.p = null;
  1564. this.q = null;
  1565. this.dmp1 = null;
  1566. this.dmq1 = null;
  1567. this.coeff = null;
  1568. }
  1569. //#region PROTECTED
  1570. // protected
  1571. // RSAKey.prototype.doPublic = RSADoPublic;
  1572. // Perform raw public operation on "x": return x^e (mod n)
  1573. RSAKey.prototype.doPublic = function (x) {
  1574. return x.modPowInt(this.e, this.n);
  1575. };
  1576. // RSAKey.prototype.doPrivate = RSADoPrivate;
  1577. // Perform raw private operation on "x": return x^d (mod n)
  1578. RSAKey.prototype.doPrivate = function (x) {
  1579. if (this.p == null || this.q == null) {
  1580. return x.modPow(this.d, this.n);
  1581. }
  1582. // TODO: re-calculate any missing CRT params
  1583. var xp = x.mod(this.p).modPow(this.dmp1, this.p);
  1584. var xq = x.mod(this.q).modPow(this.dmq1, this.q);
  1585. while (xp.compareTo(xq) < 0) {
  1586. xp = xp.add(this.p);
  1587. }
  1588. return xp.subtract(xq).multiply(this.coeff).mod(this.p).multiply(this.q).add(xq);
  1589. };
  1590. //#endregion PROTECTED
  1591. //#region PUBLIC
  1592. // RSAKey.prototype.setPublic = RSASetPublic;
  1593. // Set the public key fields N and e from hex strings
  1594. RSAKey.prototype.setPublic = function (N, E) {
  1595. if (N != null && E != null && N.length > 0 && E.length > 0) {
  1596. this.n = parseBigInt(N, 16);
  1597. this.e = parseInt(E, 16);
  1598. }
  1599. else {
  1600. console.error("Invalid RSA public key");
  1601. }
  1602. };
  1603. // RSAKey.prototype.encrypt = RSAEncrypt;
  1604. // Return the PKCS#1 RSA encryption of "text" as an even-length hex string
  1605. RSAKey.prototype.encrypt = function (text) {
  1606. var maxLength = (this.n.bitLength() + 7) >> 3;
  1607. var m = pkcs1pad2(text, maxLength);
  1608. if (m == null) {
  1609. return null;
  1610. }
  1611. var c = this.doPublic(m);
  1612. if (c == null) {
  1613. return null;
  1614. }
  1615. var h = c.toString(16);
  1616. var length = h.length;
  1617. // fix zero before result
  1618. for (var i = 0; i < maxLength * 2 - length; i++) {
  1619. h = "0" + h;
  1620. }
  1621. return h;
  1622. };
  1623. // RSAKey.prototype.setPrivate = RSASetPrivate;
  1624. // Set the private key fields N, e, and d from hex strings
  1625. RSAKey.prototype.setPrivate = function (N, E, D) {
  1626. if (N != null && E != null && N.length > 0 && E.length > 0) {
  1627. this.n = parseBigInt(N, 16);
  1628. this.e = parseInt(E, 16);
  1629. this.d = parseBigInt(D, 16);
  1630. }
  1631. else {
  1632. console.error("Invalid RSA private key");
  1633. }
  1634. };
  1635. // RSAKey.prototype.setPrivateEx = RSASetPrivateEx;
  1636. // Set the private key fields N, e, d and CRT params from hex strings
  1637. RSAKey.prototype.setPrivateEx = function (N, E, D, P, Q, DP, DQ, C) {
  1638. if (N != null && E != null && N.length > 0 && E.length > 0) {
  1639. this.n = parseBigInt(N, 16);
  1640. this.e = parseInt(E, 16);
  1641. this.d = parseBigInt(D, 16);
  1642. this.p = parseBigInt(P, 16);
  1643. this.q = parseBigInt(Q, 16);
  1644. this.dmp1 = parseBigInt(DP, 16);
  1645. this.dmq1 = parseBigInt(DQ, 16);
  1646. this.coeff = parseBigInt(C, 16);
  1647. }
  1648. else {
  1649. console.error("Invalid RSA private key");
  1650. }
  1651. };
  1652. // RSAKey.prototype.generate = RSAGenerate;
  1653. // Generate a new random private key B bits long, using public expt E
  1654. RSAKey.prototype.generate = function (B, E) {
  1655. var rng = new SecureRandom();
  1656. var qs = B >> 1;
  1657. this.e = parseInt(E, 16);
  1658. var ee = new BigInteger(E, 16);
  1659. for (;;) {
  1660. for (;;) {
  1661. this.p = new BigInteger(B - qs, 1, rng);
  1662. if (this.p.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) == 0 && this.p.isProbablePrime(10)) {
  1663. break;
  1664. }
  1665. }
  1666. for (;;) {
  1667. this.q = new BigInteger(qs, 1, rng);
  1668. if (this.q.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) == 0 && this.q.isProbablePrime(10)) {
  1669. break;
  1670. }
  1671. }
  1672. if (this.p.compareTo(this.q) <= 0) {
  1673. var t = this.p;
  1674. this.p = this.q;
  1675. this.q = t;
  1676. }
  1677. var p1 = this.p.subtract(BigInteger.ONE);
  1678. var q1 = this.q.subtract(BigInteger.ONE);
  1679. var phi = p1.multiply(q1);
  1680. if (phi.gcd(ee).compareTo(BigInteger.ONE) == 0) {
  1681. this.n = this.p.multiply(this.q);
  1682. this.d = ee.modInverse(phi);
  1683. this.dmp1 = this.d.mod(p1);
  1684. this.dmq1 = this.d.mod(q1);
  1685. this.coeff = this.q.modInverse(this.p);
  1686. break;
  1687. }
  1688. }
  1689. };
  1690. // RSAKey.prototype.decrypt = RSADecrypt;
  1691. // Return the PKCS#1 RSA decryption of "ctext".
  1692. // "ctext" is an even-length hex string and the output is a plain string.
  1693. RSAKey.prototype.decrypt = function (ctext) {
  1694. var c = parseBigInt(ctext, 16);
  1695. var m = this.doPrivate(c);
  1696. if (m == null) {
  1697. return null;
  1698. }
  1699. return pkcs1unpad2(m, (this.n.bitLength() + 7) >> 3);
  1700. };
  1701. // Generate a new random private key B bits long, using public expt E
  1702. RSAKey.prototype.generateAsync = function (B, E, callback) {
  1703. var rng = new SecureRandom();
  1704. var qs = B >> 1;
  1705. this.e = parseInt(E, 16);
  1706. var ee = new BigInteger(E, 16);
  1707. var rsa = this;
  1708. // These functions have non-descript names because they were originally for(;;) loops.
  1709. // I don't know about cryptography to give them better names than loop1-4.
  1710. var loop1 = function () {
  1711. var loop4 = function () {
  1712. if (rsa.p.compareTo(rsa.q) <= 0) {
  1713. var t = rsa.p;
  1714. rsa.p = rsa.q;
  1715. rsa.q = t;
  1716. }
  1717. var p1 = rsa.p.subtract(BigInteger.ONE);
  1718. var q1 = rsa.q.subtract(BigInteger.ONE);
  1719. var phi = p1.multiply(q1);
  1720. if (phi.gcd(ee).compareTo(BigInteger.ONE) == 0) {
  1721. rsa.n = rsa.p.multiply(rsa.q);
  1722. rsa.d = ee.modInverse(phi);
  1723. rsa.dmp1 = rsa.d.mod(p1);
  1724. rsa.dmq1 = rsa.d.mod(q1);
  1725. rsa.coeff = rsa.q.modInverse(rsa.p);
  1726. setTimeout(function () { callback(); }, 0); // escape
  1727. }
  1728. else {
  1729. setTimeout(loop1, 0);
  1730. }
  1731. };
  1732. var loop3 = function () {
  1733. rsa.q = nbi();
  1734. rsa.q.fromNumberAsync(qs, 1, rng, function () {
  1735. rsa.q.subtract(BigInteger.ONE).gcda(ee, function (r) {
  1736. if (r.compareTo(BigInteger.ONE) == 0 && rsa.q.isProbablePrime(10)) {
  1737. setTimeout(loop4, 0);
  1738. }
  1739. else {
  1740. setTimeout(loop3, 0);
  1741. }
  1742. });
  1743. });
  1744. };
  1745. var loop2 = function () {
  1746. rsa.p = nbi();
  1747. rsa.p.fromNumberAsync(B - qs, 1, rng, function () {
  1748. rsa.p.subtract(BigInteger.ONE).gcda(ee, function (r) {
  1749. if (r.compareTo(BigInteger.ONE) == 0 && rsa.p.isProbablePrime(10)) {
  1750. setTimeout(loop3, 0);
  1751. }
  1752. else {
  1753. setTimeout(loop2, 0);
  1754. }
  1755. });
  1756. });
  1757. };
  1758. setTimeout(loop2, 0);
  1759. };
  1760. setTimeout(loop1, 0);
  1761. };
  1762. RSAKey.prototype.sign = function (text, digestMethod, digestName) {
  1763. var header = getDigestHeader(digestName);
  1764. var digest = header + digestMethod(text).toString();
  1765. var m = pkcs1pad1(digest, this.n.bitLength() / 4);
  1766. if (m == null) {
  1767. return null;
  1768. }
  1769. var c = this.doPrivate(m);
  1770. if (c == null) {
  1771. return null;
  1772. }
  1773. var h = c.toString(16);
  1774. if ((h.length & 1) == 0) {
  1775. return h;
  1776. }
  1777. else {
  1778. return "0" + h;
  1779. }
  1780. };
  1781. RSAKey.prototype.verify = function (text, signature, digestMethod) {
  1782. var c = parseBigInt(signature, 16);
  1783. var m = this.doPublic(c);
  1784. if (m == null) {
  1785. return null;
  1786. }
  1787. var unpadded = m.toString(16).replace(/^1f+00/, "");
  1788. var digest = removeDigestHeader(unpadded);
  1789. return digest == digestMethod(text).toString();
  1790. };
  1791. RSAKey.prototype.encryptLong = function (text) {
  1792. var _this = this;
  1793. var res = '';
  1794. var maxLen = ((this.n.bitLength() + 7) >> 3) - 11;
  1795. var textArr = this.setSplitChn(text, maxLen);
  1796. textArr.forEach(function (v) {
  1797. res += _this.encrypt(v);
  1798. });
  1799. return res;
  1800. };
  1801. RSAKey.prototype.decryptLong = function (ctext) {
  1802. var res = '';
  1803. var maxLen = (this.n.bitLength() + 7) >> 3;
  1804. var splitMaxLen = maxLen * 2;
  1805. if (ctext.length > splitMaxLen) {
  1806. var ctextArr = ctext.match(new RegExp('.{1,' + splitMaxLen + '}', 'g')) || [];
  1807. var mArr = [];
  1808. for (var i = 0; i < ctextArr.length; i++) {
  1809. var c = parseBigInt(ctextArr[i], 16);
  1810. var m = this.doPrivate(c);
  1811. if (m == null) {
  1812. return null;
  1813. }
  1814. mArr.push(m);
  1815. }
  1816. res = pkcs1unpad2Long(mArr, maxLen);
  1817. }
  1818. else {
  1819. res = this.decrypt(ctext);
  1820. }
  1821. return res;
  1822. };
  1823. RSAKey.prototype.setSplitChn = function (str, maxLen, res) {
  1824. if (res === void 0) { res = []; }
  1825. var arr = str.split('');
  1826. var len = 0;
  1827. for (var i = 0; i < arr.length; i++) {
  1828. var charCode = arr[i].charCodeAt(0);
  1829. if (charCode <= 0x007f) {
  1830. len += 1;
  1831. }
  1832. else if (charCode <= 0x07ff) {
  1833. len += 2;
  1834. }
  1835. else if (charCode <= 0xffff) {
  1836. len += 3;
  1837. }
  1838. else {
  1839. len += 4;
  1840. }
  1841. if (len > maxLen) {
  1842. var currentStr = str.substring(0, i);
  1843. res.push(currentStr);
  1844. return this.setSplitChn(str.substring(i), maxLen, res);
  1845. }
  1846. }
  1847. res.push(str);
  1848. return res;
  1849. };
  1850. return RSAKey;
  1851. }());
  1852. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, 'RSAKey', { enumerable: true, configurable: true, get: function() { return RSAKey; } });
  1853. // Undo PKCS#1 (type 2, random) padding and, if valid, return the plaintext
  1854. function pkcs1unpad2(d, n) {
  1855. var b = d.toByteArray();
  1856. var i = 0;
  1857. while (i < b.length && b[i] == 0) {
  1858. ++i;
  1859. }
  1860. if (b.length - i != n - 1 || b[i] != 2) {
  1861. return null;
  1862. }
  1863. ++i;
  1864. while (b[i] != 0) {
  1865. if (++i >= b.length) {
  1866. return null;
  1867. }
  1868. }
  1869. var ret = "";
  1870. while (++i < b.length) {
  1871. var c = b[i] & 255;
  1872. if (c < 128) { // utf-8 decode
  1873. ret += String.fromCharCode(c);
  1874. }
  1875. else if ((c > 191) && (c < 224)) {
  1876. ret += String.fromCharCode(((c & 31) << 6) | (b[i + 1] & 63));
  1877. ++i;
  1878. }
  1879. else {
  1880. ret += String.fromCharCode(((c & 15) << 12) | ((b[i + 1] & 63) << 6) | (b[i + 2] & 63));
  1881. i += 2;
  1882. }
  1883. }
  1884. return ret;
  1885. }
  1886. function pkcs1unpad2Long(dArr, n) {
  1887. var bArr = [];
  1888. for (var j = 0; j < dArr.length; j++) {
  1889. var d = dArr[j];
  1890. var b_1 = d.toByteArray();
  1891. var i_1 = 0;
  1892. while (i_1 < b_1.length && b_1[i_1] == 0) {
  1893. ++i_1;
  1894. }
  1895. if (b_1.length - i_1 != n - 1 || b_1[i_1] != 2) {
  1896. return null;
  1897. }
  1898. ++i_1;
  1899. while (b_1[i_1] != 0) {
  1900. if (++i_1 >= b_1.length) {
  1901. return null;
  1902. }
  1903. }
  1904. bArr = bArr.concat(b_1.slice(i_1 + 1));
  1905. }
  1906. var b = bArr;
  1907. var i = -1;
  1908. var ret = "";
  1909. while (++i < b.length) {
  1910. var c = b[i] & 255;
  1911. if (c < 128) { // utf-8 decode
  1912. ret += String.fromCharCode(c);
  1913. }
  1914. else if ((c > 191) && (c < 224)) {
  1915. ret += String.fromCharCode(((c & 31) << 6) | (b[i + 1] & 63));
  1916. ++i;
  1917. }
  1918. else {
  1919. ret += String.fromCharCode(((c & 15) << 12) | ((b[i + 1] & 63) << 6) | (b[i + 2] & 63));
  1920. i += 2;
  1921. }
  1922. }
  1923. return ret;
  1924. }
  1925. // https://tools.ietf.org/html/rfc3447#page-43
  1926. var DIGEST_HEADERS = {
  1927. md2: "3020300c06082a864886f70d020205000410",
  1928. md5: "3020300c06082a864886f70d020505000410",
  1929. sha1: "3021300906052b0e03021a05000414",
  1930. sha224: "302d300d06096086480165030402040500041c",
  1931. sha256: "3031300d060960864801650304020105000420",
  1932. sha384: "3041300d060960864801650304020205000430",
  1933. sha512: "3051300d060960864801650304020305000440",
  1934. ripemd160: "3021300906052b2403020105000414"
  1935. };
  1936. function getDigestHeader(name) {
  1937. return DIGEST_HEADERS[name] || "";
  1938. }
  1939. function removeDigestHeader(str) {
  1940. for (var name_1 in DIGEST_HEADERS) {
  1941. if (DIGEST_HEADERS.hasOwnProperty(name_1)) {
  1942. var header = DIGEST_HEADERS[name_1];
  1943. var len = header.length;
  1944. if (str.substr(0, len) == header) {
  1945. return str.substr(len);
  1946. }
  1947. }
  1948. }
  1949. return str;
  1950. }
  1951. // Return the PKCS#1 RSA encryption of "text" as a Base64-encoded string
  1952. // function RSAEncryptB64(text) {
  1953. // var h = this.encrypt(text);
  1954. // if(h) return hex2b64(h); else return null;
  1955. // }
  1956. // public
  1957. // RSAKey.prototype.encrypt_b64 = RSAEncryptB64;
  1958. }, function(modId) { var map = {"./jsbn":1709513243604,"./rng":1709513243605}; return __REQUIRE__(map[modId], modId); })
  1959. __DEFINE__(1709513243604, function(require, module, exports) {
  1960. // Copyright (c) 2005 Tom Wu
  1961. // All Rights Reserved.
  1962. // See "LICENSE" for details.
  1963. // Basic JavaScript BN library - subset useful for RSA encryption.
  1964. var __TEMP__ = require('./util');var cbit = __TEMP__['cbit'];var int2char = __TEMP__['int2char'];var lbit = __TEMP__['lbit'];var op_and = __TEMP__['op_and'];var op_andnot = __TEMP__['op_andnot'];var op_or = __TEMP__['op_or'];var op_xor = __TEMP__['op_xor'];
  1965. // Bits per digit
  1966. var dbits;
  1967. // JavaScript engine analysis
  1968. var canary = 0xdeadbeefcafe;
  1969. var j_lm = ((canary & 0xffffff) == 0xefcafe);
  1970. //#region
  1971. var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997];
  1972. var lplim = (1 << 26) / lowprimes[lowprimes.length - 1];
  1973. //#endregion
  1974. // (public) Constructor
  1975. var BigInteger = /** @class */ (function () {
  1976. function BigInteger(a, b, c) {
  1977. if (a != null) {
  1978. if ("number" == typeof a) {
  1979. this.fromNumber(a, b, c);
  1980. }
  1981. else if (b == null && "string" != typeof a) {
  1982. this.fromString(a, 256);
  1983. }
  1984. else {
  1985. this.fromString(a, b);
  1986. }
  1987. }
  1988. }
  1989. //#region PUBLIC
  1990. // BigInteger.prototype.toString = bnToString;
  1991. // (public) return string representation in given radix
  1992. BigInteger.prototype.toString = function (b) {
  1993. if (this.s < 0) {
  1994. return "-" + this.negate().toString(b);
  1995. }
  1996. var k;
  1997. if (b == 16) {
  1998. k = 4;
  1999. }
  2000. else if (b == 8) {
  2001. k = 3;
  2002. }
  2003. else if (b == 2) {
  2004. k = 1;
  2005. }
  2006. else if (b == 32) {
  2007. k = 5;
  2008. }
  2009. else if (b == 4) {
  2010. k = 2;
  2011. }
  2012. else {
  2013. return this.toRadix(b);
  2014. }
  2015. var km = (1 << k) - 1;
  2016. var d;
  2017. var m = false;
  2018. var r = "";
  2019. var i = this.t;
  2020. var p = this.DB - (i * this.DB) % k;
  2021. if (i-- > 0) {
  2022. if (p < this.DB && (d = this[i] >> p) > 0) {
  2023. m = true;
  2024. r = int2char(d);
  2025. }
  2026. while (i >= 0) {
  2027. if (p < k) {
  2028. d = (this[i] & ((1 << p) - 1)) << (k - p);
  2029. d |= this[--i] >> (p += this.DB - k);
  2030. }
  2031. else {
  2032. d = (this[i] >> (p -= k)) & km;
  2033. if (p <= 0) {
  2034. p += this.DB;
  2035. --i;
  2036. }
  2037. }
  2038. if (d > 0) {
  2039. m = true;
  2040. }
  2041. if (m) {
  2042. r += int2char(d);
  2043. }
  2044. }
  2045. }
  2046. return m ? r : "0";
  2047. };
  2048. // BigInteger.prototype.negate = bnNegate;
  2049. // (public) -this
  2050. BigInteger.prototype.negate = function () {
  2051. var r = nbi();
  2052. BigInteger.ZERO.subTo(this, r);
  2053. return r;
  2054. };
  2055. // BigInteger.prototype.abs = bnAbs;
  2056. // (public) |this|
  2057. BigInteger.prototype.abs = function () {
  2058. return (this.s < 0) ? this.negate() : this;
  2059. };
  2060. // BigInteger.prototype.compareTo = bnCompareTo;
  2061. // (public) return + if this > a, - if this < a, 0 if equal
  2062. BigInteger.prototype.compareTo = function (a) {
  2063. var r = this.s - a.s;
  2064. if (r != 0) {
  2065. return r;
  2066. }
  2067. var i = this.t;
  2068. r = i - a.t;
  2069. if (r != 0) {
  2070. return (this.s < 0) ? -r : r;
  2071. }
  2072. while (--i >= 0) {
  2073. if ((r = this[i] - a[i]) != 0) {
  2074. return r;
  2075. }
  2076. }
  2077. return 0;
  2078. };
  2079. // BigInteger.prototype.bitLength = bnBitLength;
  2080. // (public) return the number of bits in "this"
  2081. BigInteger.prototype.bitLength = function () {
  2082. if (this.t <= 0) {
  2083. return 0;
  2084. }
  2085. return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM));
  2086. };
  2087. // BigInteger.prototype.mod = bnMod;
  2088. // (public) this mod a
  2089. BigInteger.prototype.mod = function (a) {
  2090. var r = nbi();
  2091. this.abs().divRemTo(a, null, r);
  2092. if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) {
  2093. a.subTo(r, r);
  2094. }
  2095. return r;
  2096. };
  2097. // BigInteger.prototype.modPowInt = bnModPowInt;
  2098. // (public) this^e % m, 0 <= e < 2^32
  2099. BigInteger.prototype.modPowInt = function (e, m) {
  2100. var z;
  2101. if (e < 256 || m.isEven()) {
  2102. z = new Classic(m);
  2103. }
  2104. else {
  2105. z = new Montgomery(m);
  2106. }
  2107. return this.exp(e, z);
  2108. };
  2109. // BigInteger.prototype.clone = bnClone;
  2110. // (public)
  2111. BigInteger.prototype.clone = function () {
  2112. var r = nbi();
  2113. this.copyTo(r);
  2114. return r;
  2115. };
  2116. // BigInteger.prototype.intValue = bnIntValue;
  2117. // (public) return value as integer
  2118. BigInteger.prototype.intValue = function () {
  2119. if (this.s < 0) {
  2120. if (this.t == 1) {
  2121. return this[0] - this.DV;
  2122. }
  2123. else if (this.t == 0) {
  2124. return -1;
  2125. }
  2126. }
  2127. else if (this.t == 1) {
  2128. return this[0];
  2129. }
  2130. else if (this.t == 0) {
  2131. return 0;
  2132. }
  2133. // assumes 16 < DB < 32
  2134. return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0];
  2135. };
  2136. // BigInteger.prototype.byteValue = bnByteValue;
  2137. // (public) return value as byte
  2138. BigInteger.prototype.byteValue = function () {
  2139. return (this.t == 0) ? this.s : (this[0] << 24) >> 24;
  2140. };
  2141. // BigInteger.prototype.shortValue = bnShortValue;
  2142. // (public) return value as short (assumes DB>=16)
  2143. BigInteger.prototype.shortValue = function () {
  2144. return (this.t == 0) ? this.s : (this[0] << 16) >> 16;
  2145. };
  2146. // BigInteger.prototype.signum = bnSigNum;
  2147. // (public) 0 if this == 0, 1 if this > 0
  2148. BigInteger.prototype.signum = function () {
  2149. if (this.s < 0) {
  2150. return -1;
  2151. }
  2152. else if (this.t <= 0 || (this.t == 1 && this[0] <= 0)) {
  2153. return 0;
  2154. }
  2155. else {
  2156. return 1;
  2157. }
  2158. };
  2159. // BigInteger.prototype.toByteArray = bnToByteArray;
  2160. // (public) convert to bigendian byte array
  2161. BigInteger.prototype.toByteArray = function () {
  2162. var i = this.t;
  2163. var r = [];
  2164. r[0] = this.s;
  2165. var p = this.DB - (i * this.DB) % 8;
  2166. var d;
  2167. var k = 0;
  2168. if (i-- > 0) {
  2169. if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p) {
  2170. r[k++] = d | (this.s << (this.DB - p));
  2171. }
  2172. while (i >= 0) {
  2173. if (p < 8) {
  2174. d = (this[i] & ((1 << p) - 1)) << (8 - p);
  2175. d |= this[--i] >> (p += this.DB - 8);
  2176. }
  2177. else {
  2178. d = (this[i] >> (p -= 8)) & 0xff;
  2179. if (p <= 0) {
  2180. p += this.DB;
  2181. --i;
  2182. }
  2183. }
  2184. if ((d & 0x80) != 0) {
  2185. d |= -256;
  2186. }
  2187. if (k == 0 && (this.s & 0x80) != (d & 0x80)) {
  2188. ++k;
  2189. }
  2190. if (k > 0 || d != this.s) {
  2191. r[k++] = d;
  2192. }
  2193. }
  2194. }
  2195. return r;
  2196. };
  2197. // BigInteger.prototype.equals = bnEquals;
  2198. BigInteger.prototype.equals = function (a) {
  2199. return (this.compareTo(a) == 0);
  2200. };
  2201. // BigInteger.prototype.min = bnMin;
  2202. BigInteger.prototype.min = function (a) {
  2203. return (this.compareTo(a) < 0) ? this : a;
  2204. };
  2205. // BigInteger.prototype.max = bnMax;
  2206. BigInteger.prototype.max = function (a) {
  2207. return (this.compareTo(a) > 0) ? this : a;
  2208. };
  2209. // BigInteger.prototype.and = bnAnd;
  2210. BigInteger.prototype.and = function (a) {
  2211. var r = nbi();
  2212. this.bitwiseTo(a, op_and, r);
  2213. return r;
  2214. };
  2215. // BigInteger.prototype.or = bnOr;
  2216. BigInteger.prototype.or = function (a) {
  2217. var r = nbi();
  2218. this.bitwiseTo(a, op_or, r);
  2219. return r;
  2220. };
  2221. // BigInteger.prototype.xor = bnXor;
  2222. BigInteger.prototype.xor = function (a) {
  2223. var r = nbi();
  2224. this.bitwiseTo(a, op_xor, r);
  2225. return r;
  2226. };
  2227. // BigInteger.prototype.andNot = bnAndNot;
  2228. BigInteger.prototype.andNot = function (a) {
  2229. var r = nbi();
  2230. this.bitwiseTo(a, op_andnot, r);
  2231. return r;
  2232. };
  2233. // BigInteger.prototype.not = bnNot;
  2234. // (public) ~this
  2235. BigInteger.prototype.not = function () {
  2236. var r = nbi();
  2237. for (var i = 0; i < this.t; ++i) {
  2238. r[i] = this.DM & ~this[i];
  2239. }
  2240. r.t = this.t;
  2241. r.s = ~this.s;
  2242. return r;
  2243. };
  2244. // BigInteger.prototype.shiftLeft = bnShiftLeft;
  2245. // (public) this << n
  2246. BigInteger.prototype.shiftLeft = function (n) {
  2247. var r = nbi();
  2248. if (n < 0) {
  2249. this.rShiftTo(-n, r);
  2250. }
  2251. else {
  2252. this.lShiftTo(n, r);
  2253. }
  2254. return r;
  2255. };
  2256. // BigInteger.prototype.shiftRight = bnShiftRight;
  2257. // (public) this >> n
  2258. BigInteger.prototype.shiftRight = function (n) {
  2259. var r = nbi();
  2260. if (n < 0) {
  2261. this.lShiftTo(-n, r);
  2262. }
  2263. else {
  2264. this.rShiftTo(n, r);
  2265. }
  2266. return r;
  2267. };
  2268. // BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit;
  2269. // (public) returns index of lowest 1-bit (or -1 if none)
  2270. BigInteger.prototype.getLowestSetBit = function () {
  2271. for (var i = 0; i < this.t; ++i) {
  2272. if (this[i] != 0) {
  2273. return i * this.DB + lbit(this[i]);
  2274. }
  2275. }
  2276. if (this.s < 0) {
  2277. return this.t * this.DB;
  2278. }
  2279. return -1;
  2280. };
  2281. // BigInteger.prototype.bitCount = bnBitCount;
  2282. // (public) return number of set bits
  2283. BigInteger.prototype.bitCount = function () {
  2284. var r = 0;
  2285. var x = this.s & this.DM;
  2286. for (var i = 0; i < this.t; ++i) {
  2287. r += cbit(this[i] ^ x);
  2288. }
  2289. return r;
  2290. };
  2291. // BigInteger.prototype.testBit = bnTestBit;
  2292. // (public) true iff nth bit is set
  2293. BigInteger.prototype.testBit = function (n) {
  2294. var j = Math.floor(n / this.DB);
  2295. if (j >= this.t) {
  2296. return (this.s != 0);
  2297. }
  2298. return ((this[j] & (1 << (n % this.DB))) != 0);
  2299. };
  2300. // BigInteger.prototype.setBit = bnSetBit;
  2301. // (public) this | (1<<n)
  2302. BigInteger.prototype.setBit = function (n) {
  2303. return this.changeBit(n, op_or);
  2304. };
  2305. // BigInteger.prototype.clearBit = bnClearBit;
  2306. // (public) this & ~(1<<n)
  2307. BigInteger.prototype.clearBit = function (n) {
  2308. return this.changeBit(n, op_andnot);
  2309. };
  2310. // BigInteger.prototype.flipBit = bnFlipBit;
  2311. // (public) this ^ (1<<n)
  2312. BigInteger.prototype.flipBit = function (n) {
  2313. return this.changeBit(n, op_xor);
  2314. };
  2315. // BigInteger.prototype.add = bnAdd;
  2316. // (public) this + a
  2317. BigInteger.prototype.add = function (a) {
  2318. var r = nbi();
  2319. this.addTo(a, r);
  2320. return r;
  2321. };
  2322. // BigInteger.prototype.subtract = bnSubtract;
  2323. // (public) this - a
  2324. BigInteger.prototype.subtract = function (a) {
  2325. var r = nbi();
  2326. this.subTo(a, r);
  2327. return r;
  2328. };
  2329. // BigInteger.prototype.multiply = bnMultiply;
  2330. // (public) this * a
  2331. BigInteger.prototype.multiply = function (a) {
  2332. var r = nbi();
  2333. this.multiplyTo(a, r);
  2334. return r;
  2335. };
  2336. // BigInteger.prototype.divide = bnDivide;
  2337. // (public) this / a
  2338. BigInteger.prototype.divide = function (a) {
  2339. var r = nbi();
  2340. this.divRemTo(a, r, null);
  2341. return r;
  2342. };
  2343. // BigInteger.prototype.remainder = bnRemainder;
  2344. // (public) this % a
  2345. BigInteger.prototype.remainder = function (a) {
  2346. var r = nbi();
  2347. this.divRemTo(a, null, r);
  2348. return r;
  2349. };
  2350. // BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder;
  2351. // (public) [this/a,this%a]
  2352. BigInteger.prototype.divideAndRemainder = function (a) {
  2353. var q = nbi();
  2354. var r = nbi();
  2355. this.divRemTo(a, q, r);
  2356. return [q, r];
  2357. };
  2358. // BigInteger.prototype.modPow = bnModPow;
  2359. // (public) this^e % m (HAC 14.85)
  2360. BigInteger.prototype.modPow = function (e, m) {
  2361. var i = e.bitLength();
  2362. var k;
  2363. var r = nbv(1);
  2364. var z;
  2365. if (i <= 0) {
  2366. return r;
  2367. }
  2368. else if (i < 18) {
  2369. k = 1;
  2370. }
  2371. else if (i < 48) {
  2372. k = 3;
  2373. }
  2374. else if (i < 144) {
  2375. k = 4;
  2376. }
  2377. else if (i < 768) {
  2378. k = 5;
  2379. }
  2380. else {
  2381. k = 6;
  2382. }
  2383. if (i < 8) {
  2384. z = new Classic(m);
  2385. }
  2386. else if (m.isEven()) {
  2387. z = new Barrett(m);
  2388. }
  2389. else {
  2390. z = new Montgomery(m);
  2391. }
  2392. // precomputation
  2393. var g = [];
  2394. var n = 3;
  2395. var k1 = k - 1;
  2396. var km = (1 << k) - 1;
  2397. g[1] = z.convert(this);
  2398. if (k > 1) {
  2399. var g2 = nbi();
  2400. z.sqrTo(g[1], g2);
  2401. while (n <= km) {
  2402. g[n] = nbi();
  2403. z.mulTo(g2, g[n - 2], g[n]);
  2404. n += 2;
  2405. }
  2406. }
  2407. var j = e.t - 1;
  2408. var w;
  2409. var is1 = true;
  2410. var r2 = nbi();
  2411. var t;
  2412. i = nbits(e[j]) - 1;
  2413. while (j >= 0) {
  2414. if (i >= k1) {
  2415. w = (e[j] >> (i - k1)) & km;
  2416. }
  2417. else {
  2418. w = (e[j] & ((1 << (i + 1)) - 1)) << (k1 - i);
  2419. if (j > 0) {
  2420. w |= e[j - 1] >> (this.DB + i - k1);
  2421. }
  2422. }
  2423. n = k;
  2424. while ((w & 1) == 0) {
  2425. w >>= 1;
  2426. --n;
  2427. }
  2428. if ((i -= n) < 0) {
  2429. i += this.DB;
  2430. --j;
  2431. }
  2432. if (is1) { // ret == 1, don't bother squaring or multiplying it
  2433. g[w].copyTo(r);
  2434. is1 = false;
  2435. }
  2436. else {
  2437. while (n > 1) {
  2438. z.sqrTo(r, r2);
  2439. z.sqrTo(r2, r);
  2440. n -= 2;
  2441. }
  2442. if (n > 0) {
  2443. z.sqrTo(r, r2);
  2444. }
  2445. else {
  2446. t = r;
  2447. r = r2;
  2448. r2 = t;
  2449. }
  2450. z.mulTo(r2, g[w], r);
  2451. }
  2452. while (j >= 0 && (e[j] & (1 << i)) == 0) {
  2453. z.sqrTo(r, r2);
  2454. t = r;
  2455. r = r2;
  2456. r2 = t;
  2457. if (--i < 0) {
  2458. i = this.DB - 1;
  2459. --j;
  2460. }
  2461. }
  2462. }
  2463. return z.revert(r);
  2464. };
  2465. // BigInteger.prototype.modInverse = bnModInverse;
  2466. // (public) 1/this % m (HAC 14.61)
  2467. BigInteger.prototype.modInverse = function (m) {
  2468. var ac = m.isEven();
  2469. if ((this.isEven() && ac) || m.signum() == 0) {
  2470. return BigInteger.ZERO;
  2471. }
  2472. var u = m.clone();
  2473. var v = this.clone();
  2474. var a = nbv(1);
  2475. var b = nbv(0);
  2476. var c = nbv(0);
  2477. var d = nbv(1);
  2478. while (u.signum() != 0) {
  2479. while (u.isEven()) {
  2480. u.rShiftTo(1, u);
  2481. if (ac) {
  2482. if (!a.isEven() || !b.isEven()) {
  2483. a.addTo(this, a);
  2484. b.subTo(m, b);
  2485. }
  2486. a.rShiftTo(1, a);
  2487. }
  2488. else if (!b.isEven()) {
  2489. b.subTo(m, b);
  2490. }
  2491. b.rShiftTo(1, b);
  2492. }
  2493. while (v.isEven()) {
  2494. v.rShiftTo(1, v);
  2495. if (ac) {
  2496. if (!c.isEven() || !d.isEven()) {
  2497. c.addTo(this, c);
  2498. d.subTo(m, d);
  2499. }
  2500. c.rShiftTo(1, c);
  2501. }
  2502. else if (!d.isEven()) {
  2503. d.subTo(m, d);
  2504. }
  2505. d.rShiftTo(1, d);
  2506. }
  2507. if (u.compareTo(v) >= 0) {
  2508. u.subTo(v, u);
  2509. if (ac) {
  2510. a.subTo(c, a);
  2511. }
  2512. b.subTo(d, b);
  2513. }
  2514. else {
  2515. v.subTo(u, v);
  2516. if (ac) {
  2517. c.subTo(a, c);
  2518. }
  2519. d.subTo(b, d);
  2520. }
  2521. }
  2522. if (v.compareTo(BigInteger.ONE) != 0) {
  2523. return BigInteger.ZERO;
  2524. }
  2525. if (d.compareTo(m) >= 0) {
  2526. return d.subtract(m);
  2527. }
  2528. if (d.signum() < 0) {
  2529. d.addTo(m, d);
  2530. }
  2531. else {
  2532. return d;
  2533. }
  2534. if (d.signum() < 0) {
  2535. return d.add(m);
  2536. }
  2537. else {
  2538. return d;
  2539. }
  2540. };
  2541. // BigInteger.prototype.pow = bnPow;
  2542. // (public) this^e
  2543. BigInteger.prototype.pow = function (e) {
  2544. return this.exp(e, new NullExp());
  2545. };
  2546. // BigInteger.prototype.gcd = bnGCD;
  2547. // (public) gcd(this,a) (HAC 14.54)
  2548. BigInteger.prototype.gcd = function (a) {
  2549. var x = (this.s < 0) ? this.negate() : this.clone();
  2550. var y = (a.s < 0) ? a.negate() : a.clone();
  2551. if (x.compareTo(y) < 0) {
  2552. var t = x;
  2553. x = y;
  2554. y = t;
  2555. }
  2556. var i = x.getLowestSetBit();
  2557. var g = y.getLowestSetBit();
  2558. if (g < 0) {
  2559. return x;
  2560. }
  2561. if (i < g) {
  2562. g = i;
  2563. }
  2564. if (g > 0) {
  2565. x.rShiftTo(g, x);
  2566. y.rShiftTo(g, y);
  2567. }
  2568. while (x.signum() > 0) {
  2569. if ((i = x.getLowestSetBit()) > 0) {
  2570. x.rShiftTo(i, x);
  2571. }
  2572. if ((i = y.getLowestSetBit()) > 0) {
  2573. y.rShiftTo(i, y);
  2574. }
  2575. if (x.compareTo(y) >= 0) {
  2576. x.subTo(y, x);
  2577. x.rShiftTo(1, x);
  2578. }
  2579. else {
  2580. y.subTo(x, y);
  2581. y.rShiftTo(1, y);
  2582. }
  2583. }
  2584. if (g > 0) {
  2585. y.lShiftTo(g, y);
  2586. }
  2587. return y;
  2588. };
  2589. // BigInteger.prototype.isProbablePrime = bnIsProbablePrime;
  2590. // (public) test primality with certainty >= 1-.5^t
  2591. BigInteger.prototype.isProbablePrime = function (t) {
  2592. var i;
  2593. var x = this.abs();
  2594. if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) {
  2595. for (i = 0; i < lowprimes.length; ++i) {
  2596. if (x[0] == lowprimes[i]) {
  2597. return true;
  2598. }
  2599. }
  2600. return false;
  2601. }
  2602. if (x.isEven()) {
  2603. return false;
  2604. }
  2605. i = 1;
  2606. while (i < lowprimes.length) {
  2607. var m = lowprimes[i];
  2608. var j = i + 1;
  2609. while (j < lowprimes.length && m < lplim) {
  2610. m *= lowprimes[j++];
  2611. }
  2612. m = x.modInt(m);
  2613. while (i < j) {
  2614. if (m % lowprimes[i++] == 0) {
  2615. return false;
  2616. }
  2617. }
  2618. }
  2619. return x.millerRabin(t);
  2620. };
  2621. //#endregion PUBLIC
  2622. //#region PROTECTED
  2623. // BigInteger.prototype.copyTo = bnpCopyTo;
  2624. // (protected) copy this to r
  2625. BigInteger.prototype.copyTo = function (r) {
  2626. for (var i = this.t - 1; i >= 0; --i) {
  2627. r[i] = this[i];
  2628. }
  2629. r.t = this.t;
  2630. r.s = this.s;
  2631. };
  2632. // BigInteger.prototype.fromInt = bnpFromInt;
  2633. // (protected) set from integer value x, -DV <= x < DV
  2634. BigInteger.prototype.fromInt = function (x) {
  2635. this.t = 1;
  2636. this.s = (x < 0) ? -1 : 0;
  2637. if (x > 0) {
  2638. this[0] = x;
  2639. }
  2640. else if (x < -1) {
  2641. this[0] = x + this.DV;
  2642. }
  2643. else {
  2644. this.t = 0;
  2645. }
  2646. };
  2647. // BigInteger.prototype.fromString = bnpFromString;
  2648. // (protected) set from string and radix
  2649. BigInteger.prototype.fromString = function (s, b) {
  2650. var k;
  2651. if (b == 16) {
  2652. k = 4;
  2653. }
  2654. else if (b == 8) {
  2655. k = 3;
  2656. }
  2657. else if (b == 256) {
  2658. k = 8;
  2659. /* byte array */
  2660. }
  2661. else if (b == 2) {
  2662. k = 1;
  2663. }
  2664. else if (b == 32) {
  2665. k = 5;
  2666. }
  2667. else if (b == 4) {
  2668. k = 2;
  2669. }
  2670. else {
  2671. this.fromRadix(s, b);
  2672. return;
  2673. }
  2674. this.t = 0;
  2675. this.s = 0;
  2676. var i = s.length;
  2677. var mi = false;
  2678. var sh = 0;
  2679. while (--i >= 0) {
  2680. var x = (k == 8) ? (+s[i]) & 0xff : intAt(s, i);
  2681. if (x < 0) {
  2682. if (s.charAt(i) == "-") {
  2683. mi = true;
  2684. }
  2685. continue;
  2686. }
  2687. mi = false;
  2688. if (sh == 0) {
  2689. this[this.t++] = x;
  2690. }
  2691. else if (sh + k > this.DB) {
  2692. this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh;
  2693. this[this.t++] = (x >> (this.DB - sh));
  2694. }
  2695. else {
  2696. this[this.t - 1] |= x << sh;
  2697. }
  2698. sh += k;
  2699. if (sh >= this.DB) {
  2700. sh -= this.DB;
  2701. }
  2702. }
  2703. if (k == 8 && ((+s[0]) & 0x80) != 0) {
  2704. this.s = -1;
  2705. if (sh > 0) {
  2706. this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh;
  2707. }
  2708. }
  2709. this.clamp();
  2710. if (mi) {
  2711. BigInteger.ZERO.subTo(this, this);
  2712. }
  2713. };
  2714. // BigInteger.prototype.clamp = bnpClamp;
  2715. // (protected) clamp off excess high words
  2716. BigInteger.prototype.clamp = function () {
  2717. var c = this.s & this.DM;
  2718. while (this.t > 0 && this[this.t - 1] == c) {
  2719. --this.t;
  2720. }
  2721. };
  2722. // BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
  2723. // (protected) r = this << n*DB
  2724. BigInteger.prototype.dlShiftTo = function (n, r) {
  2725. var i;
  2726. for (i = this.t - 1; i >= 0; --i) {
  2727. r[i + n] = this[i];
  2728. }
  2729. for (i = n - 1; i >= 0; --i) {
  2730. r[i] = 0;
  2731. }
  2732. r.t = this.t + n;
  2733. r.s = this.s;
  2734. };
  2735. // BigInteger.prototype.drShiftTo = bnpDRShiftTo;
  2736. // (protected) r = this >> n*DB
  2737. BigInteger.prototype.drShiftTo = function (n, r) {
  2738. for (var i = n; i < this.t; ++i) {
  2739. r[i - n] = this[i];
  2740. }
  2741. r.t = Math.max(this.t - n, 0);
  2742. r.s = this.s;
  2743. };
  2744. // BigInteger.prototype.lShiftTo = bnpLShiftTo;
  2745. // (protected) r = this << n
  2746. BigInteger.prototype.lShiftTo = function (n, r) {
  2747. var bs = n % this.DB;
  2748. var cbs = this.DB - bs;
  2749. var bm = (1 << cbs) - 1;
  2750. var ds = Math.floor(n / this.DB);
  2751. var c = (this.s << bs) & this.DM;
  2752. for (var i = this.t - 1; i >= 0; --i) {
  2753. r[i + ds + 1] = (this[i] >> cbs) | c;
  2754. c = (this[i] & bm) << bs;
  2755. }
  2756. for (var i = ds - 1; i >= 0; --i) {
  2757. r[i] = 0;
  2758. }
  2759. r[ds] = c;
  2760. r.t = this.t + ds + 1;
  2761. r.s = this.s;
  2762. r.clamp();
  2763. };
  2764. // BigInteger.prototype.rShiftTo = bnpRShiftTo;
  2765. // (protected) r = this >> n
  2766. BigInteger.prototype.rShiftTo = function (n, r) {
  2767. r.s = this.s;
  2768. var ds = Math.floor(n / this.DB);
  2769. if (ds >= this.t) {
  2770. r.t = 0;
  2771. return;
  2772. }
  2773. var bs = n % this.DB;
  2774. var cbs = this.DB - bs;
  2775. var bm = (1 << bs) - 1;
  2776. r[0] = this[ds] >> bs;
  2777. for (var i = ds + 1; i < this.t; ++i) {
  2778. r[i - ds - 1] |= (this[i] & bm) << cbs;
  2779. r[i - ds] = this[i] >> bs;
  2780. }
  2781. if (bs > 0) {
  2782. r[this.t - ds - 1] |= (this.s & bm) << cbs;
  2783. }
  2784. r.t = this.t - ds;
  2785. r.clamp();
  2786. };
  2787. // BigInteger.prototype.subTo = bnpSubTo;
  2788. // (protected) r = this - a
  2789. BigInteger.prototype.subTo = function (a, r) {
  2790. var i = 0;
  2791. var c = 0;
  2792. var m = Math.min(a.t, this.t);
  2793. while (i < m) {
  2794. c += this[i] - a[i];
  2795. r[i++] = c & this.DM;
  2796. c >>= this.DB;
  2797. }
  2798. if (a.t < this.t) {
  2799. c -= a.s;
  2800. while (i < this.t) {
  2801. c += this[i];
  2802. r[i++] = c & this.DM;
  2803. c >>= this.DB;
  2804. }
  2805. c += this.s;
  2806. }
  2807. else {
  2808. c += this.s;
  2809. while (i < a.t) {
  2810. c -= a[i];
  2811. r[i++] = c & this.DM;
  2812. c >>= this.DB;
  2813. }
  2814. c -= a.s;
  2815. }
  2816. r.s = (c < 0) ? -1 : 0;
  2817. if (c < -1) {
  2818. r[i++] = this.DV + c;
  2819. }
  2820. else if (c > 0) {
  2821. r[i++] = c;
  2822. }
  2823. r.t = i;
  2824. r.clamp();
  2825. };
  2826. // BigInteger.prototype.multiplyTo = bnpMultiplyTo;
  2827. // (protected) r = this * a, r != this,a (HAC 14.12)
  2828. // "this" should be the larger one if appropriate.
  2829. BigInteger.prototype.multiplyTo = function (a, r) {
  2830. var x = this.abs();
  2831. var y = a.abs();
  2832. var i = x.t;
  2833. r.t = i + y.t;
  2834. while (--i >= 0) {
  2835. r[i] = 0;
  2836. }
  2837. for (i = 0; i < y.t; ++i) {
  2838. r[i + x.t] = x.am(0, y[i], r, i, 0, x.t);
  2839. }
  2840. r.s = 0;
  2841. r.clamp();
  2842. if (this.s != a.s) {
  2843. BigInteger.ZERO.subTo(r, r);
  2844. }
  2845. };
  2846. // BigInteger.prototype.squareTo = bnpSquareTo;
  2847. // (protected) r = this^2, r != this (HAC 14.16)
  2848. BigInteger.prototype.squareTo = function (r) {
  2849. var x = this.abs();
  2850. var i = r.t = 2 * x.t;
  2851. while (--i >= 0) {
  2852. r[i] = 0;
  2853. }
  2854. for (i = 0; i < x.t - 1; ++i) {
  2855. var c = x.am(i, x[i], r, 2 * i, 0, 1);
  2856. if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
  2857. r[i + x.t] -= x.DV;
  2858. r[i + x.t + 1] = 1;
  2859. }
  2860. }
  2861. if (r.t > 0) {
  2862. r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1);
  2863. }
  2864. r.s = 0;
  2865. r.clamp();
  2866. };
  2867. // BigInteger.prototype.divRemTo = bnpDivRemTo;
  2868. // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
  2869. // r != q, this != m. q or r may be null.
  2870. BigInteger.prototype.divRemTo = function (m, q, r) {
  2871. var pm = m.abs();
  2872. if (pm.t <= 0) {
  2873. return;
  2874. }
  2875. var pt = this.abs();
  2876. if (pt.t < pm.t) {
  2877. if (q != null) {
  2878. q.fromInt(0);
  2879. }
  2880. if (r != null) {
  2881. this.copyTo(r);
  2882. }
  2883. return;
  2884. }
  2885. if (r == null) {
  2886. r = nbi();
  2887. }
  2888. var y = nbi();
  2889. var ts = this.s;
  2890. var ms = m.s;
  2891. var nsh = this.DB - nbits(pm[pm.t - 1]); // normalize modulus
  2892. if (nsh > 0) {
  2893. pm.lShiftTo(nsh, y);
  2894. pt.lShiftTo(nsh, r);
  2895. }
  2896. else {
  2897. pm.copyTo(y);
  2898. pt.copyTo(r);
  2899. }
  2900. var ys = y.t;
  2901. var y0 = y[ys - 1];
  2902. if (y0 == 0) {
  2903. return;
  2904. }
  2905. var yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0);
  2906. var d1 = this.FV / yt;
  2907. var d2 = (1 << this.F1) / yt;
  2908. var e = 1 << this.F2;
  2909. var i = r.t;
  2910. var j = i - ys;
  2911. var t = (q == null) ? nbi() : q;
  2912. y.dlShiftTo(j, t);
  2913. if (r.compareTo(t) >= 0) {
  2914. r[r.t++] = 1;
  2915. r.subTo(t, r);
  2916. }
  2917. BigInteger.ONE.dlShiftTo(ys, t);
  2918. t.subTo(y, y); // "negative" y so we can replace sub with am later
  2919. while (y.t < ys) {
  2920. y[y.t++] = 0;
  2921. }
  2922. while (--j >= 0) {
  2923. // Estimate quotient digit
  2924. var qd = (r[--i] == y0) ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2);
  2925. if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out
  2926. y.dlShiftTo(j, t);
  2927. r.subTo(t, r);
  2928. while (r[i] < --qd) {
  2929. r.subTo(t, r);
  2930. }
  2931. }
  2932. }
  2933. if (q != null) {
  2934. r.drShiftTo(ys, q);
  2935. if (ts != ms) {
  2936. BigInteger.ZERO.subTo(q, q);
  2937. }
  2938. }
  2939. r.t = ys;
  2940. r.clamp();
  2941. if (nsh > 0) {
  2942. r.rShiftTo(nsh, r);
  2943. } // Denormalize remainder
  2944. if (ts < 0) {
  2945. BigInteger.ZERO.subTo(r, r);
  2946. }
  2947. };
  2948. // BigInteger.prototype.invDigit = bnpInvDigit;
  2949. // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
  2950. // justification:
  2951. // xy == 1 (mod m)
  2952. // xy = 1+km
  2953. // xy(2-xy) = (1+km)(1-km)
  2954. // x[y(2-xy)] = 1-k^2m^2
  2955. // x[y(2-xy)] == 1 (mod m^2)
  2956. // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
  2957. // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
  2958. // JS multiply "overflows" differently from C/C++, so care is needed here.
  2959. BigInteger.prototype.invDigit = function () {
  2960. if (this.t < 1) {
  2961. return 0;
  2962. }
  2963. var x = this[0];
  2964. if ((x & 1) == 0) {
  2965. return 0;
  2966. }
  2967. var y = x & 3; // y == 1/x mod 2^2
  2968. y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4
  2969. y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8
  2970. y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16
  2971. // last step - calculate inverse mod DV directly;
  2972. // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
  2973. y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits
  2974. // we really want the negative inverse, and -DV < y < DV
  2975. return (y > 0) ? this.DV - y : -y;
  2976. };
  2977. // BigInteger.prototype.isEven = bnpIsEven;
  2978. // (protected) true iff this is even
  2979. BigInteger.prototype.isEven = function () {
  2980. return ((this.t > 0) ? (this[0] & 1) : this.s) == 0;
  2981. };
  2982. // BigInteger.prototype.exp = bnpExp;
  2983. // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
  2984. BigInteger.prototype.exp = function (e, z) {
  2985. if (e > 0xffffffff || e < 1) {
  2986. return BigInteger.ONE;
  2987. }
  2988. var r = nbi();
  2989. var r2 = nbi();
  2990. var g = z.convert(this);
  2991. var i = nbits(e) - 1;
  2992. g.copyTo(r);
  2993. while (--i >= 0) {
  2994. z.sqrTo(r, r2);
  2995. if ((e & (1 << i)) > 0) {
  2996. z.mulTo(r2, g, r);
  2997. }
  2998. else {
  2999. var t = r;
  3000. r = r2;
  3001. r2 = t;
  3002. }
  3003. }
  3004. return z.revert(r);
  3005. };
  3006. // BigInteger.prototype.chunkSize = bnpChunkSize;
  3007. // (protected) return x s.t. r^x < DV
  3008. BigInteger.prototype.chunkSize = function (r) {
  3009. return Math.floor(Math.LN2 * this.DB / Math.log(r));
  3010. };
  3011. // BigInteger.prototype.toRadix = bnpToRadix;
  3012. // (protected) convert to radix string
  3013. BigInteger.prototype.toRadix = function (b) {
  3014. if (b == null) {
  3015. b = 10;
  3016. }
  3017. if (this.signum() == 0 || b < 2 || b > 36) {
  3018. return "0";
  3019. }
  3020. var cs = this.chunkSize(b);
  3021. var a = Math.pow(b, cs);
  3022. var d = nbv(a);
  3023. var y = nbi();
  3024. var z = nbi();
  3025. var r = "";
  3026. this.divRemTo(d, y, z);
  3027. while (y.signum() > 0) {
  3028. r = (a + z.intValue()).toString(b).substr(1) + r;
  3029. y.divRemTo(d, y, z);
  3030. }
  3031. return z.intValue().toString(b) + r;
  3032. };
  3033. // BigInteger.prototype.fromRadix = bnpFromRadix;
  3034. // (protected) convert from radix string
  3035. BigInteger.prototype.fromRadix = function (s, b) {
  3036. this.fromInt(0);
  3037. if (b == null) {
  3038. b = 10;
  3039. }
  3040. var cs = this.chunkSize(b);
  3041. var d = Math.pow(b, cs);
  3042. var mi = false;
  3043. var j = 0;
  3044. var w = 0;
  3045. for (var i = 0; i < s.length; ++i) {
  3046. var x = intAt(s, i);
  3047. if (x < 0) {
  3048. if (s.charAt(i) == "-" && this.signum() == 0) {
  3049. mi = true;
  3050. }
  3051. continue;
  3052. }
  3053. w = b * w + x;
  3054. if (++j >= cs) {
  3055. this.dMultiply(d);
  3056. this.dAddOffset(w, 0);
  3057. j = 0;
  3058. w = 0;
  3059. }
  3060. }
  3061. if (j > 0) {
  3062. this.dMultiply(Math.pow(b, j));
  3063. this.dAddOffset(w, 0);
  3064. }
  3065. if (mi) {
  3066. BigInteger.ZERO.subTo(this, this);
  3067. }
  3068. };
  3069. // BigInteger.prototype.fromNumber = bnpFromNumber;
  3070. // (protected) alternate constructor
  3071. BigInteger.prototype.fromNumber = function (a, b, c) {
  3072. if ("number" == typeof b) {
  3073. // new BigInteger(int,int,RNG)
  3074. if (a < 2) {
  3075. this.fromInt(1);
  3076. }
  3077. else {
  3078. this.fromNumber(a, c);
  3079. if (!this.testBit(a - 1)) {
  3080. // force MSB set
  3081. this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this);
  3082. }
  3083. if (this.isEven()) {
  3084. this.dAddOffset(1, 0);
  3085. } // force odd
  3086. while (!this.isProbablePrime(b)) {
  3087. this.dAddOffset(2, 0);
  3088. if (this.bitLength() > a) {
  3089. this.subTo(BigInteger.ONE.shiftLeft(a - 1), this);
  3090. }
  3091. }
  3092. }
  3093. }
  3094. else {
  3095. // new BigInteger(int,RNG)
  3096. var x = [];
  3097. var t = a & 7;
  3098. x.length = (a >> 3) + 1;
  3099. b.nextBytes(x);
  3100. if (t > 0) {
  3101. x[0] &= ((1 << t) - 1);
  3102. }
  3103. else {
  3104. x[0] = 0;
  3105. }
  3106. this.fromString(x, 256);
  3107. }
  3108. };
  3109. // BigInteger.prototype.bitwiseTo = bnpBitwiseTo;
  3110. // (protected) r = this op a (bitwise)
  3111. BigInteger.prototype.bitwiseTo = function (a, op, r) {
  3112. var i;
  3113. var f;
  3114. var m = Math.min(a.t, this.t);
  3115. for (i = 0; i < m; ++i) {
  3116. r[i] = op(this[i], a[i]);
  3117. }
  3118. if (a.t < this.t) {
  3119. f = a.s & this.DM;
  3120. for (i = m; i < this.t; ++i) {
  3121. r[i] = op(this[i], f);
  3122. }
  3123. r.t = this.t;
  3124. }
  3125. else {
  3126. f = this.s & this.DM;
  3127. for (i = m; i < a.t; ++i) {
  3128. r[i] = op(f, a[i]);
  3129. }
  3130. r.t = a.t;
  3131. }
  3132. r.s = op(this.s, a.s);
  3133. r.clamp();
  3134. };
  3135. // BigInteger.prototype.changeBit = bnpChangeBit;
  3136. // (protected) this op (1<<n)
  3137. BigInteger.prototype.changeBit = function (n, op) {
  3138. var r = BigInteger.ONE.shiftLeft(n);
  3139. this.bitwiseTo(r, op, r);
  3140. return r;
  3141. };
  3142. // BigInteger.prototype.addTo = bnpAddTo;
  3143. // (protected) r = this + a
  3144. BigInteger.prototype.addTo = function (a, r) {
  3145. var i = 0;
  3146. var c = 0;
  3147. var m = Math.min(a.t, this.t);
  3148. while (i < m) {
  3149. c += this[i] + a[i];
  3150. r[i++] = c & this.DM;
  3151. c >>= this.DB;
  3152. }
  3153. if (a.t < this.t) {
  3154. c += a.s;
  3155. while (i < this.t) {
  3156. c += this[i];
  3157. r[i++] = c & this.DM;
  3158. c >>= this.DB;
  3159. }
  3160. c += this.s;
  3161. }
  3162. else {
  3163. c += this.s;
  3164. while (i < a.t) {
  3165. c += a[i];
  3166. r[i++] = c & this.DM;
  3167. c >>= this.DB;
  3168. }
  3169. c += a.s;
  3170. }
  3171. r.s = (c < 0) ? -1 : 0;
  3172. if (c > 0) {
  3173. r[i++] = c;
  3174. }
  3175. else if (c < -1) {
  3176. r[i++] = this.DV + c;
  3177. }
  3178. r.t = i;
  3179. r.clamp();
  3180. };
  3181. // BigInteger.prototype.dMultiply = bnpDMultiply;
  3182. // (protected) this *= n, this >= 0, 1 < n < DV
  3183. BigInteger.prototype.dMultiply = function (n) {
  3184. this[this.t] = this.am(0, n - 1, this, 0, 0, this.t);
  3185. ++this.t;
  3186. this.clamp();
  3187. };
  3188. // BigInteger.prototype.dAddOffset = bnpDAddOffset;
  3189. // (protected) this += n << w words, this >= 0
  3190. BigInteger.prototype.dAddOffset = function (n, w) {
  3191. if (n == 0) {
  3192. return;
  3193. }
  3194. while (this.t <= w) {
  3195. this[this.t++] = 0;
  3196. }
  3197. this[w] += n;
  3198. while (this[w] >= this.DV) {
  3199. this[w] -= this.DV;
  3200. if (++w >= this.t) {
  3201. this[this.t++] = 0;
  3202. }
  3203. ++this[w];
  3204. }
  3205. };
  3206. // BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
  3207. // (protected) r = lower n words of "this * a", a.t <= n
  3208. // "this" should be the larger one if appropriate.
  3209. BigInteger.prototype.multiplyLowerTo = function (a, n, r) {
  3210. var i = Math.min(this.t + a.t, n);
  3211. r.s = 0; // assumes a,this >= 0
  3212. r.t = i;
  3213. while (i > 0) {
  3214. r[--i] = 0;
  3215. }
  3216. for (var j = r.t - this.t; i < j; ++i) {
  3217. r[i + this.t] = this.am(0, a[i], r, i, 0, this.t);
  3218. }
  3219. for (var j = Math.min(a.t, n); i < j; ++i) {
  3220. this.am(0, a[i], r, i, 0, n - i);
  3221. }
  3222. r.clamp();
  3223. };
  3224. // BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
  3225. // (protected) r = "this * a" without lower n words, n > 0
  3226. // "this" should be the larger one if appropriate.
  3227. BigInteger.prototype.multiplyUpperTo = function (a, n, r) {
  3228. --n;
  3229. var i = r.t = this.t + a.t - n;
  3230. r.s = 0; // assumes a,this >= 0
  3231. while (--i >= 0) {
  3232. r[i] = 0;
  3233. }
  3234. for (i = Math.max(n - this.t, 0); i < a.t; ++i) {
  3235. r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n);
  3236. }
  3237. r.clamp();
  3238. r.drShiftTo(1, r);
  3239. };
  3240. // BigInteger.prototype.modInt = bnpModInt;
  3241. // (protected) this % n, n < 2^26
  3242. BigInteger.prototype.modInt = function (n) {
  3243. if (n <= 0) {
  3244. return 0;
  3245. }
  3246. var d = this.DV % n;
  3247. var r = (this.s < 0) ? n - 1 : 0;
  3248. if (this.t > 0) {
  3249. if (d == 0) {
  3250. r = this[0] % n;
  3251. }
  3252. else {
  3253. for (var i = this.t - 1; i >= 0; --i) {
  3254. r = (d * r + this[i]) % n;
  3255. }
  3256. }
  3257. }
  3258. return r;
  3259. };
  3260. // BigInteger.prototype.millerRabin = bnpMillerRabin;
  3261. // (protected) true if probably prime (HAC 4.24, Miller-Rabin)
  3262. BigInteger.prototype.millerRabin = function (t) {
  3263. var n1 = this.subtract(BigInteger.ONE);
  3264. var k = n1.getLowestSetBit();
  3265. if (k <= 0) {
  3266. return false;
  3267. }
  3268. var r = n1.shiftRight(k);
  3269. t = (t + 1) >> 1;
  3270. if (t > lowprimes.length) {
  3271. t = lowprimes.length;
  3272. }
  3273. var a = nbi();
  3274. for (var i = 0; i < t; ++i) {
  3275. // Pick bases at random, instead of starting at 2
  3276. a.fromInt(lowprimes[Math.floor(Math.random() * lowprimes.length)]);
  3277. var y = a.modPow(r, this);
  3278. if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
  3279. var j = 1;
  3280. while (j++ < k && y.compareTo(n1) != 0) {
  3281. y = y.modPowInt(2, this);
  3282. if (y.compareTo(BigInteger.ONE) == 0) {
  3283. return false;
  3284. }
  3285. }
  3286. if (y.compareTo(n1) != 0) {
  3287. return false;
  3288. }
  3289. }
  3290. }
  3291. return true;
  3292. };
  3293. // BigInteger.prototype.square = bnSquare;
  3294. // (public) this^2
  3295. BigInteger.prototype.square = function () {
  3296. var r = nbi();
  3297. this.squareTo(r);
  3298. return r;
  3299. };
  3300. //#region ASYNC
  3301. // Public API method
  3302. BigInteger.prototype.gcda = function (a, callback) {
  3303. var x = (this.s < 0) ? this.negate() : this.clone();
  3304. var y = (a.s < 0) ? a.negate() : a.clone();
  3305. if (x.compareTo(y) < 0) {
  3306. var t = x;
  3307. x = y;
  3308. y = t;
  3309. }
  3310. var i = x.getLowestSetBit();
  3311. var g = y.getLowestSetBit();
  3312. if (g < 0) {
  3313. callback(x);
  3314. return;
  3315. }
  3316. if (i < g) {
  3317. g = i;
  3318. }
  3319. if (g > 0) {
  3320. x.rShiftTo(g, x);
  3321. y.rShiftTo(g, y);
  3322. }
  3323. // Workhorse of the algorithm, gets called 200 - 800 times per 512 bit keygen.
  3324. var gcda1 = function () {
  3325. if ((i = x.getLowestSetBit()) > 0) {
  3326. x.rShiftTo(i, x);
  3327. }
  3328. if ((i = y.getLowestSetBit()) > 0) {
  3329. y.rShiftTo(i, y);
  3330. }
  3331. if (x.compareTo(y) >= 0) {
  3332. x.subTo(y, x);
  3333. x.rShiftTo(1, x);
  3334. }
  3335. else {
  3336. y.subTo(x, y);
  3337. y.rShiftTo(1, y);
  3338. }
  3339. if (!(x.signum() > 0)) {
  3340. if (g > 0) {
  3341. y.lShiftTo(g, y);
  3342. }
  3343. setTimeout(function () { callback(y); }, 0); // escape
  3344. }
  3345. else {
  3346. setTimeout(gcda1, 0);
  3347. }
  3348. };
  3349. setTimeout(gcda1, 10);
  3350. };
  3351. // (protected) alternate constructor
  3352. BigInteger.prototype.fromNumberAsync = function (a, b, c, callback) {
  3353. if ("number" == typeof b) {
  3354. if (a < 2) {
  3355. this.fromInt(1);
  3356. }
  3357. else {
  3358. this.fromNumber(a, c);
  3359. if (!this.testBit(a - 1)) {
  3360. this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this);
  3361. }
  3362. if (this.isEven()) {
  3363. this.dAddOffset(1, 0);
  3364. }
  3365. var bnp_1 = this;
  3366. var bnpfn1_1 = function () {
  3367. bnp_1.dAddOffset(2, 0);
  3368. if (bnp_1.bitLength() > a) {
  3369. bnp_1.subTo(BigInteger.ONE.shiftLeft(a - 1), bnp_1);
  3370. }
  3371. if (bnp_1.isProbablePrime(b)) {
  3372. setTimeout(function () { callback(); }, 0); // escape
  3373. }
  3374. else {
  3375. setTimeout(bnpfn1_1, 0);
  3376. }
  3377. };
  3378. setTimeout(bnpfn1_1, 0);
  3379. }
  3380. }
  3381. else {
  3382. var x = [];
  3383. var t = a & 7;
  3384. x.length = (a >> 3) + 1;
  3385. b.nextBytes(x);
  3386. if (t > 0) {
  3387. x[0] &= ((1 << t) - 1);
  3388. }
  3389. else {
  3390. x[0] = 0;
  3391. }
  3392. this.fromString(x, 256);
  3393. }
  3394. };
  3395. return BigInteger;
  3396. }());
  3397. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, 'BigInteger', { enumerable: true, configurable: true, get: function() { return BigInteger; } });
  3398. //#region REDUCERS
  3399. //#region NullExp
  3400. var NullExp = /** @class */ (function () {
  3401. function NullExp() {
  3402. }
  3403. // NullExp.prototype.convert = nNop;
  3404. NullExp.prototype.convert = function (x) {
  3405. return x;
  3406. };
  3407. // NullExp.prototype.revert = nNop;
  3408. NullExp.prototype.revert = function (x) {
  3409. return x;
  3410. };
  3411. // NullExp.prototype.mulTo = nMulTo;
  3412. NullExp.prototype.mulTo = function (x, y, r) {
  3413. x.multiplyTo(y, r);
  3414. };
  3415. // NullExp.prototype.sqrTo = nSqrTo;
  3416. NullExp.prototype.sqrTo = function (x, r) {
  3417. x.squareTo(r);
  3418. };
  3419. return NullExp;
  3420. }());
  3421. // Modular reduction using "classic" algorithm
  3422. var Classic = /** @class */ (function () {
  3423. function Classic(m) {
  3424. this.m = m;
  3425. }
  3426. // Classic.prototype.convert = cConvert;
  3427. Classic.prototype.convert = function (x) {
  3428. if (x.s < 0 || x.compareTo(this.m) >= 0) {
  3429. return x.mod(this.m);
  3430. }
  3431. else {
  3432. return x;
  3433. }
  3434. };
  3435. // Classic.prototype.revert = cRevert;
  3436. Classic.prototype.revert = function (x) {
  3437. return x;
  3438. };
  3439. // Classic.prototype.reduce = cReduce;
  3440. Classic.prototype.reduce = function (x) {
  3441. x.divRemTo(this.m, null, x);
  3442. };
  3443. // Classic.prototype.mulTo = cMulTo;
  3444. Classic.prototype.mulTo = function (x, y, r) {
  3445. x.multiplyTo(y, r);
  3446. this.reduce(r);
  3447. };
  3448. // Classic.prototype.sqrTo = cSqrTo;
  3449. Classic.prototype.sqrTo = function (x, r) {
  3450. x.squareTo(r);
  3451. this.reduce(r);
  3452. };
  3453. return Classic;
  3454. }());
  3455. //#endregion
  3456. //#region Montgomery
  3457. // Montgomery reduction
  3458. var Montgomery = /** @class */ (function () {
  3459. function Montgomery(m) {
  3460. this.m = m;
  3461. this.mp = m.invDigit();
  3462. this.mpl = this.mp & 0x7fff;
  3463. this.mph = this.mp >> 15;
  3464. this.um = (1 << (m.DB - 15)) - 1;
  3465. this.mt2 = 2 * m.t;
  3466. }
  3467. // Montgomery.prototype.convert = montConvert;
  3468. // xR mod m
  3469. Montgomery.prototype.convert = function (x) {
  3470. var r = nbi();
  3471. x.abs().dlShiftTo(this.m.t, r);
  3472. r.divRemTo(this.m, null, r);
  3473. if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) {
  3474. this.m.subTo(r, r);
  3475. }
  3476. return r;
  3477. };
  3478. // Montgomery.prototype.revert = montRevert;
  3479. // x/R mod m
  3480. Montgomery.prototype.revert = function (x) {
  3481. var r = nbi();
  3482. x.copyTo(r);
  3483. this.reduce(r);
  3484. return r;
  3485. };
  3486. // Montgomery.prototype.reduce = montReduce;
  3487. // x = x/R mod m (HAC 14.32)
  3488. Montgomery.prototype.reduce = function (x) {
  3489. while (x.t <= this.mt2) {
  3490. // pad x so am has enough room later
  3491. x[x.t++] = 0;
  3492. }
  3493. for (var i = 0; i < this.m.t; ++i) {
  3494. // faster way of calculating u0 = x[i]*mp mod DV
  3495. var j = x[i] & 0x7fff;
  3496. var u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM;
  3497. // use am to combine the multiply-shift-add into one call
  3498. j = i + this.m.t;
  3499. x[j] += this.m.am(0, u0, x, i, 0, this.m.t);
  3500. // propagate carry
  3501. while (x[j] >= x.DV) {
  3502. x[j] -= x.DV;
  3503. x[++j]++;
  3504. }
  3505. }
  3506. x.clamp();
  3507. x.drShiftTo(this.m.t, x);
  3508. if (x.compareTo(this.m) >= 0) {
  3509. x.subTo(this.m, x);
  3510. }
  3511. };
  3512. // Montgomery.prototype.mulTo = montMulTo;
  3513. // r = "xy/R mod m"; x,y != r
  3514. Montgomery.prototype.mulTo = function (x, y, r) {
  3515. x.multiplyTo(y, r);
  3516. this.reduce(r);
  3517. };
  3518. // Montgomery.prototype.sqrTo = montSqrTo;
  3519. // r = "x^2/R mod m"; x != r
  3520. Montgomery.prototype.sqrTo = function (x, r) {
  3521. x.squareTo(r);
  3522. this.reduce(r);
  3523. };
  3524. return Montgomery;
  3525. }());
  3526. //#endregion Montgomery
  3527. //#region Barrett
  3528. // Barrett modular reduction
  3529. var Barrett = /** @class */ (function () {
  3530. function Barrett(m) {
  3531. this.m = m;
  3532. // setup Barrett
  3533. this.r2 = nbi();
  3534. this.q3 = nbi();
  3535. BigInteger.ONE.dlShiftTo(2 * m.t, this.r2);
  3536. this.mu = this.r2.divide(m);
  3537. }
  3538. // Barrett.prototype.convert = barrettConvert;
  3539. Barrett.prototype.convert = function (x) {
  3540. if (x.s < 0 || x.t > 2 * this.m.t) {
  3541. return x.mod(this.m);
  3542. }
  3543. else if (x.compareTo(this.m) < 0) {
  3544. return x;
  3545. }
  3546. else {
  3547. var r = nbi();
  3548. x.copyTo(r);
  3549. this.reduce(r);
  3550. return r;
  3551. }
  3552. };
  3553. // Barrett.prototype.revert = barrettRevert;
  3554. Barrett.prototype.revert = function (x) {
  3555. return x;
  3556. };
  3557. // Barrett.prototype.reduce = barrettReduce;
  3558. // x = x mod m (HAC 14.42)
  3559. Barrett.prototype.reduce = function (x) {
  3560. x.drShiftTo(this.m.t - 1, this.r2);
  3561. if (x.t > this.m.t + 1) {
  3562. x.t = this.m.t + 1;
  3563. x.clamp();
  3564. }
  3565. this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3);
  3566. this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2);
  3567. while (x.compareTo(this.r2) < 0) {
  3568. x.dAddOffset(1, this.m.t + 1);
  3569. }
  3570. x.subTo(this.r2, x);
  3571. while (x.compareTo(this.m) >= 0) {
  3572. x.subTo(this.m, x);
  3573. }
  3574. };
  3575. // Barrett.prototype.mulTo = barrettMulTo;
  3576. // r = x*y mod m; x,y != r
  3577. Barrett.prototype.mulTo = function (x, y, r) {
  3578. x.multiplyTo(y, r);
  3579. this.reduce(r);
  3580. };
  3581. // Barrett.prototype.sqrTo = barrettSqrTo;
  3582. // r = x^2 mod m; x != r
  3583. Barrett.prototype.sqrTo = function (x, r) {
  3584. x.squareTo(r);
  3585. this.reduce(r);
  3586. };
  3587. return Barrett;
  3588. }());
  3589. //#endregion
  3590. //#endregion REDUCERS
  3591. // return new, unset BigInteger
  3592. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function nbi() { return new BigInteger(null); };exports.nbi = nbi
  3593. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function parseBigInt(str, r) {
  3594. return new BigInteger(str, r);
  3595. };exports.parseBigInt = parseBigInt
  3596. // am: Compute w_j += (x*this_i), propagate carries,
  3597. // c is initial carry, returns final carry.
  3598. // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
  3599. // We need to select the fastest one that works in this environment.
  3600. var inBrowser = typeof navigator !== "undefined";
  3601. if (inBrowser && j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
  3602. // am2 avoids a big mult-and-extract completely.
  3603. // Max digit bits should be <= 30 because we do bitwise ops
  3604. // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
  3605. BigInteger.prototype.am = function am2(i, x, w, j, c, n) {
  3606. var xl = x & 0x7fff;
  3607. var xh = x >> 15;
  3608. while (--n >= 0) {
  3609. var l = this[i] & 0x7fff;
  3610. var h = this[i++] >> 15;
  3611. var m = xh * l + h * xl;
  3612. l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff);
  3613. c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30);
  3614. w[j++] = l & 0x3fffffff;
  3615. }
  3616. return c;
  3617. };
  3618. dbits = 30;
  3619. }
  3620. else if (inBrowser && j_lm && (navigator.appName != "Netscape")) {
  3621. // am1: use a single mult and divide to get the high bits,
  3622. // max digit bits should be 26 because
  3623. // max internal value = 2*dvalue^2-2*dvalue (< 2^53)
  3624. BigInteger.prototype.am = function am1(i, x, w, j, c, n) {
  3625. while (--n >= 0) {
  3626. var v = x * this[i++] + w[j] + c;
  3627. c = Math.floor(v / 0x4000000);
  3628. w[j++] = v & 0x3ffffff;
  3629. }
  3630. return c;
  3631. };
  3632. dbits = 26;
  3633. }
  3634. else { // Mozilla/Netscape seems to prefer am3
  3635. // Alternately, set max digit bits to 28 since some
  3636. // browsers slow down when dealing with 32-bit numbers.
  3637. BigInteger.prototype.am = function am3(i, x, w, j, c, n) {
  3638. var xl = x & 0x3fff;
  3639. var xh = x >> 14;
  3640. while (--n >= 0) {
  3641. var l = this[i] & 0x3fff;
  3642. var h = this[i++] >> 14;
  3643. var m = xh * l + h * xl;
  3644. l = xl * l + ((m & 0x3fff) << 14) + w[j] + c;
  3645. c = (l >> 28) + (m >> 14) + xh * h;
  3646. w[j++] = l & 0xfffffff;
  3647. }
  3648. return c;
  3649. };
  3650. dbits = 28;
  3651. }
  3652. BigInteger.prototype.DB = dbits;
  3653. BigInteger.prototype.DM = ((1 << dbits) - 1);
  3654. BigInteger.prototype.DV = (1 << dbits);
  3655. var BI_FP = 52;
  3656. BigInteger.prototype.FV = Math.pow(2, BI_FP);
  3657. BigInteger.prototype.F1 = BI_FP - dbits;
  3658. BigInteger.prototype.F2 = 2 * dbits - BI_FP;
  3659. // Digit conversions
  3660. var BI_RC = [];
  3661. var rr;
  3662. var vv;
  3663. rr = "0".charCodeAt(0);
  3664. for (vv = 0; vv <= 9; ++vv) {
  3665. BI_RC[rr++] = vv;
  3666. }
  3667. rr = "a".charCodeAt(0);
  3668. for (vv = 10; vv < 36; ++vv) {
  3669. BI_RC[rr++] = vv;
  3670. }
  3671. rr = "A".charCodeAt(0);
  3672. for (vv = 10; vv < 36; ++vv) {
  3673. BI_RC[rr++] = vv;
  3674. }
  3675. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function intAt(s, i) {
  3676. var c = BI_RC[s.charCodeAt(i)];
  3677. return (c == null) ? -1 : c;
  3678. };exports.intAt = intAt
  3679. // return bigint initialized to value
  3680. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function nbv(i) {
  3681. var r = nbi();
  3682. r.fromInt(i);
  3683. return r;
  3684. };exports.nbv = nbv
  3685. // returns bit length of the integer x
  3686. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function nbits(x) {
  3687. var r = 1;
  3688. var t;
  3689. if ((t = x >>> 16) != 0) {
  3690. x = t;
  3691. r += 16;
  3692. }
  3693. if ((t = x >> 8) != 0) {
  3694. x = t;
  3695. r += 8;
  3696. }
  3697. if ((t = x >> 4) != 0) {
  3698. x = t;
  3699. r += 4;
  3700. }
  3701. if ((t = x >> 2) != 0) {
  3702. x = t;
  3703. r += 2;
  3704. }
  3705. if ((t = x >> 1) != 0) {
  3706. x = t;
  3707. r += 1;
  3708. }
  3709. return r;
  3710. };exports.nbits = nbits
  3711. // "constants"
  3712. BigInteger.ZERO = nbv(0);
  3713. BigInteger.ONE = nbv(1);
  3714. }, function(modId) { var map = {"./util":1709513243597}; return __REQUIRE__(map[modId], modId); })
  3715. __DEFINE__(1709513243605, function(require, module, exports) {
  3716. // Random number generator - requires a PRNG backend, e.g. prng4.js
  3717. var __TEMP__ = require('./prng4');var prng_newstate = __TEMP__['prng_newstate'];var rng_psize = __TEMP__['rng_psize'];
  3718. var rng_state;
  3719. var rng_pool = null;
  3720. var rng_pptr;
  3721. // Initialize the pool with junk if needed.
  3722. if (rng_pool == null) {
  3723. rng_pool = [];
  3724. rng_pptr = 0;
  3725. var t = void 0;
  3726. // Use mouse events for entropy, if we do not have enough entropy by the time
  3727. // we need it, entropy will be generated by Math.random.
  3728. var count = 0;
  3729. var onMouseMoveListener = function (ev) {
  3730. count = count || 0;
  3731. if (count >= 256 || rng_pptr >= rng_psize) {
  3732. return;
  3733. }
  3734. try {
  3735. var mouseCoordinates = ev.x + ev.y;
  3736. rng_pool[rng_pptr++] = mouseCoordinates & 255;
  3737. count += 1;
  3738. }
  3739. catch (e) {
  3740. // Sometimes Firefox will deny permission to access event properties for some reason. Ignore.
  3741. }
  3742. };
  3743. }
  3744. function rng_get_byte() {
  3745. if (rng_state == null) {
  3746. rng_state = prng_newstate();
  3747. // At this point, we may not have collected enough entropy. If not, fall back to Math.random
  3748. while (rng_pptr < rng_psize) {
  3749. var random = Math.floor(65536 * Math.random());
  3750. rng_pool[rng_pptr++] = random & 255;
  3751. }
  3752. rng_state.init(rng_pool);
  3753. for (rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr) {
  3754. rng_pool[rng_pptr] = 0;
  3755. }
  3756. rng_pptr = 0;
  3757. }
  3758. // TODO: allow reseeding after first request
  3759. return rng_state.next();
  3760. }
  3761. var SecureRandom = /** @class */ (function () {
  3762. function SecureRandom() {
  3763. }
  3764. SecureRandom.prototype.nextBytes = function (ba) {
  3765. for (var i = 0; i < ba.length; ++i) {
  3766. ba[i] = rng_get_byte();
  3767. }
  3768. };
  3769. return SecureRandom;
  3770. }());
  3771. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, 'SecureRandom', { enumerable: true, configurable: true, get: function() { return SecureRandom; } });
  3772. }, function(modId) { var map = {"./prng4":1709513243606}; return __REQUIRE__(map[modId], modId); })
  3773. __DEFINE__(1709513243606, function(require, module, exports) {
  3774. // prng4.js - uses Arcfour as a PRNG
  3775. var Arcfour = /** @class */ (function () {
  3776. function Arcfour() {
  3777. this.i = 0;
  3778. this.j = 0;
  3779. this.S = [];
  3780. }
  3781. // Arcfour.prototype.init = ARC4init;
  3782. // Initialize arcfour context from key, an array of ints, each from [0..255]
  3783. Arcfour.prototype.init = function (key) {
  3784. var i;
  3785. var j;
  3786. var t;
  3787. for (i = 0; i < 256; ++i) {
  3788. this.S[i] = i;
  3789. }
  3790. j = 0;
  3791. for (i = 0; i < 256; ++i) {
  3792. j = (j + this.S[i] + key[i % key.length]) & 255;
  3793. t = this.S[i];
  3794. this.S[i] = this.S[j];
  3795. this.S[j] = t;
  3796. }
  3797. this.i = 0;
  3798. this.j = 0;
  3799. };
  3800. // Arcfour.prototype.next = ARC4next;
  3801. Arcfour.prototype.next = function () {
  3802. var t;
  3803. this.i = (this.i + 1) & 255;
  3804. this.j = (this.j + this.S[this.i]) & 255;
  3805. t = this.S[this.i];
  3806. this.S[this.i] = this.S[this.j];
  3807. this.S[this.j] = t;
  3808. return this.S[(t + this.S[this.i]) & 255];
  3809. };
  3810. return Arcfour;
  3811. }());
  3812. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, 'Arcfour', { enumerable: true, configurable: true, get: function() { return Arcfour; } });
  3813. // Plug in your RNG constructor here
  3814. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });function prng_newstate() {
  3815. return new Arcfour();
  3816. };exports.prng_newstate = prng_newstate
  3817. // Pool size must be a multiple of 4 and greater than 32.
  3818. // An array of bytes the size of the pool will be passed to init()
  3819. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });var rng_psize = exports.rng_psize = 256;
  3820. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  3821. __DEFINE__(1709513243607, function(require, module, exports) {
  3822. /* asn1-1.0.13.js (c) 2013-2017 Kenji Urushima | kjur.github.com/jsrsasign/license
  3823. */
  3824. /*
  3825. * asn1.js - ASN.1 DER encoder classes
  3826. *
  3827. * Copyright (c) 2013-2017 Kenji Urushima (kenji.urushima@gmail.com)
  3828. *
  3829. * This software is licensed under the terms of the MIT License.
  3830. * https://kjur.github.io/jsrsasign/license
  3831. *
  3832. * The above copyright and license notice shall be
  3833. * included in all copies or substantial portions of the Software.
  3834. */
  3835. var __TEMP__ = require('../jsbn/jsbn');var BigInteger = __TEMP__['BigInteger'];
  3836. var __TEMP__ = require('./yahoo');var YAHOO = __TEMP__['YAHOO'];
  3837. /**
  3838. * @fileOverview
  3839. * @name asn1-1.0.js
  3840. * @author Kenji Urushima kenji.urushima@gmail.com
  3841. * @version asn1 1.0.13 (2017-Jun-02)
  3842. * @since jsrsasign 2.1
  3843. * @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
  3844. */
  3845. /**
  3846. * kjur's class library name space
  3847. * <p>
  3848. * This name space provides following name spaces:
  3849. * <ul>
  3850. * <li>{@link KJUR.asn1} - ASN.1 primitive hexadecimal encoder</li>
  3851. * <li>{@link KJUR.asn1.x509} - ASN.1 structure for X.509 certificate and CRL</li>
  3852. * <li>{@link KJUR.crypto} - Java Cryptographic Extension(JCE) style MessageDigest/Signature
  3853. * class and utilities</li>
  3854. * </ul>
  3855. * </p>
  3856. * NOTE: Please ignore method summary and document of this namespace. This caused by a bug of jsdoc2.
  3857. * @name KJUR
  3858. * @namespace kjur's class library name space
  3859. */
  3860. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });var KJUR = exports.KJUR = {};
  3861. /**
  3862. * kjur's ASN.1 class library name space
  3863. * <p>
  3864. * This is ITU-T X.690 ASN.1 DER encoder class library and
  3865. * class structure and methods is very similar to
  3866. * org.bouncycastle.asn1 package of
  3867. * well known BouncyCaslte Cryptography Library.
  3868. * <h4>PROVIDING ASN.1 PRIMITIVES</h4>
  3869. * Here are ASN.1 DER primitive classes.
  3870. * <ul>
  3871. * <li>0x01 {@link KJUR.asn1.DERBoolean}</li>
  3872. * <li>0x02 {@link KJUR.asn1.DERInteger}</li>
  3873. * <li>0x03 {@link KJUR.asn1.DERBitString}</li>
  3874. * <li>0x04 {@link KJUR.asn1.DEROctetString}</li>
  3875. * <li>0x05 {@link KJUR.asn1.DERNull}</li>
  3876. * <li>0x06 {@link KJUR.asn1.DERObjectIdentifier}</li>
  3877. * <li>0x0a {@link KJUR.asn1.DEREnumerated}</li>
  3878. * <li>0x0c {@link KJUR.asn1.DERUTF8String}</li>
  3879. * <li>0x12 {@link KJUR.asn1.DERNumericString}</li>
  3880. * <li>0x13 {@link KJUR.asn1.DERPrintableString}</li>
  3881. * <li>0x14 {@link KJUR.asn1.DERTeletexString}</li>
  3882. * <li>0x16 {@link KJUR.asn1.DERIA5String}</li>
  3883. * <li>0x17 {@link KJUR.asn1.DERUTCTime}</li>
  3884. * <li>0x18 {@link KJUR.asn1.DERGeneralizedTime}</li>
  3885. * <li>0x30 {@link KJUR.asn1.DERSequence}</li>
  3886. * <li>0x31 {@link KJUR.asn1.DERSet}</li>
  3887. * </ul>
  3888. * <h4>OTHER ASN.1 CLASSES</h4>
  3889. * <ul>
  3890. * <li>{@link KJUR.asn1.ASN1Object}</li>
  3891. * <li>{@link KJUR.asn1.DERAbstractString}</li>
  3892. * <li>{@link KJUR.asn1.DERAbstractTime}</li>
  3893. * <li>{@link KJUR.asn1.DERAbstractStructured}</li>
  3894. * <li>{@link KJUR.asn1.DERTaggedObject}</li>
  3895. * </ul>
  3896. * <h4>SUB NAME SPACES</h4>
  3897. * <ul>
  3898. * <li>{@link KJUR.asn1.cades} - CAdES long term signature format</li>
  3899. * <li>{@link KJUR.asn1.cms} - Cryptographic Message Syntax</li>
  3900. * <li>{@link KJUR.asn1.csr} - Certificate Signing Request (CSR/PKCS#10)</li>
  3901. * <li>{@link KJUR.asn1.tsp} - RFC 3161 Timestamping Protocol Format</li>
  3902. * <li>{@link KJUR.asn1.x509} - RFC 5280 X.509 certificate and CRL</li>
  3903. * </ul>
  3904. * </p>
  3905. * NOTE: Please ignore method summary and document of this namespace.
  3906. * This caused by a bug of jsdoc2.
  3907. * @name KJUR.asn1
  3908. * @namespace
  3909. */
  3910. if (typeof KJUR.asn1 == "undefined" || !KJUR.asn1)
  3911. KJUR.asn1 = {};
  3912. /**
  3913. * ASN1 utilities class
  3914. * @name KJUR.asn1.ASN1Util
  3915. * @class ASN1 utilities class
  3916. * @since asn1 1.0.2
  3917. */
  3918. KJUR.asn1.ASN1Util = new function () {
  3919. this.integerToByteHex = function (i) {
  3920. var h = i.toString(16);
  3921. if ((h.length % 2) == 1)
  3922. h = '0' + h;
  3923. return h;
  3924. };
  3925. this.bigIntToMinTwosComplementsHex = function (bigIntegerValue) {
  3926. var h = bigIntegerValue.toString(16);
  3927. if (h.substr(0, 1) != '-') {
  3928. if (h.length % 2 == 1) {
  3929. h = '0' + h;
  3930. }
  3931. else {
  3932. if (!h.match(/^[0-7]/)) {
  3933. h = '00' + h;
  3934. }
  3935. }
  3936. }
  3937. else {
  3938. var hPos = h.substr(1);
  3939. var xorLen = hPos.length;
  3940. if (xorLen % 2 == 1) {
  3941. xorLen += 1;
  3942. }
  3943. else {
  3944. if (!h.match(/^[0-7]/)) {
  3945. xorLen += 2;
  3946. }
  3947. }
  3948. var hMask = '';
  3949. for (var i = 0; i < xorLen; i++) {
  3950. hMask += 'f';
  3951. }
  3952. var biMask = new BigInteger(hMask, 16);
  3953. var biNeg = biMask.xor(bigIntegerValue).add(BigInteger.ONE);
  3954. h = biNeg.toString(16).replace(/^-/, '');
  3955. }
  3956. return h;
  3957. };
  3958. /**
  3959. * get PEM string from hexadecimal data and header string
  3960. * @name getPEMStringFromHex
  3961. * @memberOf KJUR.asn1.ASN1Util
  3962. * @function
  3963. * @param {String} dataHex hexadecimal string of PEM body
  3964. * @param {String} pemHeader PEM header string (ex. 'RSA PRIVATE KEY')
  3965. * @return {String} PEM formatted string of input data
  3966. * @description
  3967. * This method converts a hexadecimal string to a PEM string with
  3968. * a specified header. Its line break will be CRLF("\r\n").
  3969. * @example
  3970. * var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex('616161', 'RSA PRIVATE KEY');
  3971. * // value of pem will be:
  3972. * -----BEGIN PRIVATE KEY-----
  3973. * YWFh
  3974. * -----END PRIVATE KEY-----
  3975. */
  3976. this.getPEMStringFromHex = function (dataHex, pemHeader) {
  3977. return hextopem(dataHex, pemHeader);
  3978. };
  3979. /**
  3980. * generate ASN1Object specifed by JSON parameters
  3981. * @name newObject
  3982. * @memberOf KJUR.asn1.ASN1Util
  3983. * @function
  3984. * @param {Array} param JSON parameter to generate ASN1Object
  3985. * @return {KJUR.asn1.ASN1Object} generated object
  3986. * @since asn1 1.0.3
  3987. * @description
  3988. * generate any ASN1Object specified by JSON param
  3989. * including ASN.1 primitive or structured.
  3990. * Generally 'param' can be described as follows:
  3991. * <blockquote>
  3992. * {TYPE-OF-ASNOBJ: ASN1OBJ-PARAMETER}
  3993. * </blockquote>
  3994. * 'TYPE-OF-ASN1OBJ' can be one of following symbols:
  3995. * <ul>
  3996. * <li>'bool' - DERBoolean</li>
  3997. * <li>'int' - DERInteger</li>
  3998. * <li>'bitstr' - DERBitString</li>
  3999. * <li>'octstr' - DEROctetString</li>
  4000. * <li>'null' - DERNull</li>
  4001. * <li>'oid' - DERObjectIdentifier</li>
  4002. * <li>'enum' - DEREnumerated</li>
  4003. * <li>'utf8str' - DERUTF8String</li>
  4004. * <li>'numstr' - DERNumericString</li>
  4005. * <li>'prnstr' - DERPrintableString</li>
  4006. * <li>'telstr' - DERTeletexString</li>
  4007. * <li>'ia5str' - DERIA5String</li>
  4008. * <li>'utctime' - DERUTCTime</li>
  4009. * <li>'gentime' - DERGeneralizedTime</li>
  4010. * <li>'seq' - DERSequence</li>
  4011. * <li>'set' - DERSet</li>
  4012. * <li>'tag' - DERTaggedObject</li>
  4013. * </ul>
  4014. * @example
  4015. * newObject({'prnstr': 'aaa'});
  4016. * newObject({'seq': [{'int': 3}, {'prnstr': 'aaa'}]})
  4017. * // ASN.1 Tagged Object
  4018. * newObject({'tag': {'tag': 'a1',
  4019. * 'explicit': true,
  4020. * 'obj': {'seq': [{'int': 3}, {'prnstr': 'aaa'}]}}});
  4021. * // more simple representation of ASN.1 Tagged Object
  4022. * newObject({'tag': ['a1',
  4023. * true,
  4024. * {'seq': [
  4025. * {'int': 3},
  4026. * {'prnstr': 'aaa'}]}
  4027. * ]});
  4028. */
  4029. this.newObject = function (param) {
  4030. var _KJUR = KJUR, _KJUR_asn1 = _KJUR.asn1, _DERBoolean = _KJUR_asn1.DERBoolean, _DERInteger = _KJUR_asn1.DERInteger, _DERBitString = _KJUR_asn1.DERBitString, _DEROctetString = _KJUR_asn1.DEROctetString, _DERNull = _KJUR_asn1.DERNull, _DERObjectIdentifier = _KJUR_asn1.DERObjectIdentifier, _DEREnumerated = _KJUR_asn1.DEREnumerated, _DERUTF8String = _KJUR_asn1.DERUTF8String, _DERNumericString = _KJUR_asn1.DERNumericString, _DERPrintableString = _KJUR_asn1.DERPrintableString, _DERTeletexString = _KJUR_asn1.DERTeletexString, _DERIA5String = _KJUR_asn1.DERIA5String, _DERUTCTime = _KJUR_asn1.DERUTCTime, _DERGeneralizedTime = _KJUR_asn1.DERGeneralizedTime, _DERSequence = _KJUR_asn1.DERSequence, _DERSet = _KJUR_asn1.DERSet, _DERTaggedObject = _KJUR_asn1.DERTaggedObject, _newObject = _KJUR_asn1.ASN1Util.newObject;
  4031. var keys = Object.keys(param);
  4032. if (keys.length != 1)
  4033. throw "key of param shall be only one.";
  4034. var key = keys[0];
  4035. if (":bool:int:bitstr:octstr:null:oid:enum:utf8str:numstr:prnstr:telstr:ia5str:utctime:gentime:seq:set:tag:".indexOf(":" + key + ":") == -1)
  4036. throw "undefined key: " + key;
  4037. if (key == "bool")
  4038. return new _DERBoolean(param[key]);
  4039. if (key == "int")
  4040. return new _DERInteger(param[key]);
  4041. if (key == "bitstr")
  4042. return new _DERBitString(param[key]);
  4043. if (key == "octstr")
  4044. return new _DEROctetString(param[key]);
  4045. if (key == "null")
  4046. return new _DERNull(param[key]);
  4047. if (key == "oid")
  4048. return new _DERObjectIdentifier(param[key]);
  4049. if (key == "enum")
  4050. return new _DEREnumerated(param[key]);
  4051. if (key == "utf8str")
  4052. return new _DERUTF8String(param[key]);
  4053. if (key == "numstr")
  4054. return new _DERNumericString(param[key]);
  4055. if (key == "prnstr")
  4056. return new _DERPrintableString(param[key]);
  4057. if (key == "telstr")
  4058. return new _DERTeletexString(param[key]);
  4059. if (key == "ia5str")
  4060. return new _DERIA5String(param[key]);
  4061. if (key == "utctime")
  4062. return new _DERUTCTime(param[key]);
  4063. if (key == "gentime")
  4064. return new _DERGeneralizedTime(param[key]);
  4065. if (key == "seq") {
  4066. var paramList = param[key];
  4067. var a = [];
  4068. for (var i = 0; i < paramList.length; i++) {
  4069. var asn1Obj = _newObject(paramList[i]);
  4070. a.push(asn1Obj);
  4071. }
  4072. return new _DERSequence({ 'array': a });
  4073. }
  4074. if (key == "set") {
  4075. var paramList = param[key];
  4076. var a = [];
  4077. for (var i = 0; i < paramList.length; i++) {
  4078. var asn1Obj = _newObject(paramList[i]);
  4079. a.push(asn1Obj);
  4080. }
  4081. return new _DERSet({ 'array': a });
  4082. }
  4083. if (key == "tag") {
  4084. var tagParam = param[key];
  4085. if (Object.prototype.toString.call(tagParam) === '[object Array]' &&
  4086. tagParam.length == 3) {
  4087. var obj = _newObject(tagParam[2]);
  4088. return new _DERTaggedObject({ tag: tagParam[0],
  4089. explicit: tagParam[1],
  4090. obj: obj });
  4091. }
  4092. else {
  4093. var newParam = {};
  4094. if (tagParam.explicit !== undefined)
  4095. newParam.explicit = tagParam.explicit;
  4096. if (tagParam.tag !== undefined)
  4097. newParam.tag = tagParam.tag;
  4098. if (tagParam.obj === undefined)
  4099. throw "obj shall be specified for 'tag'.";
  4100. newParam.obj = _newObject(tagParam.obj);
  4101. return new _DERTaggedObject(newParam);
  4102. }
  4103. }
  4104. };
  4105. /**
  4106. * get encoded hexadecimal string of ASN1Object specifed by JSON parameters
  4107. * @name jsonToASN1HEX
  4108. * @memberOf KJUR.asn1.ASN1Util
  4109. * @function
  4110. * @param {Array} param JSON parameter to generate ASN1Object
  4111. * @return hexadecimal string of ASN1Object
  4112. * @since asn1 1.0.4
  4113. * @description
  4114. * As for ASN.1 object representation of JSON object,
  4115. * please see {@link newObject}.
  4116. * @example
  4117. * jsonToASN1HEX({'prnstr': 'aaa'});
  4118. */
  4119. this.jsonToASN1HEX = function (param) {
  4120. var asn1Obj = this.newObject(param);
  4121. return asn1Obj.getEncodedHex();
  4122. };
  4123. };
  4124. /**
  4125. * get dot noted oid number string from hexadecimal value of OID
  4126. * @name oidHexToInt
  4127. * @memberOf KJUR.asn1.ASN1Util
  4128. * @function
  4129. * @param {String} hex hexadecimal value of object identifier
  4130. * @return {String} dot noted string of object identifier
  4131. * @since jsrsasign 4.8.3 asn1 1.0.7
  4132. * @description
  4133. * This static method converts from hexadecimal string representation of
  4134. * ASN.1 value of object identifier to oid number string.
  4135. * @example
  4136. * KJUR.asn1.ASN1Util.oidHexToInt('550406') &rarr; "2.5.4.6"
  4137. */
  4138. KJUR.asn1.ASN1Util.oidHexToInt = function (hex) {
  4139. var s = "";
  4140. var i01 = parseInt(hex.substr(0, 2), 16);
  4141. var i0 = Math.floor(i01 / 40);
  4142. var i1 = i01 % 40;
  4143. var s = i0 + "." + i1;
  4144. var binbuf = "";
  4145. for (var i = 2; i < hex.length; i += 2) {
  4146. var value = parseInt(hex.substr(i, 2), 16);
  4147. var bin = ("00000000" + value.toString(2)).slice(-8);
  4148. binbuf = binbuf + bin.substr(1, 7);
  4149. if (bin.substr(0, 1) == "0") {
  4150. var bi = new BigInteger(binbuf, 2);
  4151. s = s + "." + bi.toString(10);
  4152. binbuf = "";
  4153. }
  4154. }
  4155. ;
  4156. return s;
  4157. };
  4158. /**
  4159. * get hexadecimal value of object identifier from dot noted oid value
  4160. * @name oidIntToHex
  4161. * @memberOf KJUR.asn1.ASN1Util
  4162. * @function
  4163. * @param {String} oidString dot noted string of object identifier
  4164. * @return {String} hexadecimal value of object identifier
  4165. * @since jsrsasign 4.8.3 asn1 1.0.7
  4166. * @description
  4167. * This static method converts from object identifier value string.
  4168. * to hexadecimal string representation of it.
  4169. * @example
  4170. * KJUR.asn1.ASN1Util.oidIntToHex("2.5.4.6") &rarr; "550406"
  4171. */
  4172. KJUR.asn1.ASN1Util.oidIntToHex = function (oidString) {
  4173. var itox = function (i) {
  4174. var h = i.toString(16);
  4175. if (h.length == 1)
  4176. h = '0' + h;
  4177. return h;
  4178. };
  4179. var roidtox = function (roid) {
  4180. var h = '';
  4181. var bi = new BigInteger(roid, 10);
  4182. var b = bi.toString(2);
  4183. var padLen = 7 - b.length % 7;
  4184. if (padLen == 7)
  4185. padLen = 0;
  4186. var bPad = '';
  4187. for (var i = 0; i < padLen; i++)
  4188. bPad += '0';
  4189. b = bPad + b;
  4190. for (var i = 0; i < b.length - 1; i += 7) {
  4191. var b8 = b.substr(i, 7);
  4192. if (i != b.length - 7)
  4193. b8 = '1' + b8;
  4194. h += itox(parseInt(b8, 2));
  4195. }
  4196. return h;
  4197. };
  4198. if (!oidString.match(/^[0-9.]+$/)) {
  4199. throw "malformed oid string: " + oidString;
  4200. }
  4201. var h = '';
  4202. var a = oidString.split('.');
  4203. var i0 = parseInt(a[0]) * 40 + parseInt(a[1]);
  4204. h += itox(i0);
  4205. a.splice(0, 2);
  4206. for (var i = 0; i < a.length; i++) {
  4207. h += roidtox(a[i]);
  4208. }
  4209. return h;
  4210. };
  4211. // ********************************************************************
  4212. // Abstract ASN.1 Classes
  4213. // ********************************************************************
  4214. // ********************************************************************
  4215. /**
  4216. * base class for ASN.1 DER encoder object
  4217. * @name KJUR.asn1.ASN1Object
  4218. * @class base class for ASN.1 DER encoder object
  4219. * @property {Boolean} isModified flag whether internal data was changed
  4220. * @property {String} hTLV hexadecimal string of ASN.1 TLV
  4221. * @property {String} hT hexadecimal string of ASN.1 TLV tag(T)
  4222. * @property {String} hL hexadecimal string of ASN.1 TLV length(L)
  4223. * @property {String} hV hexadecimal string of ASN.1 TLV value(V)
  4224. * @description
  4225. */
  4226. KJUR.asn1.ASN1Object = function () {
  4227. var isModified = true;
  4228. var hTLV = null;
  4229. var hT = '00';
  4230. var hL = '00';
  4231. var hV = '';
  4232. /**
  4233. * get hexadecimal ASN.1 TLV length(L) bytes from TLV value(V)
  4234. * @name getLengthHexFromValue
  4235. * @memberOf KJUR.asn1.ASN1Object#
  4236. * @function
  4237. * @return {String} hexadecimal string of ASN.1 TLV length(L)
  4238. */
  4239. this.getLengthHexFromValue = function () {
  4240. if (typeof this.hV == "undefined" || this.hV == null) {
  4241. throw "this.hV is null or undefined.";
  4242. }
  4243. if (this.hV.length % 2 == 1) {
  4244. throw "value hex must be even length: n=" + hV.length + ",v=" + this.hV;
  4245. }
  4246. var n = this.hV.length / 2;
  4247. var hN = n.toString(16);
  4248. if (hN.length % 2 == 1) {
  4249. hN = "0" + hN;
  4250. }
  4251. if (n < 128) {
  4252. return hN;
  4253. }
  4254. else {
  4255. var hNlen = hN.length / 2;
  4256. if (hNlen > 15) {
  4257. throw "ASN.1 length too long to represent by 8x: n = " + n.toString(16);
  4258. }
  4259. var head = 128 + hNlen;
  4260. return head.toString(16) + hN;
  4261. }
  4262. };
  4263. /**
  4264. * get hexadecimal string of ASN.1 TLV bytes
  4265. * @name getEncodedHex
  4266. * @memberOf KJUR.asn1.ASN1Object#
  4267. * @function
  4268. * @return {String} hexadecimal string of ASN.1 TLV
  4269. */
  4270. this.getEncodedHex = function () {
  4271. if (this.hTLV == null || this.isModified) {
  4272. this.hV = this.getFreshValueHex();
  4273. this.hL = this.getLengthHexFromValue();
  4274. this.hTLV = this.hT + this.hL + this.hV;
  4275. this.isModified = false;
  4276. //alert("first time: " + this.hTLV);
  4277. }
  4278. return this.hTLV;
  4279. };
  4280. /**
  4281. * get hexadecimal string of ASN.1 TLV value(V) bytes
  4282. * @name getValueHex
  4283. * @memberOf KJUR.asn1.ASN1Object#
  4284. * @function
  4285. * @return {String} hexadecimal string of ASN.1 TLV value(V) bytes
  4286. */
  4287. this.getValueHex = function () {
  4288. this.getEncodedHex();
  4289. return this.hV;
  4290. };
  4291. this.getFreshValueHex = function () {
  4292. return '';
  4293. };
  4294. };
  4295. // == BEGIN DERAbstractString ================================================
  4296. /**
  4297. * base class for ASN.1 DER string classes
  4298. * @name KJUR.asn1.DERAbstractString
  4299. * @class base class for ASN.1 DER string classes
  4300. * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
  4301. * @property {String} s internal string of value
  4302. * @extends KJUR.asn1.ASN1Object
  4303. * @description
  4304. * <br/>
  4305. * As for argument 'params' for constructor, you can specify one of
  4306. * following properties:
  4307. * <ul>
  4308. * <li>str - specify initial ASN.1 value(V) by a string</li>
  4309. * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
  4310. * </ul>
  4311. * NOTE: 'params' can be omitted.
  4312. */
  4313. KJUR.asn1.DERAbstractString = function (params) {
  4314. KJUR.asn1.DERAbstractString.superclass.constructor.call(this);
  4315. var s = null;
  4316. var hV = null;
  4317. /**
  4318. * get string value of this string object
  4319. * @name getString
  4320. * @memberOf KJUR.asn1.DERAbstractString#
  4321. * @function
  4322. * @return {String} string value of this string object
  4323. */
  4324. this.getString = function () {
  4325. return this.s;
  4326. };
  4327. /**
  4328. * set value by a string
  4329. * @name setString
  4330. * @memberOf KJUR.asn1.DERAbstractString#
  4331. * @function
  4332. * @param {String} newS value by a string to set
  4333. */
  4334. this.setString = function (newS) {
  4335. this.hTLV = null;
  4336. this.isModified = true;
  4337. this.s = newS;
  4338. this.hV = stohex(this.s);
  4339. };
  4340. /**
  4341. * set value by a hexadecimal string
  4342. * @name setStringHex
  4343. * @memberOf KJUR.asn1.DERAbstractString#
  4344. * @function
  4345. * @param {String} newHexString value by a hexadecimal string to set
  4346. */
  4347. this.setStringHex = function (newHexString) {
  4348. this.hTLV = null;
  4349. this.isModified = true;
  4350. this.s = null;
  4351. this.hV = newHexString;
  4352. };
  4353. this.getFreshValueHex = function () {
  4354. return this.hV;
  4355. };
  4356. if (typeof params != "undefined") {
  4357. if (typeof params == "string") {
  4358. this.setString(params);
  4359. }
  4360. else if (typeof params['str'] != "undefined") {
  4361. this.setString(params['str']);
  4362. }
  4363. else if (typeof params['hex'] != "undefined") {
  4364. this.setStringHex(params['hex']);
  4365. }
  4366. }
  4367. };
  4368. YAHOO.lang.extend(KJUR.asn1.DERAbstractString, KJUR.asn1.ASN1Object);
  4369. // == END DERAbstractString ================================================
  4370. // == BEGIN DERAbstractTime ==================================================
  4371. /**
  4372. * base class for ASN.1 DER Generalized/UTCTime class
  4373. * @name KJUR.asn1.DERAbstractTime
  4374. * @class base class for ASN.1 DER Generalized/UTCTime class
  4375. * @param {Array} params associative array of parameters (ex. {'str': '130430235959Z'})
  4376. * @extends KJUR.asn1.ASN1Object
  4377. * @description
  4378. * @see KJUR.asn1.ASN1Object - superclass
  4379. */
  4380. KJUR.asn1.DERAbstractTime = function (params) {
  4381. KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);
  4382. var s = null;
  4383. var date = null;
  4384. // --- PRIVATE METHODS --------------------
  4385. this.localDateToUTC = function (d) {
  4386. utc = d.getTime() + (d.getTimezoneOffset() * 60000);
  4387. var utcDate = new Date(utc);
  4388. return utcDate;
  4389. };
  4390. /*
  4391. * format date string by Data object
  4392. * @name formatDate
  4393. * @memberOf KJUR.asn1.AbstractTime;
  4394. * @param {Date} dateObject
  4395. * @param {string} type 'utc' or 'gen'
  4396. * @param {boolean} withMillis flag for with millisections or not
  4397. * @description
  4398. * 'withMillis' flag is supported from asn1 1.0.6.
  4399. */
  4400. this.formatDate = function (dateObject, type, withMillis) {
  4401. var pad = this.zeroPadding;
  4402. var d = this.localDateToUTC(dateObject);
  4403. var year = String(d.getFullYear());
  4404. if (type == 'utc')
  4405. year = year.substr(2, 2);
  4406. var month = pad(String(d.getMonth() + 1), 2);
  4407. var day = pad(String(d.getDate()), 2);
  4408. var hour = pad(String(d.getHours()), 2);
  4409. var min = pad(String(d.getMinutes()), 2);
  4410. var sec = pad(String(d.getSeconds()), 2);
  4411. var s = year + month + day + hour + min + sec;
  4412. if (withMillis === true) {
  4413. var millis = d.getMilliseconds();
  4414. if (millis != 0) {
  4415. var sMillis = pad(String(millis), 3);
  4416. sMillis = sMillis.replace(/[0]+$/, "");
  4417. s = s + "." + sMillis;
  4418. }
  4419. }
  4420. return s + "Z";
  4421. };
  4422. this.zeroPadding = function (s, len) {
  4423. if (s.length >= len)
  4424. return s;
  4425. return new Array(len - s.length + 1).join('0') + s;
  4426. };
  4427. // --- PUBLIC METHODS --------------------
  4428. /**
  4429. * get string value of this string object
  4430. * @name getString
  4431. * @memberOf KJUR.asn1.DERAbstractTime#
  4432. * @function
  4433. * @return {String} string value of this time object
  4434. */
  4435. this.getString = function () {
  4436. return this.s;
  4437. };
  4438. /**
  4439. * set value by a string
  4440. * @name setString
  4441. * @memberOf KJUR.asn1.DERAbstractTime#
  4442. * @function
  4443. * @param {String} newS value by a string to set such like "130430235959Z"
  4444. */
  4445. this.setString = function (newS) {
  4446. this.hTLV = null;
  4447. this.isModified = true;
  4448. this.s = newS;
  4449. this.hV = stohex(newS);
  4450. };
  4451. /**
  4452. * set value by a Date object
  4453. * @name setByDateValue
  4454. * @memberOf KJUR.asn1.DERAbstractTime#
  4455. * @function
  4456. * @param {Integer} year year of date (ex. 2013)
  4457. * @param {Integer} month month of date between 1 and 12 (ex. 12)
  4458. * @param {Integer} day day of month
  4459. * @param {Integer} hour hours of date
  4460. * @param {Integer} min minutes of date
  4461. * @param {Integer} sec seconds of date
  4462. */
  4463. this.setByDateValue = function (year, month, day, hour, min, sec) {
  4464. var dateObject = new Date(Date.UTC(year, month - 1, day, hour, min, sec, 0));
  4465. this.setByDate(dateObject);
  4466. };
  4467. this.getFreshValueHex = function () {
  4468. return this.hV;
  4469. };
  4470. };
  4471. YAHOO.lang.extend(KJUR.asn1.DERAbstractTime, KJUR.asn1.ASN1Object);
  4472. // == END DERAbstractTime ==================================================
  4473. // == BEGIN DERAbstractStructured ============================================
  4474. /**
  4475. * base class for ASN.1 DER structured class
  4476. * @name KJUR.asn1.DERAbstractStructured
  4477. * @class base class for ASN.1 DER structured class
  4478. * @property {Array} asn1Array internal array of ASN1Object
  4479. * @extends KJUR.asn1.ASN1Object
  4480. * @description
  4481. * @see KJUR.asn1.ASN1Object - superclass
  4482. */
  4483. KJUR.asn1.DERAbstractStructured = function (params) {
  4484. KJUR.asn1.DERAbstractString.superclass.constructor.call(this);
  4485. var asn1Array = null;
  4486. /**
  4487. * set value by array of ASN1Object
  4488. * @name setByASN1ObjectArray
  4489. * @memberOf KJUR.asn1.DERAbstractStructured#
  4490. * @function
  4491. * @param {array} asn1ObjectArray array of ASN1Object to set
  4492. */
  4493. this.setByASN1ObjectArray = function (asn1ObjectArray) {
  4494. this.hTLV = null;
  4495. this.isModified = true;
  4496. this.asn1Array = asn1ObjectArray;
  4497. };
  4498. /**
  4499. * append an ASN1Object to internal array
  4500. * @name appendASN1Object
  4501. * @memberOf KJUR.asn1.DERAbstractStructured#
  4502. * @function
  4503. * @param {ASN1Object} asn1Object to add
  4504. */
  4505. this.appendASN1Object = function (asn1Object) {
  4506. this.hTLV = null;
  4507. this.isModified = true;
  4508. this.asn1Array.push(asn1Object);
  4509. };
  4510. this.asn1Array = new Array();
  4511. if (typeof params != "undefined") {
  4512. if (typeof params['array'] != "undefined") {
  4513. this.asn1Array = params['array'];
  4514. }
  4515. }
  4516. };
  4517. YAHOO.lang.extend(KJUR.asn1.DERAbstractStructured, KJUR.asn1.ASN1Object);
  4518. // ********************************************************************
  4519. // ASN.1 Object Classes
  4520. // ********************************************************************
  4521. // ********************************************************************
  4522. /**
  4523. * class for ASN.1 DER Boolean
  4524. * @name KJUR.asn1.DERBoolean
  4525. * @class class for ASN.1 DER Boolean
  4526. * @extends KJUR.asn1.ASN1Object
  4527. * @description
  4528. * @see KJUR.asn1.ASN1Object - superclass
  4529. */
  4530. KJUR.asn1.DERBoolean = function () {
  4531. KJUR.asn1.DERBoolean.superclass.constructor.call(this);
  4532. this.hT = "01";
  4533. this.hTLV = "0101ff";
  4534. };
  4535. YAHOO.lang.extend(KJUR.asn1.DERBoolean, KJUR.asn1.ASN1Object);
  4536. // ********************************************************************
  4537. /**
  4538. * class for ASN.1 DER Integer
  4539. * @name KJUR.asn1.DERInteger
  4540. * @class class for ASN.1 DER Integer
  4541. * @extends KJUR.asn1.ASN1Object
  4542. * @description
  4543. * <br/>
  4544. * As for argument 'params' for constructor, you can specify one of
  4545. * following properties:
  4546. * <ul>
  4547. * <li>int - specify initial ASN.1 value(V) by integer value</li>
  4548. * <li>bigint - specify initial ASN.1 value(V) by BigInteger object</li>
  4549. * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
  4550. * </ul>
  4551. * NOTE: 'params' can be omitted.
  4552. */
  4553. KJUR.asn1.DERInteger = function (params) {
  4554. KJUR.asn1.DERInteger.superclass.constructor.call(this);
  4555. this.hT = "02";
  4556. /**
  4557. * set value by Tom Wu's BigInteger object
  4558. * @name setByBigInteger
  4559. * @memberOf KJUR.asn1.DERInteger#
  4560. * @function
  4561. * @param {BigInteger} bigIntegerValue to set
  4562. */
  4563. this.setByBigInteger = function (bigIntegerValue) {
  4564. this.hTLV = null;
  4565. this.isModified = true;
  4566. this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue);
  4567. };
  4568. /**
  4569. * set value by integer value
  4570. * @name setByInteger
  4571. * @memberOf KJUR.asn1.DERInteger
  4572. * @function
  4573. * @param {Integer} integer value to set
  4574. */
  4575. this.setByInteger = function (intValue) {
  4576. var bi = new BigInteger(String(intValue), 10);
  4577. this.setByBigInteger(bi);
  4578. };
  4579. /**
  4580. * set value by integer value
  4581. * @name setValueHex
  4582. * @memberOf KJUR.asn1.DERInteger#
  4583. * @function
  4584. * @param {String} hexadecimal string of integer value
  4585. * @description
  4586. * <br/>
  4587. * NOTE: Value shall be represented by minimum octet length of
  4588. * two's complement representation.
  4589. * @example
  4590. * new KJUR.asn1.DERInteger(123);
  4591. * new KJUR.asn1.DERInteger({'int': 123});
  4592. * new KJUR.asn1.DERInteger({'hex': '1fad'});
  4593. */
  4594. this.setValueHex = function (newHexString) {
  4595. this.hV = newHexString;
  4596. };
  4597. this.getFreshValueHex = function () {
  4598. return this.hV;
  4599. };
  4600. if (typeof params != "undefined") {
  4601. if (typeof params['bigint'] != "undefined") {
  4602. this.setByBigInteger(params['bigint']);
  4603. }
  4604. else if (typeof params['int'] != "undefined") {
  4605. this.setByInteger(params['int']);
  4606. }
  4607. else if (typeof params == "number") {
  4608. this.setByInteger(params);
  4609. }
  4610. else if (typeof params['hex'] != "undefined") {
  4611. this.setValueHex(params['hex']);
  4612. }
  4613. }
  4614. };
  4615. YAHOO.lang.extend(KJUR.asn1.DERInteger, KJUR.asn1.ASN1Object);
  4616. // ********************************************************************
  4617. /**
  4618. * class for ASN.1 DER encoded BitString primitive
  4619. * @name KJUR.asn1.DERBitString
  4620. * @class class for ASN.1 DER encoded BitString primitive
  4621. * @extends KJUR.asn1.ASN1Object
  4622. * @description
  4623. * <br/>
  4624. * As for argument 'params' for constructor, you can specify one of
  4625. * following properties:
  4626. * <ul>
  4627. * <li>bin - specify binary string (ex. '10111')</li>
  4628. * <li>array - specify array of boolean (ex. [true,false,true,true])</li>
  4629. * <li>hex - specify hexadecimal string of ASN.1 value(V) including unused bits</li>
  4630. * <li>obj - specify {@link KJUR.asn1.ASN1Util.newObject}
  4631. * argument for "BitString encapsulates" structure.</li>
  4632. * </ul>
  4633. * NOTE1: 'params' can be omitted.<br/>
  4634. * NOTE2: 'obj' parameter have been supported since
  4635. * asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).<br/>
  4636. * @example
  4637. * // default constructor
  4638. * o = new KJUR.asn1.DERBitString();
  4639. * // initialize with binary string
  4640. * o = new KJUR.asn1.DERBitString({bin: "1011"});
  4641. * // initialize with boolean array
  4642. * o = new KJUR.asn1.DERBitString({array: [true,false,true,true]});
  4643. * // initialize with hexadecimal string (04 is unused bits)
  4644. * o = new KJUR.asn1.DEROctetString({hex: "04bac0"});
  4645. * // initialize with ASN1Util.newObject argument for encapsulated
  4646. * o = new KJUR.asn1.DERBitString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}});
  4647. * // above generates a ASN.1 data like this:
  4648. * // BIT STRING, encapsulates {
  4649. * // SEQUENCE {
  4650. * // INTEGER 3
  4651. * // PrintableString 'aaa'
  4652. * // }
  4653. * // }
  4654. */
  4655. KJUR.asn1.DERBitString = function (params) {
  4656. if (params !== undefined && typeof params.obj !== "undefined") {
  4657. var o = KJUR.asn1.ASN1Util.newObject(params.obj);
  4658. params.hex = "00" + o.getEncodedHex();
  4659. }
  4660. KJUR.asn1.DERBitString.superclass.constructor.call(this);
  4661. this.hT = "03";
  4662. /**
  4663. * set ASN.1 value(V) by a hexadecimal string including unused bits
  4664. * @name setHexValueIncludingUnusedBits
  4665. * @memberOf KJUR.asn1.DERBitString#
  4666. * @function
  4667. * @param {String} newHexStringIncludingUnusedBits
  4668. */
  4669. this.setHexValueIncludingUnusedBits = function (newHexStringIncludingUnusedBits) {
  4670. this.hTLV = null;
  4671. this.isModified = true;
  4672. this.hV = newHexStringIncludingUnusedBits;
  4673. };
  4674. /**
  4675. * set ASN.1 value(V) by unused bit and hexadecimal string of value
  4676. * @name setUnusedBitsAndHexValue
  4677. * @memberOf KJUR.asn1.DERBitString#
  4678. * @function
  4679. * @param {Integer} unusedBits
  4680. * @param {String} hValue
  4681. */
  4682. this.setUnusedBitsAndHexValue = function (unusedBits, hValue) {
  4683. if (unusedBits < 0 || 7 < unusedBits) {
  4684. throw "unused bits shall be from 0 to 7: u = " + unusedBits;
  4685. }
  4686. var hUnusedBits = "0" + unusedBits;
  4687. this.hTLV = null;
  4688. this.isModified = true;
  4689. this.hV = hUnusedBits + hValue;
  4690. };
  4691. /**
  4692. * set ASN.1 DER BitString by binary string<br/>
  4693. * @name setByBinaryString
  4694. * @memberOf KJUR.asn1.DERBitString#
  4695. * @function
  4696. * @param {String} binaryString binary value string (i.e. '10111')
  4697. * @description
  4698. * Its unused bits will be calculated automatically by length of
  4699. * 'binaryValue'. <br/>
  4700. * NOTE: Trailing zeros '0' will be ignored.
  4701. * @example
  4702. * o = new KJUR.asn1.DERBitString();
  4703. * o.setByBooleanArray("01011");
  4704. */
  4705. this.setByBinaryString = function (binaryString) {
  4706. binaryString = binaryString.replace(/0+$/, '');
  4707. var unusedBits = 8 - binaryString.length % 8;
  4708. if (unusedBits == 8)
  4709. unusedBits = 0;
  4710. for (var i = 0; i <= unusedBits; i++) {
  4711. binaryString += '0';
  4712. }
  4713. var h = '';
  4714. for (var i = 0; i < binaryString.length - 1; i += 8) {
  4715. var b = binaryString.substr(i, 8);
  4716. var x = parseInt(b, 2).toString(16);
  4717. if (x.length == 1)
  4718. x = '0' + x;
  4719. h += x;
  4720. }
  4721. this.hTLV = null;
  4722. this.isModified = true;
  4723. this.hV = '0' + unusedBits + h;
  4724. };
  4725. /**
  4726. * set ASN.1 TLV value(V) by an array of boolean<br/>
  4727. * @name setByBooleanArray
  4728. * @memberOf KJUR.asn1.DERBitString#
  4729. * @function
  4730. * @param {array} booleanArray array of boolean (ex. [true, false, true])
  4731. * @description
  4732. * NOTE: Trailing falses will be ignored in the ASN.1 DER Object.
  4733. * @example
  4734. * o = new KJUR.asn1.DERBitString();
  4735. * o.setByBooleanArray([false, true, false, true, true]);
  4736. */
  4737. this.setByBooleanArray = function (booleanArray) {
  4738. var s = '';
  4739. for (var i = 0; i < booleanArray.length; i++) {
  4740. if (booleanArray[i] == true) {
  4741. s += '1';
  4742. }
  4743. else {
  4744. s += '0';
  4745. }
  4746. }
  4747. this.setByBinaryString(s);
  4748. };
  4749. /**
  4750. * generate an array of falses with specified length<br/>
  4751. * @name newFalseArray
  4752. * @memberOf KJUR.asn1.DERBitString
  4753. * @function
  4754. * @param {Integer} nLength length of array to generate
  4755. * @return {array} array of boolean falses
  4756. * @description
  4757. * This static method may be useful to initialize boolean array.
  4758. * @example
  4759. * o = new KJUR.asn1.DERBitString();
  4760. * o.newFalseArray(3) &rarr; [false, false, false]
  4761. */
  4762. this.newFalseArray = function (nLength) {
  4763. var a = new Array(nLength);
  4764. for (var i = 0; i < nLength; i++) {
  4765. a[i] = false;
  4766. }
  4767. return a;
  4768. };
  4769. this.getFreshValueHex = function () {
  4770. return this.hV;
  4771. };
  4772. if (typeof params != "undefined") {
  4773. if (typeof params == "string" && params.toLowerCase().match(/^[0-9a-f]+$/)) {
  4774. this.setHexValueIncludingUnusedBits(params);
  4775. }
  4776. else if (typeof params['hex'] != "undefined") {
  4777. this.setHexValueIncludingUnusedBits(params['hex']);
  4778. }
  4779. else if (typeof params['bin'] != "undefined") {
  4780. this.setByBinaryString(params['bin']);
  4781. }
  4782. else if (typeof params['array'] != "undefined") {
  4783. this.setByBooleanArray(params['array']);
  4784. }
  4785. }
  4786. };
  4787. YAHOO.lang.extend(KJUR.asn1.DERBitString, KJUR.asn1.ASN1Object);
  4788. // ********************************************************************
  4789. /**
  4790. * class for ASN.1 DER OctetString<br/>
  4791. * @name KJUR.asn1.DEROctetString
  4792. * @class class for ASN.1 DER OctetString
  4793. * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
  4794. * @extends KJUR.asn1.DERAbstractString
  4795. * @description
  4796. * This class provides ASN.1 OctetString simple type.<br/>
  4797. * Supported "params" attributes are:
  4798. * <ul>
  4799. * <li>str - to set a string as a value</li>
  4800. * <li>hex - to set a hexadecimal string as a value</li>
  4801. * <li>obj - to set a encapsulated ASN.1 value by JSON object
  4802. * which is defined in {@link KJUR.asn1.ASN1Util.newObject}</li>
  4803. * </ul>
  4804. * NOTE: A parameter 'obj' have been supported
  4805. * for "OCTET STRING, encapsulates" structure.
  4806. * since asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).
  4807. * @see KJUR.asn1.DERAbstractString - superclass
  4808. * @example
  4809. * // default constructor
  4810. * o = new KJUR.asn1.DEROctetString();
  4811. * // initialize with string
  4812. * o = new KJUR.asn1.DEROctetString({str: "aaa"});
  4813. * // initialize with hexadecimal string
  4814. * o = new KJUR.asn1.DEROctetString({hex: "616161"});
  4815. * // initialize with ASN1Util.newObject argument
  4816. * o = new KJUR.asn1.DEROctetString({obj: {seq: [{int: 3}, {prnstr: 'aaa'}]}});
  4817. * // above generates a ASN.1 data like this:
  4818. * // OCTET STRING, encapsulates {
  4819. * // SEQUENCE {
  4820. * // INTEGER 3
  4821. * // PrintableString 'aaa'
  4822. * // }
  4823. * // }
  4824. */
  4825. KJUR.asn1.DEROctetString = function (params) {
  4826. if (params !== undefined && typeof params.obj !== "undefined") {
  4827. var o = KJUR.asn1.ASN1Util.newObject(params.obj);
  4828. params.hex = o.getEncodedHex();
  4829. }
  4830. KJUR.asn1.DEROctetString.superclass.constructor.call(this, params);
  4831. this.hT = "04";
  4832. };
  4833. YAHOO.lang.extend(KJUR.asn1.DEROctetString, KJUR.asn1.DERAbstractString);
  4834. // ********************************************************************
  4835. /**
  4836. * class for ASN.1 DER Null
  4837. * @name KJUR.asn1.DERNull
  4838. * @class class for ASN.1 DER Null
  4839. * @extends KJUR.asn1.ASN1Object
  4840. * @description
  4841. * @see KJUR.asn1.ASN1Object - superclass
  4842. */
  4843. KJUR.asn1.DERNull = function () {
  4844. KJUR.asn1.DERNull.superclass.constructor.call(this);
  4845. this.hT = "05";
  4846. this.hTLV = "0500";
  4847. };
  4848. YAHOO.lang.extend(KJUR.asn1.DERNull, KJUR.asn1.ASN1Object);
  4849. // ********************************************************************
  4850. /**
  4851. * class for ASN.1 DER ObjectIdentifier
  4852. * @name KJUR.asn1.DERObjectIdentifier
  4853. * @class class for ASN.1 DER ObjectIdentifier
  4854. * @param {Array} params associative array of parameters (ex. {'oid': '2.5.4.5'})
  4855. * @extends KJUR.asn1.ASN1Object
  4856. * @description
  4857. * <br/>
  4858. * As for argument 'params' for constructor, you can specify one of
  4859. * following properties:
  4860. * <ul>
  4861. * <li>oid - specify initial ASN.1 value(V) by a oid string (ex. 2.5.4.13)</li>
  4862. * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
  4863. * </ul>
  4864. * NOTE: 'params' can be omitted.
  4865. */
  4866. KJUR.asn1.DERObjectIdentifier = function (params) {
  4867. var itox = function (i) {
  4868. var h = i.toString(16);
  4869. if (h.length == 1)
  4870. h = '0' + h;
  4871. return h;
  4872. };
  4873. var roidtox = function (roid) {
  4874. var h = '';
  4875. var bi = new BigInteger(roid, 10);
  4876. var b = bi.toString(2);
  4877. var padLen = 7 - b.length % 7;
  4878. if (padLen == 7)
  4879. padLen = 0;
  4880. var bPad = '';
  4881. for (var i = 0; i < padLen; i++)
  4882. bPad += '0';
  4883. b = bPad + b;
  4884. for (var i = 0; i < b.length - 1; i += 7) {
  4885. var b8 = b.substr(i, 7);
  4886. if (i != b.length - 7)
  4887. b8 = '1' + b8;
  4888. h += itox(parseInt(b8, 2));
  4889. }
  4890. return h;
  4891. };
  4892. KJUR.asn1.DERObjectIdentifier.superclass.constructor.call(this);
  4893. this.hT = "06";
  4894. /**
  4895. * set value by a hexadecimal string
  4896. * @name setValueHex
  4897. * @memberOf KJUR.asn1.DERObjectIdentifier#
  4898. * @function
  4899. * @param {String} newHexString hexadecimal value of OID bytes
  4900. */
  4901. this.setValueHex = function (newHexString) {
  4902. this.hTLV = null;
  4903. this.isModified = true;
  4904. this.s = null;
  4905. this.hV = newHexString;
  4906. };
  4907. /**
  4908. * set value by a OID string<br/>
  4909. * @name setValueOidString
  4910. * @memberOf KJUR.asn1.DERObjectIdentifier#
  4911. * @function
  4912. * @param {String} oidString OID string (ex. 2.5.4.13)
  4913. * @example
  4914. * o = new KJUR.asn1.DERObjectIdentifier();
  4915. * o.setValueOidString("2.5.4.13");
  4916. */
  4917. this.setValueOidString = function (oidString) {
  4918. if (!oidString.match(/^[0-9.]+$/)) {
  4919. throw "malformed oid string: " + oidString;
  4920. }
  4921. var h = '';
  4922. var a = oidString.split('.');
  4923. var i0 = parseInt(a[0]) * 40 + parseInt(a[1]);
  4924. h += itox(i0);
  4925. a.splice(0, 2);
  4926. for (var i = 0; i < a.length; i++) {
  4927. h += roidtox(a[i]);
  4928. }
  4929. this.hTLV = null;
  4930. this.isModified = true;
  4931. this.s = null;
  4932. this.hV = h;
  4933. };
  4934. /**
  4935. * set value by a OID name
  4936. * @name setValueName
  4937. * @memberOf KJUR.asn1.DERObjectIdentifier#
  4938. * @function
  4939. * @param {String} oidName OID name (ex. 'serverAuth')
  4940. * @since 1.0.1
  4941. * @description
  4942. * OID name shall be defined in 'KJUR.asn1.x509.OID.name2oidList'.
  4943. * Otherwise raise error.
  4944. * @example
  4945. * o = new KJUR.asn1.DERObjectIdentifier();
  4946. * o.setValueName("serverAuth");
  4947. */
  4948. this.setValueName = function (oidName) {
  4949. var oid = KJUR.asn1.x509.OID.name2oid(oidName);
  4950. if (oid !== '') {
  4951. this.setValueOidString(oid);
  4952. }
  4953. else {
  4954. throw "DERObjectIdentifier oidName undefined: " + oidName;
  4955. }
  4956. };
  4957. this.getFreshValueHex = function () {
  4958. return this.hV;
  4959. };
  4960. if (params !== undefined) {
  4961. if (typeof params === "string") {
  4962. if (params.match(/^[0-2].[0-9.]+$/)) {
  4963. this.setValueOidString(params);
  4964. }
  4965. else {
  4966. this.setValueName(params);
  4967. }
  4968. }
  4969. else if (params.oid !== undefined) {
  4970. this.setValueOidString(params.oid);
  4971. }
  4972. else if (params.hex !== undefined) {
  4973. this.setValueHex(params.hex);
  4974. }
  4975. else if (params.name !== undefined) {
  4976. this.setValueName(params.name);
  4977. }
  4978. }
  4979. };
  4980. YAHOO.lang.extend(KJUR.asn1.DERObjectIdentifier, KJUR.asn1.ASN1Object);
  4981. // ********************************************************************
  4982. /**
  4983. * class for ASN.1 DER Enumerated
  4984. * @name KJUR.asn1.DEREnumerated
  4985. * @class class for ASN.1 DER Enumerated
  4986. * @extends KJUR.asn1.ASN1Object
  4987. * @description
  4988. * <br/>
  4989. * As for argument 'params' for constructor, you can specify one of
  4990. * following properties:
  4991. * <ul>
  4992. * <li>int - specify initial ASN.1 value(V) by integer value</li>
  4993. * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
  4994. * </ul>
  4995. * NOTE: 'params' can be omitted.
  4996. * @example
  4997. * new KJUR.asn1.DEREnumerated(123);
  4998. * new KJUR.asn1.DEREnumerated({int: 123});
  4999. * new KJUR.asn1.DEREnumerated({hex: '1fad'});
  5000. */
  5001. KJUR.asn1.DEREnumerated = function (params) {
  5002. KJUR.asn1.DEREnumerated.superclass.constructor.call(this);
  5003. this.hT = "0a";
  5004. /**
  5005. * set value by Tom Wu's BigInteger object
  5006. * @name setByBigInteger
  5007. * @memberOf KJUR.asn1.DEREnumerated#
  5008. * @function
  5009. * @param {BigInteger} bigIntegerValue to set
  5010. */
  5011. this.setByBigInteger = function (bigIntegerValue) {
  5012. this.hTLV = null;
  5013. this.isModified = true;
  5014. this.hV = KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue);
  5015. };
  5016. /**
  5017. * set value by integer value
  5018. * @name setByInteger
  5019. * @memberOf KJUR.asn1.DEREnumerated#
  5020. * @function
  5021. * @param {Integer} integer value to set
  5022. */
  5023. this.setByInteger = function (intValue) {
  5024. var bi = new BigInteger(String(intValue), 10);
  5025. this.setByBigInteger(bi);
  5026. };
  5027. /**
  5028. * set value by integer value
  5029. * @name setValueHex
  5030. * @memberOf KJUR.asn1.DEREnumerated#
  5031. * @function
  5032. * @param {String} hexadecimal string of integer value
  5033. * @description
  5034. * <br/>
  5035. * NOTE: Value shall be represented by minimum octet length of
  5036. * two's complement representation.
  5037. */
  5038. this.setValueHex = function (newHexString) {
  5039. this.hV = newHexString;
  5040. };
  5041. this.getFreshValueHex = function () {
  5042. return this.hV;
  5043. };
  5044. if (typeof params != "undefined") {
  5045. if (typeof params['int'] != "undefined") {
  5046. this.setByInteger(params['int']);
  5047. }
  5048. else if (typeof params == "number") {
  5049. this.setByInteger(params);
  5050. }
  5051. else if (typeof params['hex'] != "undefined") {
  5052. this.setValueHex(params['hex']);
  5053. }
  5054. }
  5055. };
  5056. YAHOO.lang.extend(KJUR.asn1.DEREnumerated, KJUR.asn1.ASN1Object);
  5057. // ********************************************************************
  5058. /**
  5059. * class for ASN.1 DER UTF8String
  5060. * @name KJUR.asn1.DERUTF8String
  5061. * @class class for ASN.1 DER UTF8String
  5062. * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
  5063. * @extends KJUR.asn1.DERAbstractString
  5064. * @description
  5065. * @see KJUR.asn1.DERAbstractString - superclass
  5066. */
  5067. KJUR.asn1.DERUTF8String = function (params) {
  5068. KJUR.asn1.DERUTF8String.superclass.constructor.call(this, params);
  5069. this.hT = "0c";
  5070. };
  5071. YAHOO.lang.extend(KJUR.asn1.DERUTF8String, KJUR.asn1.DERAbstractString);
  5072. // ********************************************************************
  5073. /**
  5074. * class for ASN.1 DER NumericString
  5075. * @name KJUR.asn1.DERNumericString
  5076. * @class class for ASN.1 DER NumericString
  5077. * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
  5078. * @extends KJUR.asn1.DERAbstractString
  5079. * @description
  5080. * @see KJUR.asn1.DERAbstractString - superclass
  5081. */
  5082. KJUR.asn1.DERNumericString = function (params) {
  5083. KJUR.asn1.DERNumericString.superclass.constructor.call(this, params);
  5084. this.hT = "12";
  5085. };
  5086. YAHOO.lang.extend(KJUR.asn1.DERNumericString, KJUR.asn1.DERAbstractString);
  5087. // ********************************************************************
  5088. /**
  5089. * class for ASN.1 DER PrintableString
  5090. * @name KJUR.asn1.DERPrintableString
  5091. * @class class for ASN.1 DER PrintableString
  5092. * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
  5093. * @extends KJUR.asn1.DERAbstractString
  5094. * @description
  5095. * @see KJUR.asn1.DERAbstractString - superclass
  5096. */
  5097. KJUR.asn1.DERPrintableString = function (params) {
  5098. KJUR.asn1.DERPrintableString.superclass.constructor.call(this, params);
  5099. this.hT = "13";
  5100. };
  5101. YAHOO.lang.extend(KJUR.asn1.DERPrintableString, KJUR.asn1.DERAbstractString);
  5102. // ********************************************************************
  5103. /**
  5104. * class for ASN.1 DER TeletexString
  5105. * @name KJUR.asn1.DERTeletexString
  5106. * @class class for ASN.1 DER TeletexString
  5107. * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
  5108. * @extends KJUR.asn1.DERAbstractString
  5109. * @description
  5110. * @see KJUR.asn1.DERAbstractString - superclass
  5111. */
  5112. KJUR.asn1.DERTeletexString = function (params) {
  5113. KJUR.asn1.DERTeletexString.superclass.constructor.call(this, params);
  5114. this.hT = "14";
  5115. };
  5116. YAHOO.lang.extend(KJUR.asn1.DERTeletexString, KJUR.asn1.DERAbstractString);
  5117. // ********************************************************************
  5118. /**
  5119. * class for ASN.1 DER IA5String
  5120. * @name KJUR.asn1.DERIA5String
  5121. * @class class for ASN.1 DER IA5String
  5122. * @param {Array} params associative array of parameters (ex. {'str': 'aaa'})
  5123. * @extends KJUR.asn1.DERAbstractString
  5124. * @description
  5125. * @see KJUR.asn1.DERAbstractString - superclass
  5126. */
  5127. KJUR.asn1.DERIA5String = function (params) {
  5128. KJUR.asn1.DERIA5String.superclass.constructor.call(this, params);
  5129. this.hT = "16";
  5130. };
  5131. YAHOO.lang.extend(KJUR.asn1.DERIA5String, KJUR.asn1.DERAbstractString);
  5132. // ********************************************************************
  5133. /**
  5134. * class for ASN.1 DER UTCTime
  5135. * @name KJUR.asn1.DERUTCTime
  5136. * @class class for ASN.1 DER UTCTime
  5137. * @param {Array} params associative array of parameters (ex. {'str': '130430235959Z'})
  5138. * @extends KJUR.asn1.DERAbstractTime
  5139. * @description
  5140. * <br/>
  5141. * As for argument 'params' for constructor, you can specify one of
  5142. * following properties:
  5143. * <ul>
  5144. * <li>str - specify initial ASN.1 value(V) by a string (ex.'130430235959Z')</li>
  5145. * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
  5146. * <li>date - specify Date object.</li>
  5147. * </ul>
  5148. * NOTE: 'params' can be omitted.
  5149. * <h4>EXAMPLES</h4>
  5150. * @example
  5151. * d1 = new KJUR.asn1.DERUTCTime();
  5152. * d1.setString('130430125959Z');
  5153. *
  5154. * d2 = new KJUR.asn1.DERUTCTime({'str': '130430125959Z'});
  5155. * d3 = new KJUR.asn1.DERUTCTime({'date': new Date(Date.UTC(2015, 0, 31, 0, 0, 0, 0))});
  5156. * d4 = new KJUR.asn1.DERUTCTime('130430125959Z');
  5157. */
  5158. KJUR.asn1.DERUTCTime = function (params) {
  5159. KJUR.asn1.DERUTCTime.superclass.constructor.call(this, params);
  5160. this.hT = "17";
  5161. /**
  5162. * set value by a Date object<br/>
  5163. * @name setByDate
  5164. * @memberOf KJUR.asn1.DERUTCTime#
  5165. * @function
  5166. * @param {Date} dateObject Date object to set ASN.1 value(V)
  5167. * @example
  5168. * o = new KJUR.asn1.DERUTCTime();
  5169. * o.setByDate(new Date("2016/12/31"));
  5170. */
  5171. this.setByDate = function (dateObject) {
  5172. this.hTLV = null;
  5173. this.isModified = true;
  5174. this.date = dateObject;
  5175. this.s = this.formatDate(this.date, 'utc');
  5176. this.hV = stohex(this.s);
  5177. };
  5178. this.getFreshValueHex = function () {
  5179. if (typeof this.date == "undefined" && typeof this.s == "undefined") {
  5180. this.date = new Date();
  5181. this.s = this.formatDate(this.date, 'utc');
  5182. this.hV = stohex(this.s);
  5183. }
  5184. return this.hV;
  5185. };
  5186. if (params !== undefined) {
  5187. if (params.str !== undefined) {
  5188. this.setString(params.str);
  5189. }
  5190. else if (typeof params == "string" && params.match(/^[0-9]{12}Z$/)) {
  5191. this.setString(params);
  5192. }
  5193. else if (params.hex !== undefined) {
  5194. this.setStringHex(params.hex);
  5195. }
  5196. else if (params.date !== undefined) {
  5197. this.setByDate(params.date);
  5198. }
  5199. }
  5200. };
  5201. YAHOO.lang.extend(KJUR.asn1.DERUTCTime, KJUR.asn1.DERAbstractTime);
  5202. // ********************************************************************
  5203. /**
  5204. * class for ASN.1 DER GeneralizedTime
  5205. * @name KJUR.asn1.DERGeneralizedTime
  5206. * @class class for ASN.1 DER GeneralizedTime
  5207. * @param {Array} params associative array of parameters (ex. {'str': '20130430235959Z'})
  5208. * @property {Boolean} withMillis flag to show milliseconds or not
  5209. * @extends KJUR.asn1.DERAbstractTime
  5210. * @description
  5211. * <br/>
  5212. * As for argument 'params' for constructor, you can specify one of
  5213. * following properties:
  5214. * <ul>
  5215. * <li>str - specify initial ASN.1 value(V) by a string (ex.'20130430235959Z')</li>
  5216. * <li>hex - specify initial ASN.1 value(V) by a hexadecimal string</li>
  5217. * <li>date - specify Date object.</li>
  5218. * <li>millis - specify flag to show milliseconds (from 1.0.6)</li>
  5219. * </ul>
  5220. * NOTE1: 'params' can be omitted.
  5221. * NOTE2: 'withMillis' property is supported from asn1 1.0.6.
  5222. */
  5223. KJUR.asn1.DERGeneralizedTime = function (params) {
  5224. KJUR.asn1.DERGeneralizedTime.superclass.constructor.call(this, params);
  5225. this.hT = "18";
  5226. this.withMillis = false;
  5227. /**
  5228. * set value by a Date object
  5229. * @name setByDate
  5230. * @memberOf KJUR.asn1.DERGeneralizedTime#
  5231. * @function
  5232. * @param {Date} dateObject Date object to set ASN.1 value(V)
  5233. * @example
  5234. * When you specify UTC time, use 'Date.UTC' method like this:<br/>
  5235. * o1 = new DERUTCTime();
  5236. * o1.setByDate(date);
  5237. *
  5238. * date = new Date(Date.UTC(2015, 0, 31, 23, 59, 59, 0)); #2015JAN31 23:59:59
  5239. */
  5240. this.setByDate = function (dateObject) {
  5241. this.hTLV = null;
  5242. this.isModified = true;
  5243. this.date = dateObject;
  5244. this.s = this.formatDate(this.date, 'gen', this.withMillis);
  5245. this.hV = stohex(this.s);
  5246. };
  5247. this.getFreshValueHex = function () {
  5248. if (this.date === undefined && this.s === undefined) {
  5249. this.date = new Date();
  5250. this.s = this.formatDate(this.date, 'gen', this.withMillis);
  5251. this.hV = stohex(this.s);
  5252. }
  5253. return this.hV;
  5254. };
  5255. if (params !== undefined) {
  5256. if (params.str !== undefined) {
  5257. this.setString(params.str);
  5258. }
  5259. else if (typeof params == "string" && params.match(/^[0-9]{14}Z$/)) {
  5260. this.setString(params);
  5261. }
  5262. else if (params.hex !== undefined) {
  5263. this.setStringHex(params.hex);
  5264. }
  5265. else if (params.date !== undefined) {
  5266. this.setByDate(params.date);
  5267. }
  5268. if (params.millis === true) {
  5269. this.withMillis = true;
  5270. }
  5271. }
  5272. };
  5273. YAHOO.lang.extend(KJUR.asn1.DERGeneralizedTime, KJUR.asn1.DERAbstractTime);
  5274. // ********************************************************************
  5275. /**
  5276. * class for ASN.1 DER Sequence
  5277. * @name KJUR.asn1.DERSequence
  5278. * @class class for ASN.1 DER Sequence
  5279. * @extends KJUR.asn1.DERAbstractStructured
  5280. * @description
  5281. * <br/>
  5282. * As for argument 'params' for constructor, you can specify one of
  5283. * following properties:
  5284. * <ul>
  5285. * <li>array - specify array of ASN1Object to set elements of content</li>
  5286. * </ul>
  5287. * NOTE: 'params' can be omitted.
  5288. */
  5289. KJUR.asn1.DERSequence = function (params) {
  5290. KJUR.asn1.DERSequence.superclass.constructor.call(this, params);
  5291. this.hT = "30";
  5292. this.getFreshValueHex = function () {
  5293. var h = '';
  5294. for (var i = 0; i < this.asn1Array.length; i++) {
  5295. var asn1Obj = this.asn1Array[i];
  5296. h += asn1Obj.getEncodedHex();
  5297. }
  5298. this.hV = h;
  5299. return this.hV;
  5300. };
  5301. };
  5302. YAHOO.lang.extend(KJUR.asn1.DERSequence, KJUR.asn1.DERAbstractStructured);
  5303. // ********************************************************************
  5304. /**
  5305. * class for ASN.1 DER Set
  5306. * @name KJUR.asn1.DERSet
  5307. * @class class for ASN.1 DER Set
  5308. * @extends KJUR.asn1.DERAbstractStructured
  5309. * @description
  5310. * <br/>
  5311. * As for argument 'params' for constructor, you can specify one of
  5312. * following properties:
  5313. * <ul>
  5314. * <li>array - specify array of ASN1Object to set elements of content</li>
  5315. * <li>sortflag - flag for sort (default: true). ASN.1 BER is not sorted in 'SET OF'.</li>
  5316. * </ul>
  5317. * NOTE1: 'params' can be omitted.<br/>
  5318. * NOTE2: sortflag is supported since 1.0.5.
  5319. */
  5320. KJUR.asn1.DERSet = function (params) {
  5321. KJUR.asn1.DERSet.superclass.constructor.call(this, params);
  5322. this.hT = "31";
  5323. this.sortFlag = true; // item shall be sorted only in ASN.1 DER
  5324. this.getFreshValueHex = function () {
  5325. var a = new Array();
  5326. for (var i = 0; i < this.asn1Array.length; i++) {
  5327. var asn1Obj = this.asn1Array[i];
  5328. a.push(asn1Obj.getEncodedHex());
  5329. }
  5330. if (this.sortFlag == true)
  5331. a.sort();
  5332. this.hV = a.join('');
  5333. return this.hV;
  5334. };
  5335. if (typeof params != "undefined") {
  5336. if (typeof params.sortflag != "undefined" &&
  5337. params.sortflag == false)
  5338. this.sortFlag = false;
  5339. }
  5340. };
  5341. YAHOO.lang.extend(KJUR.asn1.DERSet, KJUR.asn1.DERAbstractStructured);
  5342. // ********************************************************************
  5343. /**
  5344. * class for ASN.1 DER TaggedObject
  5345. * @name KJUR.asn1.DERTaggedObject
  5346. * @class class for ASN.1 DER TaggedObject
  5347. * @extends KJUR.asn1.ASN1Object
  5348. * @description
  5349. * <br/>
  5350. * Parameter 'tagNoNex' is ASN.1 tag(T) value for this object.
  5351. * For example, if you find '[1]' tag in a ASN.1 dump,
  5352. * 'tagNoHex' will be 'a1'.
  5353. * <br/>
  5354. * As for optional argument 'params' for constructor, you can specify *ANY* of
  5355. * following properties:
  5356. * <ul>
  5357. * <li>explicit - specify true if this is explicit tag otherwise false
  5358. * (default is 'true').</li>
  5359. * <li>tag - specify tag (default is 'a0' which means [0])</li>
  5360. * <li>obj - specify ASN1Object which is tagged</li>
  5361. * </ul>
  5362. * @example
  5363. * d1 = new KJUR.asn1.DERUTF8String({'str':'a'});
  5364. * d2 = new KJUR.asn1.DERTaggedObject({'obj': d1});
  5365. * hex = d2.getEncodedHex();
  5366. */
  5367. KJUR.asn1.DERTaggedObject = function (params) {
  5368. KJUR.asn1.DERTaggedObject.superclass.constructor.call(this);
  5369. this.hT = "a0";
  5370. this.hV = '';
  5371. this.isExplicit = true;
  5372. this.asn1Object = null;
  5373. /**
  5374. * set value by an ASN1Object
  5375. * @name setString
  5376. * @memberOf KJUR.asn1.DERTaggedObject#
  5377. * @function
  5378. * @param {Boolean} isExplicitFlag flag for explicit/implicit tag
  5379. * @param {Integer} tagNoHex hexadecimal string of ASN.1 tag
  5380. * @param {ASN1Object} asn1Object ASN.1 to encapsulate
  5381. */
  5382. this.setASN1Object = function (isExplicitFlag, tagNoHex, asn1Object) {
  5383. this.hT = tagNoHex;
  5384. this.isExplicit = isExplicitFlag;
  5385. this.asn1Object = asn1Object;
  5386. if (this.isExplicit) {
  5387. this.hV = this.asn1Object.getEncodedHex();
  5388. this.hTLV = null;
  5389. this.isModified = true;
  5390. }
  5391. else {
  5392. this.hV = null;
  5393. this.hTLV = asn1Object.getEncodedHex();
  5394. this.hTLV = this.hTLV.replace(/^../, tagNoHex);
  5395. this.isModified = false;
  5396. }
  5397. };
  5398. this.getFreshValueHex = function () {
  5399. return this.hV;
  5400. };
  5401. if (typeof params != "undefined") {
  5402. if (typeof params['tag'] != "undefined") {
  5403. this.hT = params['tag'];
  5404. }
  5405. if (typeof params['explicit'] != "undefined") {
  5406. this.isExplicit = params['explicit'];
  5407. }
  5408. if (typeof params['obj'] != "undefined") {
  5409. this.asn1Object = params['obj'];
  5410. this.setASN1Object(this.isExplicit, this.hT, this.asn1Object);
  5411. }
  5412. }
  5413. };
  5414. YAHOO.lang.extend(KJUR.asn1.DERTaggedObject, KJUR.asn1.ASN1Object);
  5415. }, function(modId) { var map = {"../jsbn/jsbn":1709513243604,"./yahoo":1709513243608}; return __REQUIRE__(map[modId], modId); })
  5416. __DEFINE__(1709513243608, function(require, module, exports) {
  5417. /*!
  5418. Copyright (c) 2011, Yahoo! Inc. All rights reserved.
  5419. Code licensed under the BSD License:
  5420. http://developer.yahoo.com/yui/license.html
  5421. version: 2.9.0
  5422. */
  5423. if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });var YAHOO = exports.YAHOO = {};
  5424. YAHOO.lang = {
  5425. /**
  5426. * Utility to set up the prototype, constructor and superclass properties to
  5427. * support an inheritance strategy that can chain constructors and methods.
  5428. * Static members will not be inherited.
  5429. *
  5430. * @method extend
  5431. * @static
  5432. * @param {Function} subc the object to modify
  5433. * @param {Function} superc the object to inherit
  5434. * @param {Object} overrides additional properties/methods to add to the
  5435. * subclass prototype. These will override the
  5436. * matching items obtained from the superclass
  5437. * if present.
  5438. */
  5439. extend: function (subc, superc, overrides) {
  5440. if (!superc || !subc) {
  5441. throw new Error("YAHOO.lang.extend failed, please check that " +
  5442. "all dependencies are included.");
  5443. }
  5444. var F = function () { };
  5445. F.prototype = superc.prototype;
  5446. subc.prototype = new F();
  5447. subc.prototype.constructor = subc;
  5448. subc.superclass = superc.prototype;
  5449. if (superc.prototype.constructor == Object.prototype.constructor) {
  5450. superc.prototype.constructor = superc;
  5451. }
  5452. if (overrides) {
  5453. var i;
  5454. for (i in overrides) {
  5455. subc.prototype[i] = overrides[i];
  5456. }
  5457. /*
  5458. * IE will not enumerate native functions in a derived object even if the
  5459. * function was overridden. This is a workaround for specific functions
  5460. * we care about on the Object prototype.
  5461. * @property _IEEnumFix
  5462. * @param {Function} r the object to receive the augmentation
  5463. * @param {Function} s the object that supplies the properties to augment
  5464. * @static
  5465. * @private
  5466. */
  5467. var _IEEnumFix = function () { }, ADD = ["toString", "valueOf"];
  5468. try {
  5469. if (/MSIE/.test(navigator.userAgent)) {
  5470. _IEEnumFix = function (r, s) {
  5471. for (i = 0; i < ADD.length; i = i + 1) {
  5472. var fname = ADD[i], f = s[fname];
  5473. if (typeof f === 'function' && f != Object.prototype[fname]) {
  5474. r[fname] = f;
  5475. }
  5476. }
  5477. };
  5478. }
  5479. }
  5480. catch (ex) { }
  5481. ;
  5482. _IEEnumFix(subc.prototype, overrides);
  5483. }
  5484. }
  5485. };
  5486. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  5487. __DEFINE__(1709513243609, function(require, module, exports) {
  5488. module.exports = {
  5489. "version": "3.2.1"
  5490. }
  5491. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  5492. return __REQUIRE__(1709513243594);
  5493. })()
  5494. //miniprogram-npm-outsideDeps=[]
  5495. //# sourceMappingURL=index.js.map