index.js 782 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331
  1. /*!
  2. * Copyright (c) 2014, GlobalSign
  3. * Copyright (c) 2015-2019, Peculiar Ventures
  4. * All rights reserved.
  5. *
  6. * Author 2014-2019, Yury Strozhevsky
  7. *
  8. * Redistribution and use in source and binary forms, with or without modification,
  9. * are permitted provided that the following conditions are met:
  10. *
  11. * * Redistributions of source code must retain the above copyright notice, this
  12. * list of conditions and the following disclaimer.
  13. *
  14. * * Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * * Neither the name of the {organization} nor the names of its
  19. * contributors may be used to endorse or promote products derived from
  20. * this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  26. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  27. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  28. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  29. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. */
  34. 'use strict';
  35. var asn1js = require('asn1js');
  36. var pvtsutils = require('pvtsutils');
  37. var pvutils = require('pvutils');
  38. var bs = require('bytestreamjs');
  39. var sha1 = require('@noble/hashes/sha1');
  40. var sha2 = require('@noble/hashes/sha2');
  41. function _interopNamespaceDefault(e) {
  42. var n = Object.create(null);
  43. if (e) {
  44. Object.keys(e).forEach(function (k) {
  45. if (k !== 'default') {
  46. var d = Object.getOwnPropertyDescriptor(e, k);
  47. Object.defineProperty(n, k, d.get ? d : {
  48. enumerable: true,
  49. get: function () { return e[k]; }
  50. });
  51. }
  52. });
  53. }
  54. n.default = e;
  55. return Object.freeze(n);
  56. }
  57. var asn1js__namespace = /*#__PURE__*/_interopNamespaceDefault(asn1js);
  58. var pvtsutils__namespace = /*#__PURE__*/_interopNamespaceDefault(pvtsutils);
  59. var pvutils__namespace = /*#__PURE__*/_interopNamespaceDefault(pvutils);
  60. var bs__namespace = /*#__PURE__*/_interopNamespaceDefault(bs);
  61. const EMPTY_BUFFER = new ArrayBuffer(0);
  62. const EMPTY_STRING = "";
  63. class ArgumentError extends TypeError {
  64. constructor() {
  65. super(...arguments);
  66. this.name = ArgumentError.NAME;
  67. }
  68. static isType(value, type) {
  69. if (typeof type === "string") {
  70. if (type === "Array" && Array.isArray(value)) {
  71. return true;
  72. }
  73. else if (type === "ArrayBuffer" && value instanceof ArrayBuffer) {
  74. return true;
  75. }
  76. else if (type === "ArrayBufferView" && ArrayBuffer.isView(value)) {
  77. return true;
  78. }
  79. else if (typeof value === type) {
  80. return true;
  81. }
  82. }
  83. else if (value instanceof type) {
  84. return true;
  85. }
  86. return false;
  87. }
  88. static assert(value, name, ...types) {
  89. for (const type of types) {
  90. if (this.isType(value, type)) {
  91. return;
  92. }
  93. }
  94. const typeNames = types.map(o => o instanceof Function && "name" in o ? o.name : `${o}`);
  95. throw new ArgumentError(`Parameter '${name}' is not of type ${typeNames.length > 1 ? `(${typeNames.join(" or ")})` : typeNames[0]}`);
  96. }
  97. }
  98. ArgumentError.NAME = "ArgumentError";
  99. class ParameterError extends TypeError {
  100. static assert(...args) {
  101. let target = null;
  102. let params;
  103. let fields;
  104. if (typeof args[0] === "string") {
  105. target = args[0];
  106. params = args[1];
  107. fields = args.slice(2);
  108. }
  109. else {
  110. params = args[0];
  111. fields = args.slice(1);
  112. }
  113. ArgumentError.assert(params, "parameters", "object");
  114. for (const field of fields) {
  115. const value = params[field];
  116. if (value === undefined || value === null) {
  117. throw new ParameterError(field, target);
  118. }
  119. }
  120. }
  121. static assertEmpty(value, name, target) {
  122. if (value === undefined || value === null) {
  123. throw new ParameterError(name, target);
  124. }
  125. }
  126. constructor(field, target = null, message) {
  127. super();
  128. this.name = ParameterError.NAME;
  129. this.field = field;
  130. if (target) {
  131. this.target = target;
  132. }
  133. if (message) {
  134. this.message = message;
  135. }
  136. else {
  137. this.message = `Absent mandatory parameter '${field}' ${target ? ` in '${target}'` : EMPTY_STRING}`;
  138. }
  139. }
  140. }
  141. ParameterError.NAME = "ParameterError";
  142. class AsnError extends Error {
  143. static assertSchema(asn1, target) {
  144. if (!asn1.verified) {
  145. throw new Error(`Object's schema was not verified against input data for ${target}`);
  146. }
  147. }
  148. static assert(asn, target) {
  149. if (asn.offset === -1) {
  150. throw new AsnError(`Error during parsing of ASN.1 data. Data is not correct for '${target}'.`);
  151. }
  152. }
  153. constructor(message) {
  154. super(message);
  155. this.name = "AsnError";
  156. }
  157. }
  158. class PkiObject {
  159. static blockName() {
  160. return this.CLASS_NAME;
  161. }
  162. static fromBER(raw) {
  163. const asn1 = asn1js__namespace.fromBER(raw);
  164. AsnError.assert(asn1, this.name);
  165. try {
  166. return new this({ schema: asn1.result });
  167. }
  168. catch (e) {
  169. throw new AsnError(`Cannot create '${this.CLASS_NAME}' from ASN.1 object`);
  170. }
  171. }
  172. static defaultValues(memberName) {
  173. throw new Error(`Invalid member name for ${this.CLASS_NAME} class: ${memberName}`);
  174. }
  175. static schema(parameters = {}) {
  176. throw new Error(`Method '${this.CLASS_NAME}.schema' should be overridden`);
  177. }
  178. get className() {
  179. return this.constructor.CLASS_NAME;
  180. }
  181. toString(encoding = "hex") {
  182. let schema;
  183. try {
  184. schema = this.toSchema();
  185. }
  186. catch {
  187. schema = this.toSchema(true);
  188. }
  189. return pvtsutils__namespace.Convert.ToString(schema.toBER(), encoding);
  190. }
  191. }
  192. PkiObject.CLASS_NAME = "PkiObject";
  193. function stringPrep(inputString) {
  194. let isSpace = false;
  195. let cutResult = EMPTY_STRING;
  196. const result = inputString.trim();
  197. for (let i = 0; i < result.length; i++) {
  198. if (result.charCodeAt(i) === 32) {
  199. if (isSpace === false)
  200. isSpace = true;
  201. }
  202. else {
  203. if (isSpace) {
  204. cutResult += " ";
  205. isSpace = false;
  206. }
  207. cutResult += result[i];
  208. }
  209. }
  210. return cutResult.toLowerCase();
  211. }
  212. const TYPE$5 = "type";
  213. const VALUE$6 = "value";
  214. class AttributeTypeAndValue extends PkiObject {
  215. constructor(parameters = {}) {
  216. super();
  217. this.type = pvutils__namespace.getParametersValue(parameters, TYPE$5, AttributeTypeAndValue.defaultValues(TYPE$5));
  218. this.value = pvutils__namespace.getParametersValue(parameters, VALUE$6, AttributeTypeAndValue.defaultValues(VALUE$6));
  219. if (parameters.schema) {
  220. this.fromSchema(parameters.schema);
  221. }
  222. }
  223. static defaultValues(memberName) {
  224. switch (memberName) {
  225. case TYPE$5:
  226. return EMPTY_STRING;
  227. case VALUE$6:
  228. return {};
  229. default:
  230. return super.defaultValues(memberName);
  231. }
  232. }
  233. static schema(parameters = {}) {
  234. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  235. return (new asn1js__namespace.Sequence({
  236. name: (names.blockName || EMPTY_STRING),
  237. value: [
  238. new asn1js__namespace.ObjectIdentifier({ name: (names.type || EMPTY_STRING) }),
  239. new asn1js__namespace.Any({ name: (names.value || EMPTY_STRING) })
  240. ]
  241. }));
  242. }
  243. fromSchema(schema) {
  244. pvutils__namespace.clearProps(schema, [
  245. TYPE$5,
  246. "typeValue"
  247. ]);
  248. const asn1 = asn1js__namespace.compareSchema(schema, schema, AttributeTypeAndValue.schema({
  249. names: {
  250. type: TYPE$5,
  251. value: "typeValue"
  252. }
  253. }));
  254. AsnError.assertSchema(asn1, this.className);
  255. this.type = asn1.result.type.valueBlock.toString();
  256. this.value = asn1.result.typeValue;
  257. }
  258. toSchema() {
  259. return (new asn1js__namespace.Sequence({
  260. value: [
  261. new asn1js__namespace.ObjectIdentifier({ value: this.type }),
  262. this.value
  263. ]
  264. }));
  265. }
  266. toJSON() {
  267. const _object = {
  268. type: this.type
  269. };
  270. if (Object.keys(this.value).length !== 0) {
  271. _object.value = (this.value).toJSON();
  272. }
  273. else {
  274. _object.value = this.value;
  275. }
  276. return _object;
  277. }
  278. isEqual(compareTo) {
  279. const stringBlockNames = [
  280. asn1js__namespace.Utf8String.blockName(),
  281. asn1js__namespace.BmpString.blockName(),
  282. asn1js__namespace.UniversalString.blockName(),
  283. asn1js__namespace.NumericString.blockName(),
  284. asn1js__namespace.PrintableString.blockName(),
  285. asn1js__namespace.TeletexString.blockName(),
  286. asn1js__namespace.VideotexString.blockName(),
  287. asn1js__namespace.IA5String.blockName(),
  288. asn1js__namespace.GraphicString.blockName(),
  289. asn1js__namespace.VisibleString.blockName(),
  290. asn1js__namespace.GeneralString.blockName(),
  291. asn1js__namespace.CharacterString.blockName()
  292. ];
  293. if (compareTo instanceof ArrayBuffer) {
  294. return pvtsutils__namespace.BufferSourceConverter.isEqual(this.value.valueBeforeDecodeView, compareTo);
  295. }
  296. if (compareTo.constructor.blockName() === AttributeTypeAndValue.blockName()) {
  297. if (this.type !== compareTo.type)
  298. return false;
  299. const isStringPair = [false, false];
  300. const thisName = this.value.constructor.blockName();
  301. for (const name of stringBlockNames) {
  302. if (thisName === name) {
  303. isStringPair[0] = true;
  304. }
  305. if (compareTo.value.constructor.blockName() === name) {
  306. isStringPair[1] = true;
  307. }
  308. }
  309. if (isStringPair[0] !== isStringPair[1]) {
  310. return false;
  311. }
  312. const isString = (isStringPair[0] && isStringPair[1]);
  313. if (isString) {
  314. const value1 = stringPrep(this.value.valueBlock.value);
  315. const value2 = stringPrep(compareTo.value.valueBlock.value);
  316. if (value1.localeCompare(value2) !== 0)
  317. return false;
  318. }
  319. else {
  320. if (!pvtsutils__namespace.BufferSourceConverter.isEqual(this.value.valueBeforeDecodeView, compareTo.value.valueBeforeDecodeView))
  321. return false;
  322. }
  323. return true;
  324. }
  325. return false;
  326. }
  327. }
  328. AttributeTypeAndValue.CLASS_NAME = "AttributeTypeAndValue";
  329. const TYPE_AND_VALUES = "typesAndValues";
  330. const VALUE_BEFORE_DECODE = "valueBeforeDecode";
  331. const RDN = "RDN";
  332. class RelativeDistinguishedNames extends PkiObject {
  333. constructor(parameters = {}) {
  334. super();
  335. this.typesAndValues = pvutils__namespace.getParametersValue(parameters, TYPE_AND_VALUES, RelativeDistinguishedNames.defaultValues(TYPE_AND_VALUES));
  336. this.valueBeforeDecode = pvutils__namespace.getParametersValue(parameters, VALUE_BEFORE_DECODE, RelativeDistinguishedNames.defaultValues(VALUE_BEFORE_DECODE));
  337. if (parameters.schema) {
  338. this.fromSchema(parameters.schema);
  339. }
  340. }
  341. static defaultValues(memberName) {
  342. switch (memberName) {
  343. case TYPE_AND_VALUES:
  344. return [];
  345. case VALUE_BEFORE_DECODE:
  346. return EMPTY_BUFFER;
  347. default:
  348. return super.defaultValues(memberName);
  349. }
  350. }
  351. static compareWithDefault(memberName, memberValue) {
  352. switch (memberName) {
  353. case TYPE_AND_VALUES:
  354. return (memberValue.length === 0);
  355. case VALUE_BEFORE_DECODE:
  356. return (memberValue.byteLength === 0);
  357. default:
  358. return super.defaultValues(memberName);
  359. }
  360. }
  361. static schema(parameters = {}) {
  362. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  363. return (new asn1js__namespace.Sequence({
  364. name: (names.blockName || EMPTY_STRING),
  365. value: [
  366. new asn1js__namespace.Repeated({
  367. name: (names.repeatedSequence || EMPTY_STRING),
  368. value: new asn1js__namespace.Set({
  369. value: [
  370. new asn1js__namespace.Repeated({
  371. name: (names.repeatedSet || EMPTY_STRING),
  372. value: AttributeTypeAndValue.schema(names.typeAndValue || {})
  373. })
  374. ]
  375. })
  376. })
  377. ]
  378. }));
  379. }
  380. fromSchema(schema) {
  381. pvutils__namespace.clearProps(schema, [
  382. RDN,
  383. TYPE_AND_VALUES
  384. ]);
  385. const asn1 = asn1js__namespace.compareSchema(schema, schema, RelativeDistinguishedNames.schema({
  386. names: {
  387. blockName: RDN,
  388. repeatedSet: TYPE_AND_VALUES
  389. }
  390. }));
  391. AsnError.assertSchema(asn1, this.className);
  392. if (TYPE_AND_VALUES in asn1.result) {
  393. this.typesAndValues = Array.from(asn1.result.typesAndValues, element => new AttributeTypeAndValue({ schema: element }));
  394. }
  395. this.valueBeforeDecode = asn1.result.RDN.valueBeforeDecodeView.slice().buffer;
  396. }
  397. toSchema() {
  398. if (this.valueBeforeDecode.byteLength === 0) {
  399. return (new asn1js__namespace.Sequence({
  400. value: [new asn1js__namespace.Set({
  401. value: Array.from(this.typesAndValues, o => o.toSchema())
  402. })]
  403. }));
  404. }
  405. const asn1 = asn1js__namespace.fromBER(this.valueBeforeDecode);
  406. AsnError.assert(asn1, "RelativeDistinguishedNames");
  407. if (!(asn1.result instanceof asn1js__namespace.Sequence)) {
  408. throw new Error("ASN.1 result should be SEQUENCE");
  409. }
  410. return asn1.result;
  411. }
  412. toJSON() {
  413. return {
  414. typesAndValues: Array.from(this.typesAndValues, o => o.toJSON())
  415. };
  416. }
  417. isEqual(compareTo) {
  418. if (compareTo instanceof RelativeDistinguishedNames) {
  419. if (this.typesAndValues.length !== compareTo.typesAndValues.length)
  420. return false;
  421. for (const [index, typeAndValue] of this.typesAndValues.entries()) {
  422. if (typeAndValue.isEqual(compareTo.typesAndValues[index]) === false)
  423. return false;
  424. }
  425. return true;
  426. }
  427. if (compareTo instanceof ArrayBuffer) {
  428. return pvutils__namespace.isEqualBuffer(this.valueBeforeDecode, compareTo);
  429. }
  430. return false;
  431. }
  432. }
  433. RelativeDistinguishedNames.CLASS_NAME = "RelativeDistinguishedNames";
  434. const TYPE$4 = "type";
  435. const VALUE$5 = "value";
  436. function builtInStandardAttributes(parameters = {}, optional = false) {
  437. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  438. return (new asn1js__namespace.Sequence({
  439. optional,
  440. value: [
  441. new asn1js__namespace.Constructed({
  442. optional: true,
  443. idBlock: {
  444. tagClass: 2,
  445. tagNumber: 1
  446. },
  447. name: (names.country_name || EMPTY_STRING),
  448. value: [
  449. new asn1js__namespace.Choice({
  450. value: [
  451. new asn1js__namespace.NumericString(),
  452. new asn1js__namespace.PrintableString()
  453. ]
  454. })
  455. ]
  456. }),
  457. new asn1js__namespace.Constructed({
  458. optional: true,
  459. idBlock: {
  460. tagClass: 2,
  461. tagNumber: 2
  462. },
  463. name: (names.administration_domain_name || EMPTY_STRING),
  464. value: [
  465. new asn1js__namespace.Choice({
  466. value: [
  467. new asn1js__namespace.NumericString(),
  468. new asn1js__namespace.PrintableString()
  469. ]
  470. })
  471. ]
  472. }),
  473. new asn1js__namespace.Primitive({
  474. optional: true,
  475. idBlock: {
  476. tagClass: 3,
  477. tagNumber: 0
  478. },
  479. name: (names.network_address || EMPTY_STRING),
  480. isHexOnly: true
  481. }),
  482. new asn1js__namespace.Primitive({
  483. optional: true,
  484. idBlock: {
  485. tagClass: 3,
  486. tagNumber: 1
  487. },
  488. name: (names.terminal_identifier || EMPTY_STRING),
  489. isHexOnly: true
  490. }),
  491. new asn1js__namespace.Constructed({
  492. optional: true,
  493. idBlock: {
  494. tagClass: 3,
  495. tagNumber: 2
  496. },
  497. name: (names.private_domain_name || EMPTY_STRING),
  498. value: [
  499. new asn1js__namespace.Choice({
  500. value: [
  501. new asn1js__namespace.NumericString(),
  502. new asn1js__namespace.PrintableString()
  503. ]
  504. })
  505. ]
  506. }),
  507. new asn1js__namespace.Primitive({
  508. optional: true,
  509. idBlock: {
  510. tagClass: 3,
  511. tagNumber: 3
  512. },
  513. name: (names.organization_name || EMPTY_STRING),
  514. isHexOnly: true
  515. }),
  516. new asn1js__namespace.Primitive({
  517. optional: true,
  518. name: (names.numeric_user_identifier || EMPTY_STRING),
  519. idBlock: {
  520. tagClass: 3,
  521. tagNumber: 4
  522. },
  523. isHexOnly: true
  524. }),
  525. new asn1js__namespace.Constructed({
  526. optional: true,
  527. name: (names.personal_name || EMPTY_STRING),
  528. idBlock: {
  529. tagClass: 3,
  530. tagNumber: 5
  531. },
  532. value: [
  533. new asn1js__namespace.Primitive({
  534. idBlock: {
  535. tagClass: 3,
  536. tagNumber: 0
  537. },
  538. isHexOnly: true
  539. }),
  540. new asn1js__namespace.Primitive({
  541. optional: true,
  542. idBlock: {
  543. tagClass: 3,
  544. tagNumber: 1
  545. },
  546. isHexOnly: true
  547. }),
  548. new asn1js__namespace.Primitive({
  549. optional: true,
  550. idBlock: {
  551. tagClass: 3,
  552. tagNumber: 2
  553. },
  554. isHexOnly: true
  555. }),
  556. new asn1js__namespace.Primitive({
  557. optional: true,
  558. idBlock: {
  559. tagClass: 3,
  560. tagNumber: 3
  561. },
  562. isHexOnly: true
  563. })
  564. ]
  565. }),
  566. new asn1js__namespace.Constructed({
  567. optional: true,
  568. name: (names.organizational_unit_names || EMPTY_STRING),
  569. idBlock: {
  570. tagClass: 3,
  571. tagNumber: 6
  572. },
  573. value: [
  574. new asn1js__namespace.Repeated({
  575. value: new asn1js__namespace.PrintableString()
  576. })
  577. ]
  578. })
  579. ]
  580. }));
  581. }
  582. function builtInDomainDefinedAttributes(optional = false) {
  583. return (new asn1js__namespace.Sequence({
  584. optional,
  585. value: [
  586. new asn1js__namespace.PrintableString(),
  587. new asn1js__namespace.PrintableString()
  588. ]
  589. }));
  590. }
  591. function extensionAttributes(optional = false) {
  592. return (new asn1js__namespace.Set({
  593. optional,
  594. value: [
  595. new asn1js__namespace.Primitive({
  596. optional: true,
  597. idBlock: {
  598. tagClass: 3,
  599. tagNumber: 0
  600. },
  601. isHexOnly: true
  602. }),
  603. new asn1js__namespace.Constructed({
  604. optional: true,
  605. idBlock: {
  606. tagClass: 3,
  607. tagNumber: 1
  608. },
  609. value: [new asn1js__namespace.Any()]
  610. })
  611. ]
  612. }));
  613. }
  614. class GeneralName extends PkiObject {
  615. constructor(parameters = {}) {
  616. super();
  617. this.type = pvutils__namespace.getParametersValue(parameters, TYPE$4, GeneralName.defaultValues(TYPE$4));
  618. this.value = pvutils__namespace.getParametersValue(parameters, VALUE$5, GeneralName.defaultValues(VALUE$5));
  619. if (parameters.schema) {
  620. this.fromSchema(parameters.schema);
  621. }
  622. }
  623. static defaultValues(memberName) {
  624. switch (memberName) {
  625. case TYPE$4:
  626. return 9;
  627. case VALUE$5:
  628. return {};
  629. default:
  630. return super.defaultValues(memberName);
  631. }
  632. }
  633. static compareWithDefault(memberName, memberValue) {
  634. switch (memberName) {
  635. case TYPE$4:
  636. return (memberValue === GeneralName.defaultValues(memberName));
  637. case VALUE$5:
  638. return (Object.keys(memberValue).length === 0);
  639. default:
  640. return super.defaultValues(memberName);
  641. }
  642. }
  643. static schema(parameters = {}) {
  644. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  645. return (new asn1js__namespace.Choice({
  646. value: [
  647. new asn1js__namespace.Constructed({
  648. idBlock: {
  649. tagClass: 3,
  650. tagNumber: 0
  651. },
  652. name: (names.blockName || EMPTY_STRING),
  653. value: [
  654. new asn1js__namespace.ObjectIdentifier(),
  655. new asn1js__namespace.Constructed({
  656. idBlock: {
  657. tagClass: 3,
  658. tagNumber: 0
  659. },
  660. value: [new asn1js__namespace.Any()]
  661. })
  662. ]
  663. }),
  664. new asn1js__namespace.Primitive({
  665. name: (names.blockName || EMPTY_STRING),
  666. idBlock: {
  667. tagClass: 3,
  668. tagNumber: 1
  669. }
  670. }),
  671. new asn1js__namespace.Primitive({
  672. name: (names.blockName || EMPTY_STRING),
  673. idBlock: {
  674. tagClass: 3,
  675. tagNumber: 2
  676. }
  677. }),
  678. new asn1js__namespace.Constructed({
  679. idBlock: {
  680. tagClass: 3,
  681. tagNumber: 3
  682. },
  683. name: (names.blockName || EMPTY_STRING),
  684. value: [
  685. builtInStandardAttributes((names.builtInStandardAttributes || {}), false),
  686. builtInDomainDefinedAttributes(true),
  687. extensionAttributes(true)
  688. ]
  689. }),
  690. new asn1js__namespace.Constructed({
  691. idBlock: {
  692. tagClass: 3,
  693. tagNumber: 4
  694. },
  695. name: (names.blockName || EMPTY_STRING),
  696. value: [RelativeDistinguishedNames.schema(names.directoryName || {})]
  697. }),
  698. new asn1js__namespace.Constructed({
  699. idBlock: {
  700. tagClass: 3,
  701. tagNumber: 5
  702. },
  703. name: (names.blockName || EMPTY_STRING),
  704. value: [
  705. new asn1js__namespace.Constructed({
  706. optional: true,
  707. idBlock: {
  708. tagClass: 3,
  709. tagNumber: 0
  710. },
  711. value: [
  712. new asn1js__namespace.Choice({
  713. value: [
  714. new asn1js__namespace.TeletexString(),
  715. new asn1js__namespace.PrintableString(),
  716. new asn1js__namespace.UniversalString(),
  717. new asn1js__namespace.Utf8String(),
  718. new asn1js__namespace.BmpString()
  719. ]
  720. })
  721. ]
  722. }),
  723. new asn1js__namespace.Constructed({
  724. idBlock: {
  725. tagClass: 3,
  726. tagNumber: 1
  727. },
  728. value: [
  729. new asn1js__namespace.Choice({
  730. value: [
  731. new asn1js__namespace.TeletexString(),
  732. new asn1js__namespace.PrintableString(),
  733. new asn1js__namespace.UniversalString(),
  734. new asn1js__namespace.Utf8String(),
  735. new asn1js__namespace.BmpString()
  736. ]
  737. })
  738. ]
  739. })
  740. ]
  741. }),
  742. new asn1js__namespace.Primitive({
  743. name: (names.blockName || EMPTY_STRING),
  744. idBlock: {
  745. tagClass: 3,
  746. tagNumber: 6
  747. }
  748. }),
  749. new asn1js__namespace.Primitive({
  750. name: (names.blockName || EMPTY_STRING),
  751. idBlock: {
  752. tagClass: 3,
  753. tagNumber: 7
  754. }
  755. }),
  756. new asn1js__namespace.Primitive({
  757. name: (names.blockName || EMPTY_STRING),
  758. idBlock: {
  759. tagClass: 3,
  760. tagNumber: 8
  761. }
  762. })
  763. ]
  764. }));
  765. }
  766. fromSchema(schema) {
  767. pvutils__namespace.clearProps(schema, [
  768. "blockName",
  769. "otherName",
  770. "rfc822Name",
  771. "dNSName",
  772. "x400Address",
  773. "directoryName",
  774. "ediPartyName",
  775. "uniformResourceIdentifier",
  776. "iPAddress",
  777. "registeredID"
  778. ]);
  779. const asn1 = asn1js__namespace.compareSchema(schema, schema, GeneralName.schema({
  780. names: {
  781. blockName: "blockName",
  782. otherName: "otherName",
  783. rfc822Name: "rfc822Name",
  784. dNSName: "dNSName",
  785. x400Address: "x400Address",
  786. directoryName: {
  787. names: {
  788. blockName: "directoryName"
  789. }
  790. },
  791. ediPartyName: "ediPartyName",
  792. uniformResourceIdentifier: "uniformResourceIdentifier",
  793. iPAddress: "iPAddress",
  794. registeredID: "registeredID"
  795. }
  796. }));
  797. AsnError.assertSchema(asn1, this.className);
  798. this.type = asn1.result.blockName.idBlock.tagNumber;
  799. switch (this.type) {
  800. case 0:
  801. this.value = asn1.result.blockName;
  802. break;
  803. case 1:
  804. case 2:
  805. case 6:
  806. {
  807. const value = asn1.result.blockName;
  808. value.idBlock.tagClass = 1;
  809. value.idBlock.tagNumber = 22;
  810. const valueBER = value.toBER(false);
  811. const asnValue = asn1js__namespace.fromBER(valueBER);
  812. AsnError.assert(asnValue, "GeneralName value");
  813. this.value = asnValue.result.valueBlock.value;
  814. }
  815. break;
  816. case 3:
  817. this.value = asn1.result.blockName;
  818. break;
  819. case 4:
  820. this.value = new RelativeDistinguishedNames({ schema: asn1.result.directoryName });
  821. break;
  822. case 5:
  823. this.value = asn1.result.ediPartyName;
  824. break;
  825. case 7:
  826. this.value = new asn1js__namespace.OctetString({ valueHex: asn1.result.blockName.valueBlock.valueHex });
  827. break;
  828. case 8:
  829. {
  830. const value = asn1.result.blockName;
  831. value.idBlock.tagClass = 1;
  832. value.idBlock.tagNumber = 6;
  833. const valueBER = value.toBER(false);
  834. const asnValue = asn1js__namespace.fromBER(valueBER);
  835. AsnError.assert(asnValue, "GeneralName registeredID");
  836. this.value = asnValue.result.valueBlock.toString();
  837. }
  838. break;
  839. }
  840. }
  841. toSchema() {
  842. switch (this.type) {
  843. case 0:
  844. case 3:
  845. case 5:
  846. return new asn1js__namespace.Constructed({
  847. idBlock: {
  848. tagClass: 3,
  849. tagNumber: this.type
  850. },
  851. value: [
  852. this.value
  853. ]
  854. });
  855. case 1:
  856. case 2:
  857. case 6:
  858. {
  859. const value = new asn1js__namespace.IA5String({ value: this.value });
  860. value.idBlock.tagClass = 3;
  861. value.idBlock.tagNumber = this.type;
  862. return value;
  863. }
  864. case 4:
  865. return new asn1js__namespace.Constructed({
  866. idBlock: {
  867. tagClass: 3,
  868. tagNumber: 4
  869. },
  870. value: [this.value.toSchema()]
  871. });
  872. case 7:
  873. {
  874. const value = this.value;
  875. value.idBlock.tagClass = 3;
  876. value.idBlock.tagNumber = this.type;
  877. return value;
  878. }
  879. case 8:
  880. {
  881. const value = new asn1js__namespace.ObjectIdentifier({ value: this.value });
  882. value.idBlock.tagClass = 3;
  883. value.idBlock.tagNumber = this.type;
  884. return value;
  885. }
  886. default:
  887. return GeneralName.schema();
  888. }
  889. }
  890. toJSON() {
  891. const _object = {
  892. type: this.type,
  893. value: EMPTY_STRING
  894. };
  895. if ((typeof this.value) === "string")
  896. _object.value = this.value;
  897. else {
  898. try {
  899. _object.value = this.value.toJSON();
  900. }
  901. catch {
  902. }
  903. }
  904. return _object;
  905. }
  906. }
  907. GeneralName.CLASS_NAME = "GeneralName";
  908. const ACCESS_METHOD = "accessMethod";
  909. const ACCESS_LOCATION = "accessLocation";
  910. const CLEAR_PROPS$1v = [
  911. ACCESS_METHOD,
  912. ACCESS_LOCATION,
  913. ];
  914. class AccessDescription extends PkiObject {
  915. constructor(parameters = {}) {
  916. super();
  917. this.accessMethod = pvutils__namespace.getParametersValue(parameters, ACCESS_METHOD, AccessDescription.defaultValues(ACCESS_METHOD));
  918. this.accessLocation = pvutils__namespace.getParametersValue(parameters, ACCESS_LOCATION, AccessDescription.defaultValues(ACCESS_LOCATION));
  919. if (parameters.schema) {
  920. this.fromSchema(parameters.schema);
  921. }
  922. }
  923. static defaultValues(memberName) {
  924. switch (memberName) {
  925. case ACCESS_METHOD:
  926. return EMPTY_STRING;
  927. case ACCESS_LOCATION:
  928. return new GeneralName();
  929. default:
  930. return super.defaultValues(memberName);
  931. }
  932. }
  933. static schema(parameters = {}) {
  934. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  935. return (new asn1js__namespace.Sequence({
  936. name: (names.blockName || EMPTY_STRING),
  937. value: [
  938. new asn1js__namespace.ObjectIdentifier({ name: (names.accessMethod || EMPTY_STRING) }),
  939. GeneralName.schema(names.accessLocation || {})
  940. ]
  941. }));
  942. }
  943. fromSchema(schema) {
  944. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1v);
  945. const asn1 = asn1js__namespace.compareSchema(schema, schema, AccessDescription.schema({
  946. names: {
  947. accessMethod: ACCESS_METHOD,
  948. accessLocation: {
  949. names: {
  950. blockName: ACCESS_LOCATION
  951. }
  952. }
  953. }
  954. }));
  955. AsnError.assertSchema(asn1, this.className);
  956. this.accessMethod = asn1.result.accessMethod.valueBlock.toString();
  957. this.accessLocation = new GeneralName({ schema: asn1.result.accessLocation });
  958. }
  959. toSchema() {
  960. return (new asn1js__namespace.Sequence({
  961. value: [
  962. new asn1js__namespace.ObjectIdentifier({ value: this.accessMethod }),
  963. this.accessLocation.toSchema()
  964. ]
  965. }));
  966. }
  967. toJSON() {
  968. return {
  969. accessMethod: this.accessMethod,
  970. accessLocation: this.accessLocation.toJSON()
  971. };
  972. }
  973. }
  974. AccessDescription.CLASS_NAME = "AccessDescription";
  975. const SECONDS = "seconds";
  976. const MILLIS = "millis";
  977. const MICROS = "micros";
  978. class Accuracy extends PkiObject {
  979. constructor(parameters = {}) {
  980. super();
  981. if (SECONDS in parameters) {
  982. this.seconds = pvutils__namespace.getParametersValue(parameters, SECONDS, Accuracy.defaultValues(SECONDS));
  983. }
  984. if (MILLIS in parameters) {
  985. this.millis = pvutils__namespace.getParametersValue(parameters, MILLIS, Accuracy.defaultValues(MILLIS));
  986. }
  987. if (MICROS in parameters) {
  988. this.micros = pvutils__namespace.getParametersValue(parameters, MICROS, Accuracy.defaultValues(MICROS));
  989. }
  990. if (parameters.schema) {
  991. this.fromSchema(parameters.schema);
  992. }
  993. }
  994. static defaultValues(memberName) {
  995. switch (memberName) {
  996. case SECONDS:
  997. case MILLIS:
  998. case MICROS:
  999. return 0;
  1000. default:
  1001. return super.defaultValues(memberName);
  1002. }
  1003. }
  1004. static compareWithDefault(memberName, memberValue) {
  1005. switch (memberName) {
  1006. case SECONDS:
  1007. case MILLIS:
  1008. case MICROS:
  1009. return (memberValue === Accuracy.defaultValues(memberName));
  1010. default:
  1011. return super.defaultValues(memberName);
  1012. }
  1013. }
  1014. static schema(parameters = {}) {
  1015. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  1016. return (new asn1js__namespace.Sequence({
  1017. name: (names.blockName || EMPTY_STRING),
  1018. optional: true,
  1019. value: [
  1020. new asn1js__namespace.Integer({
  1021. optional: true,
  1022. name: (names.seconds || EMPTY_STRING)
  1023. }),
  1024. new asn1js__namespace.Primitive({
  1025. name: (names.millis || EMPTY_STRING),
  1026. optional: true,
  1027. idBlock: {
  1028. tagClass: 3,
  1029. tagNumber: 0
  1030. }
  1031. }),
  1032. new asn1js__namespace.Primitive({
  1033. name: (names.micros || EMPTY_STRING),
  1034. optional: true,
  1035. idBlock: {
  1036. tagClass: 3,
  1037. tagNumber: 1
  1038. }
  1039. })
  1040. ]
  1041. }));
  1042. }
  1043. fromSchema(schema) {
  1044. pvutils__namespace.clearProps(schema, [
  1045. SECONDS,
  1046. MILLIS,
  1047. MICROS,
  1048. ]);
  1049. const asn1 = asn1js__namespace.compareSchema(schema, schema, Accuracy.schema({
  1050. names: {
  1051. seconds: SECONDS,
  1052. millis: MILLIS,
  1053. micros: MICROS,
  1054. }
  1055. }));
  1056. AsnError.assertSchema(asn1, this.className);
  1057. if ("seconds" in asn1.result) {
  1058. this.seconds = asn1.result.seconds.valueBlock.valueDec;
  1059. }
  1060. if ("millis" in asn1.result) {
  1061. const intMillis = new asn1js__namespace.Integer({ valueHex: asn1.result.millis.valueBlock.valueHex });
  1062. this.millis = intMillis.valueBlock.valueDec;
  1063. }
  1064. if ("micros" in asn1.result) {
  1065. const intMicros = new asn1js__namespace.Integer({ valueHex: asn1.result.micros.valueBlock.valueHex });
  1066. this.micros = intMicros.valueBlock.valueDec;
  1067. }
  1068. }
  1069. toSchema() {
  1070. const outputArray = [];
  1071. if (this.seconds !== undefined)
  1072. outputArray.push(new asn1js__namespace.Integer({ value: this.seconds }));
  1073. if (this.millis !== undefined) {
  1074. const intMillis = new asn1js__namespace.Integer({ value: this.millis });
  1075. outputArray.push(new asn1js__namespace.Primitive({
  1076. idBlock: {
  1077. tagClass: 3,
  1078. tagNumber: 0
  1079. },
  1080. valueHex: intMillis.valueBlock.valueHexView
  1081. }));
  1082. }
  1083. if (this.micros !== undefined) {
  1084. const intMicros = new asn1js__namespace.Integer({ value: this.micros });
  1085. outputArray.push(new asn1js__namespace.Primitive({
  1086. idBlock: {
  1087. tagClass: 3,
  1088. tagNumber: 1
  1089. },
  1090. valueHex: intMicros.valueBlock.valueHexView
  1091. }));
  1092. }
  1093. return (new asn1js__namespace.Sequence({
  1094. value: outputArray
  1095. }));
  1096. }
  1097. toJSON() {
  1098. const _object = {};
  1099. if (this.seconds !== undefined)
  1100. _object.seconds = this.seconds;
  1101. if (this.millis !== undefined)
  1102. _object.millis = this.millis;
  1103. if (this.micros !== undefined)
  1104. _object.micros = this.micros;
  1105. return _object;
  1106. }
  1107. }
  1108. Accuracy.CLASS_NAME = "Accuracy";
  1109. const ALGORITHM_ID = "algorithmId";
  1110. const ALGORITHM_PARAMS = "algorithmParams";
  1111. const ALGORITHM$2 = "algorithm";
  1112. const PARAMS = "params";
  1113. const CLEAR_PROPS$1u = [
  1114. ALGORITHM$2,
  1115. PARAMS
  1116. ];
  1117. class AlgorithmIdentifier extends PkiObject {
  1118. constructor(parameters = {}) {
  1119. super();
  1120. this.algorithmId = pvutils__namespace.getParametersValue(parameters, ALGORITHM_ID, AlgorithmIdentifier.defaultValues(ALGORITHM_ID));
  1121. if (ALGORITHM_PARAMS in parameters) {
  1122. this.algorithmParams = pvutils__namespace.getParametersValue(parameters, ALGORITHM_PARAMS, AlgorithmIdentifier.defaultValues(ALGORITHM_PARAMS));
  1123. }
  1124. if (parameters.schema) {
  1125. this.fromSchema(parameters.schema);
  1126. }
  1127. }
  1128. static defaultValues(memberName) {
  1129. switch (memberName) {
  1130. case ALGORITHM_ID:
  1131. return EMPTY_STRING;
  1132. case ALGORITHM_PARAMS:
  1133. return new asn1js__namespace.Any();
  1134. default:
  1135. return super.defaultValues(memberName);
  1136. }
  1137. }
  1138. static compareWithDefault(memberName, memberValue) {
  1139. switch (memberName) {
  1140. case ALGORITHM_ID:
  1141. return (memberValue === EMPTY_STRING);
  1142. case ALGORITHM_PARAMS:
  1143. return (memberValue instanceof asn1js__namespace.Any);
  1144. default:
  1145. return super.defaultValues(memberName);
  1146. }
  1147. }
  1148. static schema(parameters = {}) {
  1149. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  1150. return (new asn1js__namespace.Sequence({
  1151. name: (names.blockName || EMPTY_STRING),
  1152. optional: (names.optional || false),
  1153. value: [
  1154. new asn1js__namespace.ObjectIdentifier({ name: (names.algorithmIdentifier || EMPTY_STRING) }),
  1155. new asn1js__namespace.Any({ name: (names.algorithmParams || EMPTY_STRING), optional: true })
  1156. ]
  1157. }));
  1158. }
  1159. fromSchema(schema) {
  1160. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1u);
  1161. const asn1 = asn1js__namespace.compareSchema(schema, schema, AlgorithmIdentifier.schema({
  1162. names: {
  1163. algorithmIdentifier: ALGORITHM$2,
  1164. algorithmParams: PARAMS
  1165. }
  1166. }));
  1167. AsnError.assertSchema(asn1, this.className);
  1168. this.algorithmId = asn1.result.algorithm.valueBlock.toString();
  1169. if (PARAMS in asn1.result) {
  1170. this.algorithmParams = asn1.result.params;
  1171. }
  1172. }
  1173. toSchema() {
  1174. const outputArray = [];
  1175. outputArray.push(new asn1js__namespace.ObjectIdentifier({ value: this.algorithmId }));
  1176. if (this.algorithmParams && !(this.algorithmParams instanceof asn1js__namespace.Any)) {
  1177. outputArray.push(this.algorithmParams);
  1178. }
  1179. return (new asn1js__namespace.Sequence({
  1180. value: outputArray
  1181. }));
  1182. }
  1183. toJSON() {
  1184. const object = {
  1185. algorithmId: this.algorithmId
  1186. };
  1187. if (this.algorithmParams && !(this.algorithmParams instanceof asn1js__namespace.Any)) {
  1188. object.algorithmParams = this.algorithmParams.toJSON();
  1189. }
  1190. return object;
  1191. }
  1192. isEqual(algorithmIdentifier) {
  1193. if (!(algorithmIdentifier instanceof AlgorithmIdentifier)) {
  1194. return false;
  1195. }
  1196. if (this.algorithmId !== algorithmIdentifier.algorithmId) {
  1197. return false;
  1198. }
  1199. if (this.algorithmParams) {
  1200. if (algorithmIdentifier.algorithmParams) {
  1201. return JSON.stringify(this.algorithmParams) === JSON.stringify(algorithmIdentifier.algorithmParams);
  1202. }
  1203. return false;
  1204. }
  1205. if (algorithmIdentifier.algorithmParams) {
  1206. return false;
  1207. }
  1208. return true;
  1209. }
  1210. }
  1211. AlgorithmIdentifier.CLASS_NAME = "AlgorithmIdentifier";
  1212. const ALT_NAMES = "altNames";
  1213. const CLEAR_PROPS$1t = [
  1214. ALT_NAMES
  1215. ];
  1216. class AltName extends PkiObject {
  1217. constructor(parameters = {}) {
  1218. super();
  1219. this.altNames = pvutils__namespace.getParametersValue(parameters, ALT_NAMES, AltName.defaultValues(ALT_NAMES));
  1220. if (parameters.schema) {
  1221. this.fromSchema(parameters.schema);
  1222. }
  1223. }
  1224. static defaultValues(memberName) {
  1225. switch (memberName) {
  1226. case ALT_NAMES:
  1227. return [];
  1228. default:
  1229. return super.defaultValues(memberName);
  1230. }
  1231. }
  1232. static schema(parameters = {}) {
  1233. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  1234. return (new asn1js__namespace.Sequence({
  1235. name: (names.blockName || EMPTY_STRING),
  1236. value: [
  1237. new asn1js__namespace.Repeated({
  1238. name: (names.altNames || EMPTY_STRING),
  1239. value: GeneralName.schema()
  1240. })
  1241. ]
  1242. }));
  1243. }
  1244. fromSchema(schema) {
  1245. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1t);
  1246. const asn1 = asn1js__namespace.compareSchema(schema, schema, AltName.schema({
  1247. names: {
  1248. altNames: ALT_NAMES
  1249. }
  1250. }));
  1251. AsnError.assertSchema(asn1, this.className);
  1252. if (ALT_NAMES in asn1.result) {
  1253. this.altNames = Array.from(asn1.result.altNames, element => new GeneralName({ schema: element }));
  1254. }
  1255. }
  1256. toSchema() {
  1257. return (new asn1js__namespace.Sequence({
  1258. value: Array.from(this.altNames, o => o.toSchema())
  1259. }));
  1260. }
  1261. toJSON() {
  1262. return {
  1263. altNames: Array.from(this.altNames, o => o.toJSON())
  1264. };
  1265. }
  1266. }
  1267. AltName.CLASS_NAME = "AltName";
  1268. const TYPE$3 = "type";
  1269. const VALUES$1 = "values";
  1270. const CLEAR_PROPS$1s = [
  1271. TYPE$3,
  1272. VALUES$1
  1273. ];
  1274. class Attribute extends PkiObject {
  1275. constructor(parameters = {}) {
  1276. super();
  1277. this.type = pvutils__namespace.getParametersValue(parameters, TYPE$3, Attribute.defaultValues(TYPE$3));
  1278. this.values = pvutils__namespace.getParametersValue(parameters, VALUES$1, Attribute.defaultValues(VALUES$1));
  1279. if (parameters.schema) {
  1280. this.fromSchema(parameters.schema);
  1281. }
  1282. }
  1283. static defaultValues(memberName) {
  1284. switch (memberName) {
  1285. case TYPE$3:
  1286. return EMPTY_STRING;
  1287. case VALUES$1:
  1288. return [];
  1289. default:
  1290. return super.defaultValues(memberName);
  1291. }
  1292. }
  1293. static compareWithDefault(memberName, memberValue) {
  1294. switch (memberName) {
  1295. case TYPE$3:
  1296. return (memberValue === EMPTY_STRING);
  1297. case VALUES$1:
  1298. return (memberValue.length === 0);
  1299. default:
  1300. return super.defaultValues(memberName);
  1301. }
  1302. }
  1303. static schema(parameters = {}) {
  1304. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  1305. return (new asn1js__namespace.Sequence({
  1306. name: (names.blockName || EMPTY_STRING),
  1307. value: [
  1308. new asn1js__namespace.ObjectIdentifier({ name: (names.type || EMPTY_STRING) }),
  1309. new asn1js__namespace.Set({
  1310. name: (names.setName || EMPTY_STRING),
  1311. value: [
  1312. new asn1js__namespace.Repeated({
  1313. name: (names.values || EMPTY_STRING),
  1314. value: new asn1js__namespace.Any()
  1315. })
  1316. ]
  1317. })
  1318. ]
  1319. }));
  1320. }
  1321. fromSchema(schema) {
  1322. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1s);
  1323. const asn1 = asn1js__namespace.compareSchema(schema, schema, Attribute.schema({
  1324. names: {
  1325. type: TYPE$3,
  1326. values: VALUES$1
  1327. }
  1328. }));
  1329. AsnError.assertSchema(asn1, this.className);
  1330. this.type = asn1.result.type.valueBlock.toString();
  1331. this.values = asn1.result.values;
  1332. }
  1333. toSchema() {
  1334. return (new asn1js__namespace.Sequence({
  1335. value: [
  1336. new asn1js__namespace.ObjectIdentifier({ value: this.type }),
  1337. new asn1js__namespace.Set({
  1338. value: this.values
  1339. })
  1340. ]
  1341. }));
  1342. }
  1343. toJSON() {
  1344. return {
  1345. type: this.type,
  1346. values: Array.from(this.values, o => o.toJSON())
  1347. };
  1348. }
  1349. }
  1350. Attribute.CLASS_NAME = "Attribute";
  1351. const NOT_BEFORE_TIME = "notBeforeTime";
  1352. const NOT_AFTER_TIME = "notAfterTime";
  1353. const CLEAR_PROPS$1r = [
  1354. NOT_BEFORE_TIME,
  1355. NOT_AFTER_TIME,
  1356. ];
  1357. class AttCertValidityPeriod extends PkiObject {
  1358. constructor(parameters = {}) {
  1359. super();
  1360. this.notBeforeTime = pvutils__namespace.getParametersValue(parameters, NOT_BEFORE_TIME, AttCertValidityPeriod.defaultValues(NOT_BEFORE_TIME));
  1361. this.notAfterTime = pvutils__namespace.getParametersValue(parameters, NOT_AFTER_TIME, AttCertValidityPeriod.defaultValues(NOT_AFTER_TIME));
  1362. if (parameters.schema) {
  1363. this.fromSchema(parameters.schema);
  1364. }
  1365. }
  1366. static defaultValues(memberName) {
  1367. switch (memberName) {
  1368. case NOT_BEFORE_TIME:
  1369. case NOT_AFTER_TIME:
  1370. return new Date(0, 0, 0);
  1371. default:
  1372. return super.defaultValues(memberName);
  1373. }
  1374. }
  1375. static schema(parameters = {}) {
  1376. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  1377. return (new asn1js__namespace.Sequence({
  1378. name: (names.blockName || EMPTY_STRING),
  1379. value: [
  1380. new asn1js__namespace.GeneralizedTime({ name: (names.notBeforeTime || EMPTY_STRING) }),
  1381. new asn1js__namespace.GeneralizedTime({ name: (names.notAfterTime || EMPTY_STRING) })
  1382. ]
  1383. }));
  1384. }
  1385. fromSchema(schema) {
  1386. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1r);
  1387. const asn1 = asn1js__namespace.compareSchema(schema, schema, AttCertValidityPeriod.schema({
  1388. names: {
  1389. notBeforeTime: NOT_BEFORE_TIME,
  1390. notAfterTime: NOT_AFTER_TIME
  1391. }
  1392. }));
  1393. AsnError.assertSchema(asn1, this.className);
  1394. this.notBeforeTime = asn1.result.notBeforeTime.toDate();
  1395. this.notAfterTime = asn1.result.notAfterTime.toDate();
  1396. }
  1397. toSchema() {
  1398. return (new asn1js__namespace.Sequence({
  1399. value: [
  1400. new asn1js__namespace.GeneralizedTime({ valueDate: this.notBeforeTime }),
  1401. new asn1js__namespace.GeneralizedTime({ valueDate: this.notAfterTime }),
  1402. ]
  1403. }));
  1404. }
  1405. toJSON() {
  1406. return {
  1407. notBeforeTime: this.notBeforeTime,
  1408. notAfterTime: this.notAfterTime
  1409. };
  1410. }
  1411. }
  1412. AttCertValidityPeriod.CLASS_NAME = "AttCertValidityPeriod";
  1413. const NAMES = "names";
  1414. const GENERAL_NAMES = "generalNames";
  1415. class GeneralNames extends PkiObject {
  1416. constructor(parameters = {}) {
  1417. super();
  1418. this.names = pvutils__namespace.getParametersValue(parameters, NAMES, GeneralNames.defaultValues(NAMES));
  1419. if (parameters.schema) {
  1420. this.fromSchema(parameters.schema);
  1421. }
  1422. }
  1423. static defaultValues(memberName) {
  1424. switch (memberName) {
  1425. case "names":
  1426. return [];
  1427. default:
  1428. return super.defaultValues(memberName);
  1429. }
  1430. }
  1431. static schema(parameters = {}, optional = false) {
  1432. const names = pvutils__namespace.getParametersValue(parameters, NAMES, {});
  1433. return (new asn1js__namespace.Sequence({
  1434. optional,
  1435. name: (names.blockName || EMPTY_STRING),
  1436. value: [
  1437. new asn1js__namespace.Repeated({
  1438. name: (names.generalNames || EMPTY_STRING),
  1439. value: GeneralName.schema()
  1440. })
  1441. ]
  1442. }));
  1443. }
  1444. fromSchema(schema) {
  1445. pvutils__namespace.clearProps(schema, [
  1446. NAMES,
  1447. GENERAL_NAMES
  1448. ]);
  1449. const asn1 = asn1js__namespace.compareSchema(schema, schema, GeneralNames.schema({
  1450. names: {
  1451. blockName: NAMES,
  1452. generalNames: GENERAL_NAMES
  1453. }
  1454. }));
  1455. AsnError.assertSchema(asn1, this.className);
  1456. this.names = Array.from(asn1.result.generalNames, element => new GeneralName({ schema: element }));
  1457. }
  1458. toSchema() {
  1459. return (new asn1js__namespace.Sequence({
  1460. value: Array.from(this.names, o => o.toSchema())
  1461. }));
  1462. }
  1463. toJSON() {
  1464. return {
  1465. names: Array.from(this.names, o => o.toJSON())
  1466. };
  1467. }
  1468. }
  1469. GeneralNames.CLASS_NAME = "GeneralNames";
  1470. const id_SubjectDirectoryAttributes = "2.5.29.9";
  1471. const id_SubjectKeyIdentifier = "2.5.29.14";
  1472. const id_KeyUsage = "2.5.29.15";
  1473. const id_PrivateKeyUsagePeriod = "2.5.29.16";
  1474. const id_SubjectAltName = "2.5.29.17";
  1475. const id_IssuerAltName = "2.5.29.18";
  1476. const id_BasicConstraints = "2.5.29.19";
  1477. const id_CRLNumber = "2.5.29.20";
  1478. const id_BaseCRLNumber = "2.5.29.27";
  1479. const id_CRLReason = "2.5.29.21";
  1480. const id_InvalidityDate = "2.5.29.24";
  1481. const id_IssuingDistributionPoint = "2.5.29.28";
  1482. const id_CertificateIssuer = "2.5.29.29";
  1483. const id_NameConstraints = "2.5.29.30";
  1484. const id_CRLDistributionPoints = "2.5.29.31";
  1485. const id_FreshestCRL = "2.5.29.46";
  1486. const id_CertificatePolicies = "2.5.29.32";
  1487. const id_AnyPolicy = "2.5.29.32.0";
  1488. const id_MicrosoftAppPolicies = "1.3.6.1.4.1.311.21.10";
  1489. const id_PolicyMappings = "2.5.29.33";
  1490. const id_AuthorityKeyIdentifier = "2.5.29.35";
  1491. const id_PolicyConstraints = "2.5.29.36";
  1492. const id_ExtKeyUsage = "2.5.29.37";
  1493. const id_InhibitAnyPolicy = "2.5.29.54";
  1494. const id_AuthorityInfoAccess = "1.3.6.1.5.5.7.1.1";
  1495. const id_SubjectInfoAccess = "1.3.6.1.5.5.7.1.11";
  1496. const id_SignedCertificateTimestampList = "1.3.6.1.4.1.11129.2.4.2";
  1497. const id_MicrosoftCertTemplateV1 = "1.3.6.1.4.1.311.20.2";
  1498. const id_MicrosoftPrevCaCertHash = "1.3.6.1.4.1.311.21.2";
  1499. const id_MicrosoftCertTemplateV2 = "1.3.6.1.4.1.311.21.7";
  1500. const id_MicrosoftCaVersion = "1.3.6.1.4.1.311.21.1";
  1501. const id_QCStatements = "1.3.6.1.5.5.7.1.3";
  1502. const id_ContentType_Data = "1.2.840.113549.1.7.1";
  1503. const id_ContentType_SignedData = "1.2.840.113549.1.7.2";
  1504. const id_ContentType_EnvelopedData = "1.2.840.113549.1.7.3";
  1505. const id_ContentType_EncryptedData = "1.2.840.113549.1.7.6";
  1506. const id_eContentType_TSTInfo = "1.2.840.113549.1.9.16.1.4";
  1507. const id_CertBag_X509Certificate = "1.2.840.113549.1.9.22.1";
  1508. const id_CertBag_SDSICertificate = "1.2.840.113549.1.9.22.2";
  1509. const id_CertBag_AttributeCertificate = "1.2.840.113549.1.9.22.3";
  1510. const id_CRLBag_X509CRL = "1.2.840.113549.1.9.23.1";
  1511. const id_pkix = "1.3.6.1.5.5.7";
  1512. const id_ad = `${id_pkix}.48`;
  1513. const id_PKIX_OCSP_Basic = `${id_ad}.1.1`;
  1514. const id_ad_caIssuers = `${id_ad}.2`;
  1515. const id_ad_ocsp = `${id_ad}.1`;
  1516. const id_sha1 = "1.3.14.3.2.26";
  1517. const id_sha256 = "2.16.840.1.101.3.4.2.1";
  1518. const id_sha384 = "2.16.840.1.101.3.4.2.2";
  1519. const id_sha512 = "2.16.840.1.101.3.4.2.3";
  1520. const KEY_IDENTIFIER$1 = "keyIdentifier";
  1521. const AUTHORITY_CERT_ISSUER = "authorityCertIssuer";
  1522. const AUTHORITY_CERT_SERIAL_NUMBER = "authorityCertSerialNumber";
  1523. const CLEAR_PROPS$1q = [
  1524. KEY_IDENTIFIER$1,
  1525. AUTHORITY_CERT_ISSUER,
  1526. AUTHORITY_CERT_SERIAL_NUMBER,
  1527. ];
  1528. class AuthorityKeyIdentifier extends PkiObject {
  1529. constructor(parameters = {}) {
  1530. super();
  1531. if (KEY_IDENTIFIER$1 in parameters) {
  1532. this.keyIdentifier = pvutils__namespace.getParametersValue(parameters, KEY_IDENTIFIER$1, AuthorityKeyIdentifier.defaultValues(KEY_IDENTIFIER$1));
  1533. }
  1534. if (AUTHORITY_CERT_ISSUER in parameters) {
  1535. this.authorityCertIssuer = pvutils__namespace.getParametersValue(parameters, AUTHORITY_CERT_ISSUER, AuthorityKeyIdentifier.defaultValues(AUTHORITY_CERT_ISSUER));
  1536. }
  1537. if (AUTHORITY_CERT_SERIAL_NUMBER in parameters) {
  1538. this.authorityCertSerialNumber = pvutils__namespace.getParametersValue(parameters, AUTHORITY_CERT_SERIAL_NUMBER, AuthorityKeyIdentifier.defaultValues(AUTHORITY_CERT_SERIAL_NUMBER));
  1539. }
  1540. if (parameters.schema) {
  1541. this.fromSchema(parameters.schema);
  1542. }
  1543. }
  1544. static defaultValues(memberName) {
  1545. switch (memberName) {
  1546. case KEY_IDENTIFIER$1:
  1547. return new asn1js__namespace.OctetString();
  1548. case AUTHORITY_CERT_ISSUER:
  1549. return [];
  1550. case AUTHORITY_CERT_SERIAL_NUMBER:
  1551. return new asn1js__namespace.Integer();
  1552. default:
  1553. return super.defaultValues(memberName);
  1554. }
  1555. }
  1556. static schema(parameters = {}) {
  1557. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  1558. return (new asn1js__namespace.Sequence({
  1559. name: (names.blockName || EMPTY_STRING),
  1560. value: [
  1561. new asn1js__namespace.Primitive({
  1562. name: (names.keyIdentifier || EMPTY_STRING),
  1563. optional: true,
  1564. idBlock: {
  1565. tagClass: 3,
  1566. tagNumber: 0
  1567. }
  1568. }),
  1569. new asn1js__namespace.Constructed({
  1570. optional: true,
  1571. idBlock: {
  1572. tagClass: 3,
  1573. tagNumber: 1
  1574. },
  1575. value: [
  1576. new asn1js__namespace.Repeated({
  1577. name: (names.authorityCertIssuer || EMPTY_STRING),
  1578. value: GeneralName.schema()
  1579. })
  1580. ]
  1581. }),
  1582. new asn1js__namespace.Primitive({
  1583. name: (names.authorityCertSerialNumber || EMPTY_STRING),
  1584. optional: true,
  1585. idBlock: {
  1586. tagClass: 3,
  1587. tagNumber: 2
  1588. }
  1589. })
  1590. ]
  1591. }));
  1592. }
  1593. fromSchema(schema) {
  1594. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1q);
  1595. const asn1 = asn1js__namespace.compareSchema(schema, schema, AuthorityKeyIdentifier.schema({
  1596. names: {
  1597. keyIdentifier: KEY_IDENTIFIER$1,
  1598. authorityCertIssuer: AUTHORITY_CERT_ISSUER,
  1599. authorityCertSerialNumber: AUTHORITY_CERT_SERIAL_NUMBER
  1600. }
  1601. }));
  1602. AsnError.assertSchema(asn1, this.className);
  1603. if (KEY_IDENTIFIER$1 in asn1.result)
  1604. this.keyIdentifier = new asn1js__namespace.OctetString({ valueHex: asn1.result.keyIdentifier.valueBlock.valueHex });
  1605. if (AUTHORITY_CERT_ISSUER in asn1.result)
  1606. this.authorityCertIssuer = Array.from(asn1.result.authorityCertIssuer, o => new GeneralName({ schema: o }));
  1607. if (AUTHORITY_CERT_SERIAL_NUMBER in asn1.result)
  1608. this.authorityCertSerialNumber = new asn1js__namespace.Integer({ valueHex: asn1.result.authorityCertSerialNumber.valueBlock.valueHex });
  1609. }
  1610. toSchema() {
  1611. const outputArray = [];
  1612. if (this.keyIdentifier) {
  1613. outputArray.push(new asn1js__namespace.Primitive({
  1614. idBlock: {
  1615. tagClass: 3,
  1616. tagNumber: 0
  1617. },
  1618. valueHex: this.keyIdentifier.valueBlock.valueHexView
  1619. }));
  1620. }
  1621. if (this.authorityCertIssuer) {
  1622. outputArray.push(new asn1js__namespace.Constructed({
  1623. idBlock: {
  1624. tagClass: 3,
  1625. tagNumber: 1
  1626. },
  1627. value: Array.from(this.authorityCertIssuer, o => o.toSchema())
  1628. }));
  1629. }
  1630. if (this.authorityCertSerialNumber) {
  1631. outputArray.push(new asn1js__namespace.Primitive({
  1632. idBlock: {
  1633. tagClass: 3,
  1634. tagNumber: 2
  1635. },
  1636. valueHex: this.authorityCertSerialNumber.valueBlock.valueHexView
  1637. }));
  1638. }
  1639. return (new asn1js__namespace.Sequence({
  1640. value: outputArray
  1641. }));
  1642. }
  1643. toJSON() {
  1644. const object = {};
  1645. if (this.keyIdentifier) {
  1646. object.keyIdentifier = this.keyIdentifier.toJSON();
  1647. }
  1648. if (this.authorityCertIssuer) {
  1649. object.authorityCertIssuer = Array.from(this.authorityCertIssuer, o => o.toJSON());
  1650. }
  1651. if (this.authorityCertSerialNumber) {
  1652. object.authorityCertSerialNumber = this.authorityCertSerialNumber.toJSON();
  1653. }
  1654. return object;
  1655. }
  1656. }
  1657. AuthorityKeyIdentifier.CLASS_NAME = "AuthorityKeyIdentifier";
  1658. const PATH_LENGTH_CONSTRAINT = "pathLenConstraint";
  1659. const CA = "cA";
  1660. class BasicConstraints extends PkiObject {
  1661. constructor(parameters = {}) {
  1662. super();
  1663. this.cA = pvutils__namespace.getParametersValue(parameters, CA, false);
  1664. if (PATH_LENGTH_CONSTRAINT in parameters) {
  1665. this.pathLenConstraint = pvutils__namespace.getParametersValue(parameters, PATH_LENGTH_CONSTRAINT, 0);
  1666. }
  1667. if (parameters.schema) {
  1668. this.fromSchema(parameters.schema);
  1669. }
  1670. }
  1671. static defaultValues(memberName) {
  1672. switch (memberName) {
  1673. case CA:
  1674. return false;
  1675. default:
  1676. return super.defaultValues(memberName);
  1677. }
  1678. }
  1679. static schema(parameters = {}) {
  1680. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  1681. return (new asn1js__namespace.Sequence({
  1682. name: (names.blockName || EMPTY_STRING),
  1683. value: [
  1684. new asn1js__namespace.Boolean({
  1685. optional: true,
  1686. name: (names.cA || EMPTY_STRING)
  1687. }),
  1688. new asn1js__namespace.Integer({
  1689. optional: true,
  1690. name: (names.pathLenConstraint || EMPTY_STRING)
  1691. })
  1692. ]
  1693. }));
  1694. }
  1695. fromSchema(schema) {
  1696. pvutils__namespace.clearProps(schema, [
  1697. CA,
  1698. PATH_LENGTH_CONSTRAINT
  1699. ]);
  1700. const asn1 = asn1js__namespace.compareSchema(schema, schema, BasicConstraints.schema({
  1701. names: {
  1702. cA: CA,
  1703. pathLenConstraint: PATH_LENGTH_CONSTRAINT
  1704. }
  1705. }));
  1706. AsnError.assertSchema(asn1, this.className);
  1707. if (CA in asn1.result) {
  1708. this.cA = asn1.result.cA.valueBlock.value;
  1709. }
  1710. if (PATH_LENGTH_CONSTRAINT in asn1.result) {
  1711. if (asn1.result.pathLenConstraint.valueBlock.isHexOnly) {
  1712. this.pathLenConstraint = asn1.result.pathLenConstraint;
  1713. }
  1714. else {
  1715. this.pathLenConstraint = asn1.result.pathLenConstraint.valueBlock.valueDec;
  1716. }
  1717. }
  1718. }
  1719. toSchema() {
  1720. const outputArray = [];
  1721. if (this.cA !== BasicConstraints.defaultValues(CA))
  1722. outputArray.push(new asn1js__namespace.Boolean({ value: this.cA }));
  1723. if (PATH_LENGTH_CONSTRAINT in this) {
  1724. if (this.pathLenConstraint instanceof asn1js__namespace.Integer) {
  1725. outputArray.push(this.pathLenConstraint);
  1726. }
  1727. else {
  1728. outputArray.push(new asn1js__namespace.Integer({ value: this.pathLenConstraint }));
  1729. }
  1730. }
  1731. return (new asn1js__namespace.Sequence({
  1732. value: outputArray
  1733. }));
  1734. }
  1735. toJSON() {
  1736. const object = {};
  1737. if (this.cA !== BasicConstraints.defaultValues(CA)) {
  1738. object.cA = this.cA;
  1739. }
  1740. if (PATH_LENGTH_CONSTRAINT in this) {
  1741. if (this.pathLenConstraint instanceof asn1js__namespace.Integer) {
  1742. object.pathLenConstraint = this.pathLenConstraint.toJSON();
  1743. }
  1744. else {
  1745. object.pathLenConstraint = this.pathLenConstraint;
  1746. }
  1747. }
  1748. return object;
  1749. }
  1750. }
  1751. BasicConstraints.CLASS_NAME = "BasicConstraints";
  1752. const CERTIFICATE_INDEX = "certificateIndex";
  1753. const KEY_INDEX = "keyIndex";
  1754. class CAVersion extends PkiObject {
  1755. constructor(parameters = {}) {
  1756. super();
  1757. this.certificateIndex = pvutils__namespace.getParametersValue(parameters, CERTIFICATE_INDEX, CAVersion.defaultValues(CERTIFICATE_INDEX));
  1758. this.keyIndex = pvutils__namespace.getParametersValue(parameters, KEY_INDEX, CAVersion.defaultValues(KEY_INDEX));
  1759. if (parameters.schema) {
  1760. this.fromSchema(parameters.schema);
  1761. }
  1762. }
  1763. static defaultValues(memberName) {
  1764. switch (memberName) {
  1765. case CERTIFICATE_INDEX:
  1766. case KEY_INDEX:
  1767. return 0;
  1768. default:
  1769. return super.defaultValues(memberName);
  1770. }
  1771. }
  1772. static schema() {
  1773. return (new asn1js__namespace.Integer());
  1774. }
  1775. fromSchema(schema) {
  1776. if (schema.constructor.blockName() !== asn1js__namespace.Integer.blockName()) {
  1777. throw new Error("Object's schema was not verified against input data for CAVersion");
  1778. }
  1779. let value = schema.valueBlock.valueHex.slice(0);
  1780. const valueView = new Uint8Array(value);
  1781. switch (true) {
  1782. case (value.byteLength < 4):
  1783. {
  1784. const tempValue = new ArrayBuffer(4);
  1785. const tempValueView = new Uint8Array(tempValue);
  1786. tempValueView.set(valueView, 4 - value.byteLength);
  1787. value = tempValue.slice(0);
  1788. }
  1789. break;
  1790. case (value.byteLength > 4):
  1791. {
  1792. const tempValue = new ArrayBuffer(4);
  1793. const tempValueView = new Uint8Array(tempValue);
  1794. tempValueView.set(valueView.slice(0, 4));
  1795. value = tempValue.slice(0);
  1796. }
  1797. break;
  1798. }
  1799. const keyIndexBuffer = value.slice(0, 2);
  1800. const keyIndexView8 = new Uint8Array(keyIndexBuffer);
  1801. let temp = keyIndexView8[0];
  1802. keyIndexView8[0] = keyIndexView8[1];
  1803. keyIndexView8[1] = temp;
  1804. const keyIndexView16 = new Uint16Array(keyIndexBuffer);
  1805. this.keyIndex = keyIndexView16[0];
  1806. const certificateIndexBuffer = value.slice(2);
  1807. const certificateIndexView8 = new Uint8Array(certificateIndexBuffer);
  1808. temp = certificateIndexView8[0];
  1809. certificateIndexView8[0] = certificateIndexView8[1];
  1810. certificateIndexView8[1] = temp;
  1811. const certificateIndexView16 = new Uint16Array(certificateIndexBuffer);
  1812. this.certificateIndex = certificateIndexView16[0];
  1813. }
  1814. toSchema() {
  1815. const certificateIndexBuffer = new ArrayBuffer(2);
  1816. const certificateIndexView = new Uint16Array(certificateIndexBuffer);
  1817. certificateIndexView[0] = this.certificateIndex;
  1818. const certificateIndexView8 = new Uint8Array(certificateIndexBuffer);
  1819. let temp = certificateIndexView8[0];
  1820. certificateIndexView8[0] = certificateIndexView8[1];
  1821. certificateIndexView8[1] = temp;
  1822. const keyIndexBuffer = new ArrayBuffer(2);
  1823. const keyIndexView = new Uint16Array(keyIndexBuffer);
  1824. keyIndexView[0] = this.keyIndex;
  1825. const keyIndexView8 = new Uint8Array(keyIndexBuffer);
  1826. temp = keyIndexView8[0];
  1827. keyIndexView8[0] = keyIndexView8[1];
  1828. keyIndexView8[1] = temp;
  1829. return (new asn1js__namespace.Integer({
  1830. valueHex: pvutils__namespace.utilConcatBuf(keyIndexBuffer, certificateIndexBuffer)
  1831. }));
  1832. }
  1833. toJSON() {
  1834. return {
  1835. certificateIndex: this.certificateIndex,
  1836. keyIndex: this.keyIndex
  1837. };
  1838. }
  1839. }
  1840. CAVersion.CLASS_NAME = "CAVersion";
  1841. const POLICY_QUALIFIER_ID = "policyQualifierId";
  1842. const QUALIFIER = "qualifier";
  1843. const CLEAR_PROPS$1p = [
  1844. POLICY_QUALIFIER_ID,
  1845. QUALIFIER
  1846. ];
  1847. class PolicyQualifierInfo extends PkiObject {
  1848. constructor(parameters = {}) {
  1849. super();
  1850. this.policyQualifierId = pvutils__namespace.getParametersValue(parameters, POLICY_QUALIFIER_ID, PolicyQualifierInfo.defaultValues(POLICY_QUALIFIER_ID));
  1851. this.qualifier = pvutils__namespace.getParametersValue(parameters, QUALIFIER, PolicyQualifierInfo.defaultValues(QUALIFIER));
  1852. if (parameters.schema) {
  1853. this.fromSchema(parameters.schema);
  1854. }
  1855. }
  1856. static defaultValues(memberName) {
  1857. switch (memberName) {
  1858. case POLICY_QUALIFIER_ID:
  1859. return EMPTY_STRING;
  1860. case QUALIFIER:
  1861. return new asn1js__namespace.Any();
  1862. default:
  1863. return super.defaultValues(memberName);
  1864. }
  1865. }
  1866. static schema(parameters = {}) {
  1867. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  1868. return (new asn1js__namespace.Sequence({
  1869. name: (names.blockName || EMPTY_STRING),
  1870. value: [
  1871. new asn1js__namespace.ObjectIdentifier({ name: (names.policyQualifierId || EMPTY_STRING) }),
  1872. new asn1js__namespace.Any({ name: (names.qualifier || EMPTY_STRING) })
  1873. ]
  1874. }));
  1875. }
  1876. fromSchema(schema) {
  1877. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1p);
  1878. const asn1 = asn1js__namespace.compareSchema(schema, schema, PolicyQualifierInfo.schema({
  1879. names: {
  1880. policyQualifierId: POLICY_QUALIFIER_ID,
  1881. qualifier: QUALIFIER
  1882. }
  1883. }));
  1884. AsnError.assertSchema(asn1, this.className);
  1885. this.policyQualifierId = asn1.result.policyQualifierId.valueBlock.toString();
  1886. this.qualifier = asn1.result.qualifier;
  1887. }
  1888. toSchema() {
  1889. return (new asn1js__namespace.Sequence({
  1890. value: [
  1891. new asn1js__namespace.ObjectIdentifier({ value: this.policyQualifierId }),
  1892. this.qualifier
  1893. ]
  1894. }));
  1895. }
  1896. toJSON() {
  1897. return {
  1898. policyQualifierId: this.policyQualifierId,
  1899. qualifier: this.qualifier.toJSON()
  1900. };
  1901. }
  1902. }
  1903. PolicyQualifierInfo.CLASS_NAME = "PolicyQualifierInfo";
  1904. const POLICY_IDENTIFIER = "policyIdentifier";
  1905. const POLICY_QUALIFIERS = "policyQualifiers";
  1906. const CLEAR_PROPS$1o = [
  1907. POLICY_IDENTIFIER,
  1908. POLICY_QUALIFIERS
  1909. ];
  1910. class PolicyInformation extends PkiObject {
  1911. constructor(parameters = {}) {
  1912. super();
  1913. this.policyIdentifier = pvutils__namespace.getParametersValue(parameters, POLICY_IDENTIFIER, PolicyInformation.defaultValues(POLICY_IDENTIFIER));
  1914. if (POLICY_QUALIFIERS in parameters) {
  1915. this.policyQualifiers = pvutils__namespace.getParametersValue(parameters, POLICY_QUALIFIERS, PolicyInformation.defaultValues(POLICY_QUALIFIERS));
  1916. }
  1917. if (parameters.schema) {
  1918. this.fromSchema(parameters.schema);
  1919. }
  1920. }
  1921. static defaultValues(memberName) {
  1922. switch (memberName) {
  1923. case POLICY_IDENTIFIER:
  1924. return EMPTY_STRING;
  1925. case POLICY_QUALIFIERS:
  1926. return [];
  1927. default:
  1928. return super.defaultValues(memberName);
  1929. }
  1930. }
  1931. static schema(parameters = {}) {
  1932. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  1933. return (new asn1js__namespace.Sequence({
  1934. name: (names.blockName || EMPTY_STRING),
  1935. value: [
  1936. new asn1js__namespace.ObjectIdentifier({ name: (names.policyIdentifier || EMPTY_STRING) }),
  1937. new asn1js__namespace.Sequence({
  1938. optional: true,
  1939. value: [
  1940. new asn1js__namespace.Repeated({
  1941. name: (names.policyQualifiers || EMPTY_STRING),
  1942. value: PolicyQualifierInfo.schema()
  1943. })
  1944. ]
  1945. })
  1946. ]
  1947. }));
  1948. }
  1949. fromSchema(schema) {
  1950. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1o);
  1951. const asn1 = asn1js__namespace.compareSchema(schema, schema, PolicyInformation.schema({
  1952. names: {
  1953. policyIdentifier: POLICY_IDENTIFIER,
  1954. policyQualifiers: POLICY_QUALIFIERS
  1955. }
  1956. }));
  1957. AsnError.assertSchema(asn1, this.className);
  1958. this.policyIdentifier = asn1.result.policyIdentifier.valueBlock.toString();
  1959. if (POLICY_QUALIFIERS in asn1.result) {
  1960. this.policyQualifiers = Array.from(asn1.result.policyQualifiers, element => new PolicyQualifierInfo({ schema: element }));
  1961. }
  1962. }
  1963. toSchema() {
  1964. const outputArray = [];
  1965. outputArray.push(new asn1js__namespace.ObjectIdentifier({ value: this.policyIdentifier }));
  1966. if (this.policyQualifiers) {
  1967. outputArray.push(new asn1js__namespace.Sequence({
  1968. value: Array.from(this.policyQualifiers, o => o.toSchema())
  1969. }));
  1970. }
  1971. return (new asn1js__namespace.Sequence({
  1972. value: outputArray
  1973. }));
  1974. }
  1975. toJSON() {
  1976. const res = {
  1977. policyIdentifier: this.policyIdentifier
  1978. };
  1979. if (this.policyQualifiers)
  1980. res.policyQualifiers = Array.from(this.policyQualifiers, o => o.toJSON());
  1981. return res;
  1982. }
  1983. }
  1984. PolicyInformation.CLASS_NAME = "PolicyInformation";
  1985. const CERTIFICATE_POLICIES = "certificatePolicies";
  1986. const CLEAR_PROPS$1n = [
  1987. CERTIFICATE_POLICIES,
  1988. ];
  1989. class CertificatePolicies extends PkiObject {
  1990. constructor(parameters = {}) {
  1991. super();
  1992. this.certificatePolicies = pvutils__namespace.getParametersValue(parameters, CERTIFICATE_POLICIES, CertificatePolicies.defaultValues(CERTIFICATE_POLICIES));
  1993. if (parameters.schema) {
  1994. this.fromSchema(parameters.schema);
  1995. }
  1996. }
  1997. static defaultValues(memberName) {
  1998. switch (memberName) {
  1999. case CERTIFICATE_POLICIES:
  2000. return [];
  2001. default:
  2002. return super.defaultValues(memberName);
  2003. }
  2004. }
  2005. static schema(parameters = {}) {
  2006. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  2007. return (new asn1js__namespace.Sequence({
  2008. name: (names.blockName || EMPTY_STRING),
  2009. value: [
  2010. new asn1js__namespace.Repeated({
  2011. name: (names.certificatePolicies || EMPTY_STRING),
  2012. value: PolicyInformation.schema()
  2013. })
  2014. ]
  2015. }));
  2016. }
  2017. fromSchema(schema) {
  2018. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1n);
  2019. const asn1 = asn1js__namespace.compareSchema(schema, schema, CertificatePolicies.schema({
  2020. names: {
  2021. certificatePolicies: CERTIFICATE_POLICIES
  2022. }
  2023. }));
  2024. AsnError.assertSchema(asn1, this.className);
  2025. this.certificatePolicies = Array.from(asn1.result.certificatePolicies, element => new PolicyInformation({ schema: element }));
  2026. }
  2027. toSchema() {
  2028. return (new asn1js__namespace.Sequence({
  2029. value: Array.from(this.certificatePolicies, o => o.toSchema())
  2030. }));
  2031. }
  2032. toJSON() {
  2033. return {
  2034. certificatePolicies: Array.from(this.certificatePolicies, o => o.toJSON())
  2035. };
  2036. }
  2037. }
  2038. CertificatePolicies.CLASS_NAME = "CertificatePolicies";
  2039. const TEMPLATE_ID = "templateID";
  2040. const TEMPLATE_MAJOR_VERSION = "templateMajorVersion";
  2041. const TEMPLATE_MINOR_VERSION = "templateMinorVersion";
  2042. const CLEAR_PROPS$1m = [
  2043. TEMPLATE_ID,
  2044. TEMPLATE_MAJOR_VERSION,
  2045. TEMPLATE_MINOR_VERSION
  2046. ];
  2047. class CertificateTemplate extends PkiObject {
  2048. constructor(parameters = {}) {
  2049. super();
  2050. this.templateID = pvutils__namespace.getParametersValue(parameters, TEMPLATE_ID, CertificateTemplate.defaultValues(TEMPLATE_ID));
  2051. if (TEMPLATE_MAJOR_VERSION in parameters) {
  2052. this.templateMajorVersion = pvutils__namespace.getParametersValue(parameters, TEMPLATE_MAJOR_VERSION, CertificateTemplate.defaultValues(TEMPLATE_MAJOR_VERSION));
  2053. }
  2054. if (TEMPLATE_MINOR_VERSION in parameters) {
  2055. this.templateMinorVersion = pvutils__namespace.getParametersValue(parameters, TEMPLATE_MINOR_VERSION, CertificateTemplate.defaultValues(TEMPLATE_MINOR_VERSION));
  2056. }
  2057. if (parameters.schema) {
  2058. this.fromSchema(parameters.schema);
  2059. }
  2060. }
  2061. static defaultValues(memberName) {
  2062. switch (memberName) {
  2063. case TEMPLATE_ID:
  2064. return EMPTY_STRING;
  2065. case TEMPLATE_MAJOR_VERSION:
  2066. case TEMPLATE_MINOR_VERSION:
  2067. return 0;
  2068. default:
  2069. return super.defaultValues(memberName);
  2070. }
  2071. }
  2072. static schema(parameters = {}) {
  2073. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  2074. return (new asn1js__namespace.Sequence({
  2075. name: (names.blockName || EMPTY_STRING),
  2076. value: [
  2077. new asn1js__namespace.ObjectIdentifier({ name: (names.templateID || EMPTY_STRING) }),
  2078. new asn1js__namespace.Integer({
  2079. name: (names.templateMajorVersion || EMPTY_STRING),
  2080. optional: true
  2081. }),
  2082. new asn1js__namespace.Integer({
  2083. name: (names.templateMinorVersion || EMPTY_STRING),
  2084. optional: true
  2085. }),
  2086. ]
  2087. }));
  2088. }
  2089. fromSchema(schema) {
  2090. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1m);
  2091. const asn1 = asn1js__namespace.compareSchema(schema, schema, CertificateTemplate.schema({
  2092. names: {
  2093. templateID: TEMPLATE_ID,
  2094. templateMajorVersion: TEMPLATE_MAJOR_VERSION,
  2095. templateMinorVersion: TEMPLATE_MINOR_VERSION
  2096. }
  2097. }));
  2098. AsnError.assertSchema(asn1, this.className);
  2099. this.templateID = asn1.result.templateID.valueBlock.toString();
  2100. if (TEMPLATE_MAJOR_VERSION in asn1.result) {
  2101. this.templateMajorVersion = asn1.result.templateMajorVersion.valueBlock.valueDec;
  2102. }
  2103. if (TEMPLATE_MINOR_VERSION in asn1.result) {
  2104. this.templateMinorVersion = asn1.result.templateMinorVersion.valueBlock.valueDec;
  2105. }
  2106. }
  2107. toSchema() {
  2108. const outputArray = [];
  2109. outputArray.push(new asn1js__namespace.ObjectIdentifier({ value: this.templateID }));
  2110. if (TEMPLATE_MAJOR_VERSION in this) {
  2111. outputArray.push(new asn1js__namespace.Integer({ value: this.templateMajorVersion }));
  2112. }
  2113. if (TEMPLATE_MINOR_VERSION in this) {
  2114. outputArray.push(new asn1js__namespace.Integer({ value: this.templateMinorVersion }));
  2115. }
  2116. return (new asn1js__namespace.Sequence({
  2117. value: outputArray
  2118. }));
  2119. }
  2120. toJSON() {
  2121. const res = {
  2122. templateID: this.templateID
  2123. };
  2124. if (TEMPLATE_MAJOR_VERSION in this)
  2125. res.templateMajorVersion = this.templateMajorVersion;
  2126. if (TEMPLATE_MINOR_VERSION in this)
  2127. res.templateMinorVersion = this.templateMinorVersion;
  2128. return res;
  2129. }
  2130. }
  2131. const DISTRIBUTION_POINT$1 = "distributionPoint";
  2132. const DISTRIBUTION_POINT_NAMES$1 = "distributionPointNames";
  2133. const REASONS = "reasons";
  2134. const CRL_ISSUER = "cRLIssuer";
  2135. const CRL_ISSUER_NAMES = "cRLIssuerNames";
  2136. const CLEAR_PROPS$1l = [
  2137. DISTRIBUTION_POINT$1,
  2138. DISTRIBUTION_POINT_NAMES$1,
  2139. REASONS,
  2140. CRL_ISSUER,
  2141. CRL_ISSUER_NAMES,
  2142. ];
  2143. class DistributionPoint extends PkiObject {
  2144. constructor(parameters = {}) {
  2145. super();
  2146. if (DISTRIBUTION_POINT$1 in parameters) {
  2147. this.distributionPoint = pvutils__namespace.getParametersValue(parameters, DISTRIBUTION_POINT$1, DistributionPoint.defaultValues(DISTRIBUTION_POINT$1));
  2148. }
  2149. if (REASONS in parameters) {
  2150. this.reasons = pvutils__namespace.getParametersValue(parameters, REASONS, DistributionPoint.defaultValues(REASONS));
  2151. }
  2152. if (CRL_ISSUER in parameters) {
  2153. this.cRLIssuer = pvutils__namespace.getParametersValue(parameters, CRL_ISSUER, DistributionPoint.defaultValues(CRL_ISSUER));
  2154. }
  2155. if (parameters.schema) {
  2156. this.fromSchema(parameters.schema);
  2157. }
  2158. }
  2159. static defaultValues(memberName) {
  2160. switch (memberName) {
  2161. case DISTRIBUTION_POINT$1:
  2162. return [];
  2163. case REASONS:
  2164. return new asn1js__namespace.BitString();
  2165. case CRL_ISSUER:
  2166. return [];
  2167. default:
  2168. return super.defaultValues(memberName);
  2169. }
  2170. }
  2171. static schema(parameters = {}) {
  2172. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  2173. return (new asn1js__namespace.Sequence({
  2174. name: (names.blockName || EMPTY_STRING),
  2175. value: [
  2176. new asn1js__namespace.Constructed({
  2177. optional: true,
  2178. idBlock: {
  2179. tagClass: 3,
  2180. tagNumber: 0
  2181. },
  2182. value: [
  2183. new asn1js__namespace.Choice({
  2184. value: [
  2185. new asn1js__namespace.Constructed({
  2186. name: (names.distributionPoint || EMPTY_STRING),
  2187. optional: true,
  2188. idBlock: {
  2189. tagClass: 3,
  2190. tagNumber: 0
  2191. },
  2192. value: [
  2193. new asn1js__namespace.Repeated({
  2194. name: (names.distributionPointNames || EMPTY_STRING),
  2195. value: GeneralName.schema()
  2196. })
  2197. ]
  2198. }),
  2199. new asn1js__namespace.Constructed({
  2200. name: (names.distributionPoint || EMPTY_STRING),
  2201. optional: true,
  2202. idBlock: {
  2203. tagClass: 3,
  2204. tagNumber: 1
  2205. },
  2206. value: RelativeDistinguishedNames.schema().valueBlock.value
  2207. })
  2208. ]
  2209. })
  2210. ]
  2211. }),
  2212. new asn1js__namespace.Primitive({
  2213. name: (names.reasons || EMPTY_STRING),
  2214. optional: true,
  2215. idBlock: {
  2216. tagClass: 3,
  2217. tagNumber: 1
  2218. }
  2219. }),
  2220. new asn1js__namespace.Constructed({
  2221. name: (names.cRLIssuer || EMPTY_STRING),
  2222. optional: true,
  2223. idBlock: {
  2224. tagClass: 3,
  2225. tagNumber: 2
  2226. },
  2227. value: [
  2228. new asn1js__namespace.Repeated({
  2229. name: (names.cRLIssuerNames || EMPTY_STRING),
  2230. value: GeneralName.schema()
  2231. })
  2232. ]
  2233. })
  2234. ]
  2235. }));
  2236. }
  2237. fromSchema(schema) {
  2238. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1l);
  2239. const asn1 = asn1js__namespace.compareSchema(schema, schema, DistributionPoint.schema({
  2240. names: {
  2241. distributionPoint: DISTRIBUTION_POINT$1,
  2242. distributionPointNames: DISTRIBUTION_POINT_NAMES$1,
  2243. reasons: REASONS,
  2244. cRLIssuer: CRL_ISSUER,
  2245. cRLIssuerNames: CRL_ISSUER_NAMES
  2246. }
  2247. }));
  2248. AsnError.assertSchema(asn1, this.className);
  2249. if (DISTRIBUTION_POINT$1 in asn1.result) {
  2250. if (asn1.result.distributionPoint.idBlock.tagNumber === 0) {
  2251. this.distributionPoint = Array.from(asn1.result.distributionPointNames, element => new GeneralName({ schema: element }));
  2252. }
  2253. if (asn1.result.distributionPoint.idBlock.tagNumber === 1) {
  2254. this.distributionPoint = new RelativeDistinguishedNames({
  2255. schema: new asn1js__namespace.Sequence({
  2256. value: asn1.result.distributionPoint.valueBlock.value
  2257. })
  2258. });
  2259. }
  2260. }
  2261. if (REASONS in asn1.result) {
  2262. this.reasons = new asn1js__namespace.BitString({ valueHex: asn1.result.reasons.valueBlock.valueHex });
  2263. }
  2264. if (CRL_ISSUER in asn1.result) {
  2265. this.cRLIssuer = Array.from(asn1.result.cRLIssuerNames, element => new GeneralName({ schema: element }));
  2266. }
  2267. }
  2268. toSchema() {
  2269. const outputArray = [];
  2270. if (this.distributionPoint) {
  2271. let internalValue;
  2272. if (this.distributionPoint instanceof Array) {
  2273. internalValue = new asn1js__namespace.Constructed({
  2274. idBlock: {
  2275. tagClass: 3,
  2276. tagNumber: 0
  2277. },
  2278. value: Array.from(this.distributionPoint, o => o.toSchema())
  2279. });
  2280. }
  2281. else {
  2282. internalValue = new asn1js__namespace.Constructed({
  2283. idBlock: {
  2284. tagClass: 3,
  2285. tagNumber: 1
  2286. },
  2287. value: [this.distributionPoint.toSchema()]
  2288. });
  2289. }
  2290. outputArray.push(new asn1js__namespace.Constructed({
  2291. idBlock: {
  2292. tagClass: 3,
  2293. tagNumber: 0
  2294. },
  2295. value: [internalValue]
  2296. }));
  2297. }
  2298. if (this.reasons) {
  2299. outputArray.push(new asn1js__namespace.Primitive({
  2300. idBlock: {
  2301. tagClass: 3,
  2302. tagNumber: 1
  2303. },
  2304. valueHex: this.reasons.valueBlock.valueHexView
  2305. }));
  2306. }
  2307. if (this.cRLIssuer) {
  2308. outputArray.push(new asn1js__namespace.Constructed({
  2309. idBlock: {
  2310. tagClass: 3,
  2311. tagNumber: 2
  2312. },
  2313. value: Array.from(this.cRLIssuer, o => o.toSchema())
  2314. }));
  2315. }
  2316. return (new asn1js__namespace.Sequence({
  2317. value: outputArray
  2318. }));
  2319. }
  2320. toJSON() {
  2321. const object = {};
  2322. if (this.distributionPoint) {
  2323. if (this.distributionPoint instanceof Array) {
  2324. object.distributionPoint = Array.from(this.distributionPoint, o => o.toJSON());
  2325. }
  2326. else {
  2327. object.distributionPoint = this.distributionPoint.toJSON();
  2328. }
  2329. }
  2330. if (this.reasons) {
  2331. object.reasons = this.reasons.toJSON();
  2332. }
  2333. if (this.cRLIssuer) {
  2334. object.cRLIssuer = Array.from(this.cRLIssuer, o => o.toJSON());
  2335. }
  2336. return object;
  2337. }
  2338. }
  2339. DistributionPoint.CLASS_NAME = "DistributionPoint";
  2340. const DISTRIBUTION_POINTS = "distributionPoints";
  2341. const CLEAR_PROPS$1k = [
  2342. DISTRIBUTION_POINTS
  2343. ];
  2344. class CRLDistributionPoints extends PkiObject {
  2345. constructor(parameters = {}) {
  2346. super();
  2347. this.distributionPoints = pvutils__namespace.getParametersValue(parameters, DISTRIBUTION_POINTS, CRLDistributionPoints.defaultValues(DISTRIBUTION_POINTS));
  2348. if (parameters.schema) {
  2349. this.fromSchema(parameters.schema);
  2350. }
  2351. }
  2352. static defaultValues(memberName) {
  2353. switch (memberName) {
  2354. case DISTRIBUTION_POINTS:
  2355. return [];
  2356. default:
  2357. return super.defaultValues(memberName);
  2358. }
  2359. }
  2360. static schema(parameters = {}) {
  2361. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  2362. return (new asn1js__namespace.Sequence({
  2363. name: (names.blockName || EMPTY_STRING),
  2364. value: [
  2365. new asn1js__namespace.Repeated({
  2366. name: (names.distributionPoints || EMPTY_STRING),
  2367. value: DistributionPoint.schema()
  2368. })
  2369. ]
  2370. }));
  2371. }
  2372. fromSchema(schema) {
  2373. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1k);
  2374. const asn1 = asn1js__namespace.compareSchema(schema, schema, CRLDistributionPoints.schema({
  2375. names: {
  2376. distributionPoints: DISTRIBUTION_POINTS
  2377. }
  2378. }));
  2379. AsnError.assertSchema(asn1, this.className);
  2380. this.distributionPoints = Array.from(asn1.result.distributionPoints, element => new DistributionPoint({ schema: element }));
  2381. }
  2382. toSchema() {
  2383. return (new asn1js__namespace.Sequence({
  2384. value: Array.from(this.distributionPoints, o => o.toSchema())
  2385. }));
  2386. }
  2387. toJSON() {
  2388. return {
  2389. distributionPoints: Array.from(this.distributionPoints, o => o.toJSON())
  2390. };
  2391. }
  2392. }
  2393. CRLDistributionPoints.CLASS_NAME = "CRLDistributionPoints";
  2394. const KEY_PURPOSES = "keyPurposes";
  2395. const CLEAR_PROPS$1j = [
  2396. KEY_PURPOSES,
  2397. ];
  2398. class ExtKeyUsage extends PkiObject {
  2399. constructor(parameters = {}) {
  2400. super();
  2401. this.keyPurposes = pvutils__namespace.getParametersValue(parameters, KEY_PURPOSES, ExtKeyUsage.defaultValues(KEY_PURPOSES));
  2402. if (parameters.schema) {
  2403. this.fromSchema(parameters.schema);
  2404. }
  2405. }
  2406. static defaultValues(memberName) {
  2407. switch (memberName) {
  2408. case KEY_PURPOSES:
  2409. return [];
  2410. default:
  2411. return super.defaultValues(memberName);
  2412. }
  2413. }
  2414. static schema(parameters = {}) {
  2415. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  2416. return (new asn1js__namespace.Sequence({
  2417. name: (names.blockName || EMPTY_STRING),
  2418. value: [
  2419. new asn1js__namespace.Repeated({
  2420. name: (names.keyPurposes || EMPTY_STRING),
  2421. value: new asn1js__namespace.ObjectIdentifier()
  2422. })
  2423. ]
  2424. }));
  2425. }
  2426. fromSchema(schema) {
  2427. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1j);
  2428. const asn1 = asn1js__namespace.compareSchema(schema, schema, ExtKeyUsage.schema({
  2429. names: {
  2430. keyPurposes: KEY_PURPOSES
  2431. }
  2432. }));
  2433. AsnError.assertSchema(asn1, this.className);
  2434. this.keyPurposes = Array.from(asn1.result.keyPurposes, (element) => element.valueBlock.toString());
  2435. }
  2436. toSchema() {
  2437. return (new asn1js__namespace.Sequence({
  2438. value: Array.from(this.keyPurposes, element => new asn1js__namespace.ObjectIdentifier({ value: element }))
  2439. }));
  2440. }
  2441. toJSON() {
  2442. return {
  2443. keyPurposes: Array.from(this.keyPurposes)
  2444. };
  2445. }
  2446. }
  2447. ExtKeyUsage.CLASS_NAME = "ExtKeyUsage";
  2448. const ACCESS_DESCRIPTIONS = "accessDescriptions";
  2449. class InfoAccess extends PkiObject {
  2450. constructor(parameters = {}) {
  2451. super();
  2452. this.accessDescriptions = pvutils__namespace.getParametersValue(parameters, ACCESS_DESCRIPTIONS, InfoAccess.defaultValues(ACCESS_DESCRIPTIONS));
  2453. if (parameters.schema) {
  2454. this.fromSchema(parameters.schema);
  2455. }
  2456. }
  2457. static defaultValues(memberName) {
  2458. switch (memberName) {
  2459. case ACCESS_DESCRIPTIONS:
  2460. return [];
  2461. default:
  2462. return super.defaultValues(memberName);
  2463. }
  2464. }
  2465. static schema(parameters = {}) {
  2466. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  2467. return (new asn1js__namespace.Sequence({
  2468. name: (names.blockName || EMPTY_STRING),
  2469. value: [
  2470. new asn1js__namespace.Repeated({
  2471. name: (names.accessDescriptions || EMPTY_STRING),
  2472. value: AccessDescription.schema()
  2473. })
  2474. ]
  2475. }));
  2476. }
  2477. fromSchema(schema) {
  2478. pvutils__namespace.clearProps(schema, [
  2479. ACCESS_DESCRIPTIONS
  2480. ]);
  2481. const asn1 = asn1js__namespace.compareSchema(schema, schema, InfoAccess.schema({
  2482. names: {
  2483. accessDescriptions: ACCESS_DESCRIPTIONS
  2484. }
  2485. }));
  2486. AsnError.assertSchema(asn1, this.className);
  2487. this.accessDescriptions = Array.from(asn1.result.accessDescriptions, element => new AccessDescription({ schema: element }));
  2488. }
  2489. toSchema() {
  2490. return (new asn1js__namespace.Sequence({
  2491. value: Array.from(this.accessDescriptions, o => o.toSchema())
  2492. }));
  2493. }
  2494. toJSON() {
  2495. return {
  2496. accessDescriptions: Array.from(this.accessDescriptions, o => o.toJSON())
  2497. };
  2498. }
  2499. }
  2500. InfoAccess.CLASS_NAME = "InfoAccess";
  2501. const DISTRIBUTION_POINT = "distributionPoint";
  2502. const DISTRIBUTION_POINT_NAMES = "distributionPointNames";
  2503. const ONLY_CONTAINS_USER_CERTS = "onlyContainsUserCerts";
  2504. const ONLY_CONTAINS_CA_CERTS = "onlyContainsCACerts";
  2505. const ONLY_SOME_REASON = "onlySomeReasons";
  2506. const INDIRECT_CRL = "indirectCRL";
  2507. const ONLY_CONTAINS_ATTRIBUTE_CERTS = "onlyContainsAttributeCerts";
  2508. const CLEAR_PROPS$1i = [
  2509. DISTRIBUTION_POINT,
  2510. DISTRIBUTION_POINT_NAMES,
  2511. ONLY_CONTAINS_USER_CERTS,
  2512. ONLY_CONTAINS_CA_CERTS,
  2513. ONLY_SOME_REASON,
  2514. INDIRECT_CRL,
  2515. ONLY_CONTAINS_ATTRIBUTE_CERTS,
  2516. ];
  2517. class IssuingDistributionPoint extends PkiObject {
  2518. constructor(parameters = {}) {
  2519. super();
  2520. if (DISTRIBUTION_POINT in parameters) {
  2521. this.distributionPoint = pvutils__namespace.getParametersValue(parameters, DISTRIBUTION_POINT, IssuingDistributionPoint.defaultValues(DISTRIBUTION_POINT));
  2522. }
  2523. this.onlyContainsUserCerts = pvutils__namespace.getParametersValue(parameters, ONLY_CONTAINS_USER_CERTS, IssuingDistributionPoint.defaultValues(ONLY_CONTAINS_USER_CERTS));
  2524. this.onlyContainsCACerts = pvutils__namespace.getParametersValue(parameters, ONLY_CONTAINS_CA_CERTS, IssuingDistributionPoint.defaultValues(ONLY_CONTAINS_CA_CERTS));
  2525. if (ONLY_SOME_REASON in parameters) {
  2526. this.onlySomeReasons = pvutils__namespace.getParametersValue(parameters, ONLY_SOME_REASON, IssuingDistributionPoint.defaultValues(ONLY_SOME_REASON));
  2527. }
  2528. this.indirectCRL = pvutils__namespace.getParametersValue(parameters, INDIRECT_CRL, IssuingDistributionPoint.defaultValues(INDIRECT_CRL));
  2529. this.onlyContainsAttributeCerts = pvutils__namespace.getParametersValue(parameters, ONLY_CONTAINS_ATTRIBUTE_CERTS, IssuingDistributionPoint.defaultValues(ONLY_CONTAINS_ATTRIBUTE_CERTS));
  2530. if (parameters.schema) {
  2531. this.fromSchema(parameters.schema);
  2532. }
  2533. }
  2534. static defaultValues(memberName) {
  2535. switch (memberName) {
  2536. case DISTRIBUTION_POINT:
  2537. return [];
  2538. case ONLY_CONTAINS_USER_CERTS:
  2539. return false;
  2540. case ONLY_CONTAINS_CA_CERTS:
  2541. return false;
  2542. case ONLY_SOME_REASON:
  2543. return 0;
  2544. case INDIRECT_CRL:
  2545. return false;
  2546. case ONLY_CONTAINS_ATTRIBUTE_CERTS:
  2547. return false;
  2548. default:
  2549. return super.defaultValues(memberName);
  2550. }
  2551. }
  2552. static schema(parameters = {}) {
  2553. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  2554. return (new asn1js__namespace.Sequence({
  2555. name: (names.blockName || EMPTY_STRING),
  2556. value: [
  2557. new asn1js__namespace.Constructed({
  2558. optional: true,
  2559. idBlock: {
  2560. tagClass: 3,
  2561. tagNumber: 0
  2562. },
  2563. value: [
  2564. new asn1js__namespace.Choice({
  2565. value: [
  2566. new asn1js__namespace.Constructed({
  2567. name: (names.distributionPoint || EMPTY_STRING),
  2568. idBlock: {
  2569. tagClass: 3,
  2570. tagNumber: 0
  2571. },
  2572. value: [
  2573. new asn1js__namespace.Repeated({
  2574. name: (names.distributionPointNames || EMPTY_STRING),
  2575. value: GeneralName.schema()
  2576. })
  2577. ]
  2578. }),
  2579. new asn1js__namespace.Constructed({
  2580. name: (names.distributionPoint || EMPTY_STRING),
  2581. idBlock: {
  2582. tagClass: 3,
  2583. tagNumber: 1
  2584. },
  2585. value: RelativeDistinguishedNames.schema().valueBlock.value
  2586. })
  2587. ]
  2588. })
  2589. ]
  2590. }),
  2591. new asn1js__namespace.Primitive({
  2592. name: (names.onlyContainsUserCerts || EMPTY_STRING),
  2593. optional: true,
  2594. idBlock: {
  2595. tagClass: 3,
  2596. tagNumber: 1
  2597. }
  2598. }),
  2599. new asn1js__namespace.Primitive({
  2600. name: (names.onlyContainsCACerts || EMPTY_STRING),
  2601. optional: true,
  2602. idBlock: {
  2603. tagClass: 3,
  2604. tagNumber: 2
  2605. }
  2606. }),
  2607. new asn1js__namespace.Primitive({
  2608. name: (names.onlySomeReasons || EMPTY_STRING),
  2609. optional: true,
  2610. idBlock: {
  2611. tagClass: 3,
  2612. tagNumber: 3
  2613. }
  2614. }),
  2615. new asn1js__namespace.Primitive({
  2616. name: (names.indirectCRL || EMPTY_STRING),
  2617. optional: true,
  2618. idBlock: {
  2619. tagClass: 3,
  2620. tagNumber: 4
  2621. }
  2622. }),
  2623. new asn1js__namespace.Primitive({
  2624. name: (names.onlyContainsAttributeCerts || EMPTY_STRING),
  2625. optional: true,
  2626. idBlock: {
  2627. tagClass: 3,
  2628. tagNumber: 5
  2629. }
  2630. })
  2631. ]
  2632. }));
  2633. }
  2634. fromSchema(schema) {
  2635. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1i);
  2636. const asn1 = asn1js__namespace.compareSchema(schema, schema, IssuingDistributionPoint.schema({
  2637. names: {
  2638. distributionPoint: DISTRIBUTION_POINT,
  2639. distributionPointNames: DISTRIBUTION_POINT_NAMES,
  2640. onlyContainsUserCerts: ONLY_CONTAINS_USER_CERTS,
  2641. onlyContainsCACerts: ONLY_CONTAINS_CA_CERTS,
  2642. onlySomeReasons: ONLY_SOME_REASON,
  2643. indirectCRL: INDIRECT_CRL,
  2644. onlyContainsAttributeCerts: ONLY_CONTAINS_ATTRIBUTE_CERTS
  2645. }
  2646. }));
  2647. AsnError.assertSchema(asn1, this.className);
  2648. if (DISTRIBUTION_POINT in asn1.result) {
  2649. switch (true) {
  2650. case (asn1.result.distributionPoint.idBlock.tagNumber === 0):
  2651. this.distributionPoint = Array.from(asn1.result.distributionPointNames, element => new GeneralName({ schema: element }));
  2652. break;
  2653. case (asn1.result.distributionPoint.idBlock.tagNumber === 1):
  2654. {
  2655. this.distributionPoint = new RelativeDistinguishedNames({
  2656. schema: new asn1js__namespace.Sequence({
  2657. value: asn1.result.distributionPoint.valueBlock.value
  2658. })
  2659. });
  2660. }
  2661. break;
  2662. default:
  2663. throw new Error("Unknown tagNumber for distributionPoint: {$asn1.result.distributionPoint.idBlock.tagNumber}");
  2664. }
  2665. }
  2666. if (ONLY_CONTAINS_USER_CERTS in asn1.result) {
  2667. const view = new Uint8Array(asn1.result.onlyContainsUserCerts.valueBlock.valueHex);
  2668. this.onlyContainsUserCerts = (view[0] !== 0x00);
  2669. }
  2670. if (ONLY_CONTAINS_CA_CERTS in asn1.result) {
  2671. const view = new Uint8Array(asn1.result.onlyContainsCACerts.valueBlock.valueHex);
  2672. this.onlyContainsCACerts = (view[0] !== 0x00);
  2673. }
  2674. if (ONLY_SOME_REASON in asn1.result) {
  2675. const view = new Uint8Array(asn1.result.onlySomeReasons.valueBlock.valueHex);
  2676. this.onlySomeReasons = view[0];
  2677. }
  2678. if (INDIRECT_CRL in asn1.result) {
  2679. const view = new Uint8Array(asn1.result.indirectCRL.valueBlock.valueHex);
  2680. this.indirectCRL = (view[0] !== 0x00);
  2681. }
  2682. if (ONLY_CONTAINS_ATTRIBUTE_CERTS in asn1.result) {
  2683. const view = new Uint8Array(asn1.result.onlyContainsAttributeCerts.valueBlock.valueHex);
  2684. this.onlyContainsAttributeCerts = (view[0] !== 0x00);
  2685. }
  2686. }
  2687. toSchema() {
  2688. const outputArray = [];
  2689. if (this.distributionPoint) {
  2690. let value;
  2691. if (this.distributionPoint instanceof Array) {
  2692. value = new asn1js__namespace.Constructed({
  2693. idBlock: {
  2694. tagClass: 3,
  2695. tagNumber: 0
  2696. },
  2697. value: Array.from(this.distributionPoint, o => o.toSchema())
  2698. });
  2699. }
  2700. else {
  2701. value = this.distributionPoint.toSchema();
  2702. value.idBlock.tagClass = 3;
  2703. value.idBlock.tagNumber = 1;
  2704. }
  2705. outputArray.push(new asn1js__namespace.Constructed({
  2706. idBlock: {
  2707. tagClass: 3,
  2708. tagNumber: 0
  2709. },
  2710. value: [value]
  2711. }));
  2712. }
  2713. if (this.onlyContainsUserCerts !== IssuingDistributionPoint.defaultValues(ONLY_CONTAINS_USER_CERTS)) {
  2714. outputArray.push(new asn1js__namespace.Primitive({
  2715. idBlock: {
  2716. tagClass: 3,
  2717. tagNumber: 1
  2718. },
  2719. valueHex: (new Uint8Array([0xFF])).buffer
  2720. }));
  2721. }
  2722. if (this.onlyContainsCACerts !== IssuingDistributionPoint.defaultValues(ONLY_CONTAINS_CA_CERTS)) {
  2723. outputArray.push(new asn1js__namespace.Primitive({
  2724. idBlock: {
  2725. tagClass: 3,
  2726. tagNumber: 2
  2727. },
  2728. valueHex: (new Uint8Array([0xFF])).buffer
  2729. }));
  2730. }
  2731. if (this.onlySomeReasons !== undefined) {
  2732. const buffer = new ArrayBuffer(1);
  2733. const view = new Uint8Array(buffer);
  2734. view[0] = this.onlySomeReasons;
  2735. outputArray.push(new asn1js__namespace.Primitive({
  2736. idBlock: {
  2737. tagClass: 3,
  2738. tagNumber: 3
  2739. },
  2740. valueHex: buffer
  2741. }));
  2742. }
  2743. if (this.indirectCRL !== IssuingDistributionPoint.defaultValues(INDIRECT_CRL)) {
  2744. outputArray.push(new asn1js__namespace.Primitive({
  2745. idBlock: {
  2746. tagClass: 3,
  2747. tagNumber: 4
  2748. },
  2749. valueHex: (new Uint8Array([0xFF])).buffer
  2750. }));
  2751. }
  2752. if (this.onlyContainsAttributeCerts !== IssuingDistributionPoint.defaultValues(ONLY_CONTAINS_ATTRIBUTE_CERTS)) {
  2753. outputArray.push(new asn1js__namespace.Primitive({
  2754. idBlock: {
  2755. tagClass: 3,
  2756. tagNumber: 5
  2757. },
  2758. valueHex: (new Uint8Array([0xFF])).buffer
  2759. }));
  2760. }
  2761. return (new asn1js__namespace.Sequence({
  2762. value: outputArray
  2763. }));
  2764. }
  2765. toJSON() {
  2766. const obj = {};
  2767. if (this.distributionPoint) {
  2768. if (this.distributionPoint instanceof Array) {
  2769. obj.distributionPoint = Array.from(this.distributionPoint, o => o.toJSON());
  2770. }
  2771. else {
  2772. obj.distributionPoint = this.distributionPoint.toJSON();
  2773. }
  2774. }
  2775. if (this.onlyContainsUserCerts !== IssuingDistributionPoint.defaultValues(ONLY_CONTAINS_USER_CERTS)) {
  2776. obj.onlyContainsUserCerts = this.onlyContainsUserCerts;
  2777. }
  2778. if (this.onlyContainsCACerts !== IssuingDistributionPoint.defaultValues(ONLY_CONTAINS_CA_CERTS)) {
  2779. obj.onlyContainsCACerts = this.onlyContainsCACerts;
  2780. }
  2781. if (ONLY_SOME_REASON in this) {
  2782. obj.onlySomeReasons = this.onlySomeReasons;
  2783. }
  2784. if (this.indirectCRL !== IssuingDistributionPoint.defaultValues(INDIRECT_CRL)) {
  2785. obj.indirectCRL = this.indirectCRL;
  2786. }
  2787. if (this.onlyContainsAttributeCerts !== IssuingDistributionPoint.defaultValues(ONLY_CONTAINS_ATTRIBUTE_CERTS)) {
  2788. obj.onlyContainsAttributeCerts = this.onlyContainsAttributeCerts;
  2789. }
  2790. return obj;
  2791. }
  2792. }
  2793. IssuingDistributionPoint.CLASS_NAME = "IssuingDistributionPoint";
  2794. const BASE = "base";
  2795. const MINIMUM = "minimum";
  2796. const MAXIMUM = "maximum";
  2797. const CLEAR_PROPS$1h = [
  2798. BASE,
  2799. MINIMUM,
  2800. MAXIMUM
  2801. ];
  2802. class GeneralSubtree extends PkiObject {
  2803. constructor(parameters = {}) {
  2804. super();
  2805. this.base = pvutils__namespace.getParametersValue(parameters, BASE, GeneralSubtree.defaultValues(BASE));
  2806. this.minimum = pvutils__namespace.getParametersValue(parameters, MINIMUM, GeneralSubtree.defaultValues(MINIMUM));
  2807. if (MAXIMUM in parameters) {
  2808. this.maximum = pvutils__namespace.getParametersValue(parameters, MAXIMUM, GeneralSubtree.defaultValues(MAXIMUM));
  2809. }
  2810. if (parameters.schema) {
  2811. this.fromSchema(parameters.schema);
  2812. }
  2813. }
  2814. static defaultValues(memberName) {
  2815. switch (memberName) {
  2816. case BASE:
  2817. return new GeneralName();
  2818. case MINIMUM:
  2819. return 0;
  2820. case MAXIMUM:
  2821. return 0;
  2822. default:
  2823. return super.defaultValues(memberName);
  2824. }
  2825. }
  2826. static schema(parameters = {}) {
  2827. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  2828. return (new asn1js__namespace.Sequence({
  2829. name: (names.blockName || EMPTY_STRING),
  2830. value: [
  2831. GeneralName.schema(names.base || {}),
  2832. new asn1js__namespace.Constructed({
  2833. optional: true,
  2834. idBlock: {
  2835. tagClass: 3,
  2836. tagNumber: 0
  2837. },
  2838. value: [new asn1js__namespace.Integer({ name: (names.minimum || EMPTY_STRING) })]
  2839. }),
  2840. new asn1js__namespace.Constructed({
  2841. optional: true,
  2842. idBlock: {
  2843. tagClass: 3,
  2844. tagNumber: 1
  2845. },
  2846. value: [new asn1js__namespace.Integer({ name: (names.maximum || EMPTY_STRING) })]
  2847. })
  2848. ]
  2849. }));
  2850. }
  2851. fromSchema(schema) {
  2852. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1h);
  2853. const asn1 = asn1js__namespace.compareSchema(schema, schema, GeneralSubtree.schema({
  2854. names: {
  2855. base: {
  2856. names: {
  2857. blockName: BASE
  2858. }
  2859. },
  2860. minimum: MINIMUM,
  2861. maximum: MAXIMUM
  2862. }
  2863. }));
  2864. AsnError.assertSchema(asn1, this.className);
  2865. this.base = new GeneralName({ schema: asn1.result.base });
  2866. if (MINIMUM in asn1.result) {
  2867. if (asn1.result.minimum.valueBlock.isHexOnly)
  2868. this.minimum = asn1.result.minimum;
  2869. else
  2870. this.minimum = asn1.result.minimum.valueBlock.valueDec;
  2871. }
  2872. if (MAXIMUM in asn1.result) {
  2873. if (asn1.result.maximum.valueBlock.isHexOnly)
  2874. this.maximum = asn1.result.maximum;
  2875. else
  2876. this.maximum = asn1.result.maximum.valueBlock.valueDec;
  2877. }
  2878. }
  2879. toSchema() {
  2880. const outputArray = [];
  2881. outputArray.push(this.base.toSchema());
  2882. if (this.minimum !== 0) {
  2883. let valueMinimum = 0;
  2884. if (this.minimum instanceof asn1js__namespace.Integer) {
  2885. valueMinimum = this.minimum;
  2886. }
  2887. else {
  2888. valueMinimum = new asn1js__namespace.Integer({ value: this.minimum });
  2889. }
  2890. outputArray.push(new asn1js__namespace.Constructed({
  2891. optional: true,
  2892. idBlock: {
  2893. tagClass: 3,
  2894. tagNumber: 0
  2895. },
  2896. value: [valueMinimum]
  2897. }));
  2898. }
  2899. if (MAXIMUM in this) {
  2900. let valueMaximum = 0;
  2901. if (this.maximum instanceof asn1js__namespace.Integer) {
  2902. valueMaximum = this.maximum;
  2903. }
  2904. else {
  2905. valueMaximum = new asn1js__namespace.Integer({ value: this.maximum });
  2906. }
  2907. outputArray.push(new asn1js__namespace.Constructed({
  2908. optional: true,
  2909. idBlock: {
  2910. tagClass: 3,
  2911. tagNumber: 1
  2912. },
  2913. value: [valueMaximum]
  2914. }));
  2915. }
  2916. return (new asn1js__namespace.Sequence({
  2917. value: outputArray
  2918. }));
  2919. }
  2920. toJSON() {
  2921. const res = {
  2922. base: this.base.toJSON()
  2923. };
  2924. if (this.minimum !== 0) {
  2925. if (typeof this.minimum === "number") {
  2926. res.minimum = this.minimum;
  2927. }
  2928. else {
  2929. res.minimum = this.minimum.toJSON();
  2930. }
  2931. }
  2932. if (this.maximum !== undefined) {
  2933. if (typeof this.maximum === "number") {
  2934. res.maximum = this.maximum;
  2935. }
  2936. else {
  2937. res.maximum = this.maximum.toJSON();
  2938. }
  2939. }
  2940. return res;
  2941. }
  2942. }
  2943. GeneralSubtree.CLASS_NAME = "GeneralSubtree";
  2944. const PERMITTED_SUBTREES = "permittedSubtrees";
  2945. const EXCLUDED_SUBTREES = "excludedSubtrees";
  2946. const CLEAR_PROPS$1g = [
  2947. PERMITTED_SUBTREES,
  2948. EXCLUDED_SUBTREES
  2949. ];
  2950. class NameConstraints extends PkiObject {
  2951. constructor(parameters = {}) {
  2952. super();
  2953. if (PERMITTED_SUBTREES in parameters) {
  2954. this.permittedSubtrees = pvutils__namespace.getParametersValue(parameters, PERMITTED_SUBTREES, NameConstraints.defaultValues(PERMITTED_SUBTREES));
  2955. }
  2956. if (EXCLUDED_SUBTREES in parameters) {
  2957. this.excludedSubtrees = pvutils__namespace.getParametersValue(parameters, EXCLUDED_SUBTREES, NameConstraints.defaultValues(EXCLUDED_SUBTREES));
  2958. }
  2959. if (parameters.schema) {
  2960. this.fromSchema(parameters.schema);
  2961. }
  2962. }
  2963. static defaultValues(memberName) {
  2964. switch (memberName) {
  2965. case PERMITTED_SUBTREES:
  2966. case EXCLUDED_SUBTREES:
  2967. return [];
  2968. default:
  2969. return super.defaultValues(memberName);
  2970. }
  2971. }
  2972. static schema(parameters = {}) {
  2973. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  2974. return (new asn1js__namespace.Sequence({
  2975. name: (names.blockName || EMPTY_STRING),
  2976. value: [
  2977. new asn1js__namespace.Constructed({
  2978. optional: true,
  2979. idBlock: {
  2980. tagClass: 3,
  2981. tagNumber: 0
  2982. },
  2983. value: [
  2984. new asn1js__namespace.Repeated({
  2985. name: (names.permittedSubtrees || EMPTY_STRING),
  2986. value: GeneralSubtree.schema()
  2987. })
  2988. ]
  2989. }),
  2990. new asn1js__namespace.Constructed({
  2991. optional: true,
  2992. idBlock: {
  2993. tagClass: 3,
  2994. tagNumber: 1
  2995. },
  2996. value: [
  2997. new asn1js__namespace.Repeated({
  2998. name: (names.excludedSubtrees || EMPTY_STRING),
  2999. value: GeneralSubtree.schema()
  3000. })
  3001. ]
  3002. })
  3003. ]
  3004. }));
  3005. }
  3006. fromSchema(schema) {
  3007. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1g);
  3008. const asn1 = asn1js__namespace.compareSchema(schema, schema, NameConstraints.schema({
  3009. names: {
  3010. permittedSubtrees: PERMITTED_SUBTREES,
  3011. excludedSubtrees: EXCLUDED_SUBTREES
  3012. }
  3013. }));
  3014. AsnError.assertSchema(asn1, this.className);
  3015. if (PERMITTED_SUBTREES in asn1.result)
  3016. this.permittedSubtrees = Array.from(asn1.result.permittedSubtrees, element => new GeneralSubtree({ schema: element }));
  3017. if (EXCLUDED_SUBTREES in asn1.result)
  3018. this.excludedSubtrees = Array.from(asn1.result.excludedSubtrees, element => new GeneralSubtree({ schema: element }));
  3019. }
  3020. toSchema() {
  3021. const outputArray = [];
  3022. if (this.permittedSubtrees) {
  3023. outputArray.push(new asn1js__namespace.Constructed({
  3024. idBlock: {
  3025. tagClass: 3,
  3026. tagNumber: 0
  3027. },
  3028. value: Array.from(this.permittedSubtrees, o => o.toSchema())
  3029. }));
  3030. }
  3031. if (this.excludedSubtrees) {
  3032. outputArray.push(new asn1js__namespace.Constructed({
  3033. idBlock: {
  3034. tagClass: 3,
  3035. tagNumber: 1
  3036. },
  3037. value: Array.from(this.excludedSubtrees, o => o.toSchema())
  3038. }));
  3039. }
  3040. return (new asn1js__namespace.Sequence({
  3041. value: outputArray
  3042. }));
  3043. }
  3044. toJSON() {
  3045. const object = {};
  3046. if (this.permittedSubtrees) {
  3047. object.permittedSubtrees = Array.from(this.permittedSubtrees, o => o.toJSON());
  3048. }
  3049. if (this.excludedSubtrees) {
  3050. object.excludedSubtrees = Array.from(this.excludedSubtrees, o => o.toJSON());
  3051. }
  3052. return object;
  3053. }
  3054. }
  3055. NameConstraints.CLASS_NAME = "NameConstraints";
  3056. const REQUIRE_EXPLICIT_POLICY = "requireExplicitPolicy";
  3057. const INHIBIT_POLICY_MAPPING = "inhibitPolicyMapping";
  3058. const CLEAR_PROPS$1f = [
  3059. REQUIRE_EXPLICIT_POLICY,
  3060. INHIBIT_POLICY_MAPPING,
  3061. ];
  3062. class PolicyConstraints extends PkiObject {
  3063. constructor(parameters = {}) {
  3064. super();
  3065. if (REQUIRE_EXPLICIT_POLICY in parameters) {
  3066. this.requireExplicitPolicy = pvutils__namespace.getParametersValue(parameters, REQUIRE_EXPLICIT_POLICY, PolicyConstraints.defaultValues(REQUIRE_EXPLICIT_POLICY));
  3067. }
  3068. if (INHIBIT_POLICY_MAPPING in parameters) {
  3069. this.inhibitPolicyMapping = pvutils__namespace.getParametersValue(parameters, INHIBIT_POLICY_MAPPING, PolicyConstraints.defaultValues(INHIBIT_POLICY_MAPPING));
  3070. }
  3071. if (parameters.schema) {
  3072. this.fromSchema(parameters.schema);
  3073. }
  3074. }
  3075. static defaultValues(memberName) {
  3076. switch (memberName) {
  3077. case REQUIRE_EXPLICIT_POLICY:
  3078. return 0;
  3079. case INHIBIT_POLICY_MAPPING:
  3080. return 0;
  3081. default:
  3082. return super.defaultValues(memberName);
  3083. }
  3084. }
  3085. static schema(parameters = {}) {
  3086. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  3087. return (new asn1js__namespace.Sequence({
  3088. name: (names.blockName || EMPTY_STRING),
  3089. value: [
  3090. new asn1js__namespace.Primitive({
  3091. name: (names.requireExplicitPolicy || EMPTY_STRING),
  3092. optional: true,
  3093. idBlock: {
  3094. tagClass: 3,
  3095. tagNumber: 0
  3096. }
  3097. }),
  3098. new asn1js__namespace.Primitive({
  3099. name: (names.inhibitPolicyMapping || EMPTY_STRING),
  3100. optional: true,
  3101. idBlock: {
  3102. tagClass: 3,
  3103. tagNumber: 1
  3104. }
  3105. })
  3106. ]
  3107. }));
  3108. }
  3109. fromSchema(schema) {
  3110. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1f);
  3111. const asn1 = asn1js__namespace.compareSchema(schema, schema, PolicyConstraints.schema({
  3112. names: {
  3113. requireExplicitPolicy: REQUIRE_EXPLICIT_POLICY,
  3114. inhibitPolicyMapping: INHIBIT_POLICY_MAPPING
  3115. }
  3116. }));
  3117. AsnError.assertSchema(asn1, this.className);
  3118. if (REQUIRE_EXPLICIT_POLICY in asn1.result) {
  3119. const field1 = asn1.result.requireExplicitPolicy;
  3120. field1.idBlock.tagClass = 1;
  3121. field1.idBlock.tagNumber = 2;
  3122. const ber1 = field1.toBER(false);
  3123. const int1 = asn1js__namespace.fromBER(ber1);
  3124. AsnError.assert(int1, "Integer");
  3125. this.requireExplicitPolicy = int1.result.valueBlock.valueDec;
  3126. }
  3127. if (INHIBIT_POLICY_MAPPING in asn1.result) {
  3128. const field2 = asn1.result.inhibitPolicyMapping;
  3129. field2.idBlock.tagClass = 1;
  3130. field2.idBlock.tagNumber = 2;
  3131. const ber2 = field2.toBER(false);
  3132. const int2 = asn1js__namespace.fromBER(ber2);
  3133. AsnError.assert(int2, "Integer");
  3134. this.inhibitPolicyMapping = int2.result.valueBlock.valueDec;
  3135. }
  3136. }
  3137. toSchema() {
  3138. const outputArray = [];
  3139. if (REQUIRE_EXPLICIT_POLICY in this) {
  3140. const int1 = new asn1js__namespace.Integer({ value: this.requireExplicitPolicy });
  3141. int1.idBlock.tagClass = 3;
  3142. int1.idBlock.tagNumber = 0;
  3143. outputArray.push(int1);
  3144. }
  3145. if (INHIBIT_POLICY_MAPPING in this) {
  3146. const int2 = new asn1js__namespace.Integer({ value: this.inhibitPolicyMapping });
  3147. int2.idBlock.tagClass = 3;
  3148. int2.idBlock.tagNumber = 1;
  3149. outputArray.push(int2);
  3150. }
  3151. return (new asn1js__namespace.Sequence({
  3152. value: outputArray
  3153. }));
  3154. }
  3155. toJSON() {
  3156. const res = {};
  3157. if (REQUIRE_EXPLICIT_POLICY in this) {
  3158. res.requireExplicitPolicy = this.requireExplicitPolicy;
  3159. }
  3160. if (INHIBIT_POLICY_MAPPING in this) {
  3161. res.inhibitPolicyMapping = this.inhibitPolicyMapping;
  3162. }
  3163. return res;
  3164. }
  3165. }
  3166. PolicyConstraints.CLASS_NAME = "PolicyConstraints";
  3167. const ISSUER_DOMAIN_POLICY = "issuerDomainPolicy";
  3168. const SUBJECT_DOMAIN_POLICY = "subjectDomainPolicy";
  3169. const CLEAR_PROPS$1e = [
  3170. ISSUER_DOMAIN_POLICY,
  3171. SUBJECT_DOMAIN_POLICY
  3172. ];
  3173. class PolicyMapping extends PkiObject {
  3174. constructor(parameters = {}) {
  3175. super();
  3176. this.issuerDomainPolicy = pvutils__namespace.getParametersValue(parameters, ISSUER_DOMAIN_POLICY, PolicyMapping.defaultValues(ISSUER_DOMAIN_POLICY));
  3177. this.subjectDomainPolicy = pvutils__namespace.getParametersValue(parameters, SUBJECT_DOMAIN_POLICY, PolicyMapping.defaultValues(SUBJECT_DOMAIN_POLICY));
  3178. if (parameters.schema) {
  3179. this.fromSchema(parameters.schema);
  3180. }
  3181. }
  3182. static defaultValues(memberName) {
  3183. switch (memberName) {
  3184. case ISSUER_DOMAIN_POLICY:
  3185. return EMPTY_STRING;
  3186. case SUBJECT_DOMAIN_POLICY:
  3187. return EMPTY_STRING;
  3188. default:
  3189. return super.defaultValues(memberName);
  3190. }
  3191. }
  3192. static schema(parameters = {}) {
  3193. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  3194. return (new asn1js__namespace.Sequence({
  3195. name: (names.blockName || EMPTY_STRING),
  3196. value: [
  3197. new asn1js__namespace.ObjectIdentifier({ name: (names.issuerDomainPolicy || EMPTY_STRING) }),
  3198. new asn1js__namespace.ObjectIdentifier({ name: (names.subjectDomainPolicy || EMPTY_STRING) })
  3199. ]
  3200. }));
  3201. }
  3202. fromSchema(schema) {
  3203. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1e);
  3204. const asn1 = asn1js__namespace.compareSchema(schema, schema, PolicyMapping.schema({
  3205. names: {
  3206. issuerDomainPolicy: ISSUER_DOMAIN_POLICY,
  3207. subjectDomainPolicy: SUBJECT_DOMAIN_POLICY
  3208. }
  3209. }));
  3210. AsnError.assertSchema(asn1, this.className);
  3211. this.issuerDomainPolicy = asn1.result.issuerDomainPolicy.valueBlock.toString();
  3212. this.subjectDomainPolicy = asn1.result.subjectDomainPolicy.valueBlock.toString();
  3213. }
  3214. toSchema() {
  3215. return (new asn1js__namespace.Sequence({
  3216. value: [
  3217. new asn1js__namespace.ObjectIdentifier({ value: this.issuerDomainPolicy }),
  3218. new asn1js__namespace.ObjectIdentifier({ value: this.subjectDomainPolicy })
  3219. ]
  3220. }));
  3221. }
  3222. toJSON() {
  3223. return {
  3224. issuerDomainPolicy: this.issuerDomainPolicy,
  3225. subjectDomainPolicy: this.subjectDomainPolicy
  3226. };
  3227. }
  3228. }
  3229. PolicyMapping.CLASS_NAME = "PolicyMapping";
  3230. const MAPPINGS = "mappings";
  3231. const CLEAR_PROPS$1d = [
  3232. MAPPINGS,
  3233. ];
  3234. class PolicyMappings extends PkiObject {
  3235. constructor(parameters = {}) {
  3236. super();
  3237. this.mappings = pvutils__namespace.getParametersValue(parameters, MAPPINGS, PolicyMappings.defaultValues(MAPPINGS));
  3238. if (parameters.schema) {
  3239. this.fromSchema(parameters.schema);
  3240. }
  3241. }
  3242. static defaultValues(memberName) {
  3243. switch (memberName) {
  3244. case MAPPINGS:
  3245. return [];
  3246. default:
  3247. return super.defaultValues(memberName);
  3248. }
  3249. }
  3250. static schema(parameters = {}) {
  3251. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  3252. return (new asn1js__namespace.Sequence({
  3253. name: (names.blockName || EMPTY_STRING),
  3254. value: [
  3255. new asn1js__namespace.Repeated({
  3256. name: (names.mappings || EMPTY_STRING),
  3257. value: PolicyMapping.schema()
  3258. })
  3259. ]
  3260. }));
  3261. }
  3262. fromSchema(schema) {
  3263. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1d);
  3264. const asn1 = asn1js__namespace.compareSchema(schema, schema, PolicyMappings.schema({
  3265. names: {
  3266. mappings: MAPPINGS
  3267. }
  3268. }));
  3269. AsnError.assertSchema(asn1, this.className);
  3270. this.mappings = Array.from(asn1.result.mappings, element => new PolicyMapping({ schema: element }));
  3271. }
  3272. toSchema() {
  3273. return (new asn1js__namespace.Sequence({
  3274. value: Array.from(this.mappings, o => o.toSchema())
  3275. }));
  3276. }
  3277. toJSON() {
  3278. return {
  3279. mappings: Array.from(this.mappings, o => o.toJSON())
  3280. };
  3281. }
  3282. }
  3283. PolicyMappings.CLASS_NAME = "PolicyMappings";
  3284. const NOT_BEFORE$1 = "notBefore";
  3285. const NOT_AFTER$1 = "notAfter";
  3286. const CLEAR_PROPS$1c = [
  3287. NOT_BEFORE$1,
  3288. NOT_AFTER$1
  3289. ];
  3290. class PrivateKeyUsagePeriod extends PkiObject {
  3291. constructor(parameters = {}) {
  3292. super();
  3293. if (NOT_BEFORE$1 in parameters) {
  3294. this.notBefore = pvutils__namespace.getParametersValue(parameters, NOT_BEFORE$1, PrivateKeyUsagePeriod.defaultValues(NOT_BEFORE$1));
  3295. }
  3296. if (NOT_AFTER$1 in parameters) {
  3297. this.notAfter = pvutils__namespace.getParametersValue(parameters, NOT_AFTER$1, PrivateKeyUsagePeriod.defaultValues(NOT_AFTER$1));
  3298. }
  3299. if (parameters.schema) {
  3300. this.fromSchema(parameters.schema);
  3301. }
  3302. }
  3303. static defaultValues(memberName) {
  3304. switch (memberName) {
  3305. case NOT_BEFORE$1:
  3306. return new Date();
  3307. case NOT_AFTER$1:
  3308. return new Date();
  3309. default:
  3310. return super.defaultValues(memberName);
  3311. }
  3312. }
  3313. static schema(parameters = {}) {
  3314. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  3315. return (new asn1js__namespace.Sequence({
  3316. name: (names.blockName || EMPTY_STRING),
  3317. value: [
  3318. new asn1js__namespace.Primitive({
  3319. name: (names.notBefore || EMPTY_STRING),
  3320. optional: true,
  3321. idBlock: {
  3322. tagClass: 3,
  3323. tagNumber: 0
  3324. }
  3325. }),
  3326. new asn1js__namespace.Primitive({
  3327. name: (names.notAfter || EMPTY_STRING),
  3328. optional: true,
  3329. idBlock: {
  3330. tagClass: 3,
  3331. tagNumber: 1
  3332. }
  3333. })
  3334. ]
  3335. }));
  3336. }
  3337. fromSchema(schema) {
  3338. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1c);
  3339. const asn1 = asn1js__namespace.compareSchema(schema, schema, PrivateKeyUsagePeriod.schema({
  3340. names: {
  3341. notBefore: NOT_BEFORE$1,
  3342. notAfter: NOT_AFTER$1
  3343. }
  3344. }));
  3345. AsnError.assertSchema(asn1, this.className);
  3346. if (NOT_BEFORE$1 in asn1.result) {
  3347. const localNotBefore = new asn1js__namespace.GeneralizedTime();
  3348. localNotBefore.fromBuffer(asn1.result.notBefore.valueBlock.valueHex);
  3349. this.notBefore = localNotBefore.toDate();
  3350. }
  3351. if (NOT_AFTER$1 in asn1.result) {
  3352. const localNotAfter = new asn1js__namespace.GeneralizedTime({ valueHex: asn1.result.notAfter.valueBlock.valueHex });
  3353. localNotAfter.fromBuffer(asn1.result.notAfter.valueBlock.valueHex);
  3354. this.notAfter = localNotAfter.toDate();
  3355. }
  3356. }
  3357. toSchema() {
  3358. const outputArray = [];
  3359. if (NOT_BEFORE$1 in this) {
  3360. outputArray.push(new asn1js__namespace.Primitive({
  3361. idBlock: {
  3362. tagClass: 3,
  3363. tagNumber: 0
  3364. },
  3365. valueHex: (new asn1js__namespace.GeneralizedTime({ valueDate: this.notBefore })).valueBlock.valueHexView
  3366. }));
  3367. }
  3368. if (NOT_AFTER$1 in this) {
  3369. outputArray.push(new asn1js__namespace.Primitive({
  3370. idBlock: {
  3371. tagClass: 3,
  3372. tagNumber: 1
  3373. },
  3374. valueHex: (new asn1js__namespace.GeneralizedTime({ valueDate: this.notAfter })).valueBlock.valueHexView
  3375. }));
  3376. }
  3377. return (new asn1js__namespace.Sequence({
  3378. value: outputArray
  3379. }));
  3380. }
  3381. toJSON() {
  3382. const res = {};
  3383. if (this.notBefore) {
  3384. res.notBefore = this.notBefore;
  3385. }
  3386. if (this.notAfter) {
  3387. res.notAfter = this.notAfter;
  3388. }
  3389. return res;
  3390. }
  3391. }
  3392. PrivateKeyUsagePeriod.CLASS_NAME = "PrivateKeyUsagePeriod";
  3393. const ID = "id";
  3394. const TYPE$2 = "type";
  3395. const VALUES = "values";
  3396. const QC_STATEMENT_CLEAR_PROPS = [
  3397. ID,
  3398. TYPE$2
  3399. ];
  3400. const QC_STATEMENTS_CLEAR_PROPS = [
  3401. VALUES
  3402. ];
  3403. class QCStatement extends PkiObject {
  3404. constructor(parameters = {}) {
  3405. super();
  3406. this.id = pvutils__namespace.getParametersValue(parameters, ID, QCStatement.defaultValues(ID));
  3407. if (TYPE$2 in parameters) {
  3408. this.type = pvutils__namespace.getParametersValue(parameters, TYPE$2, QCStatement.defaultValues(TYPE$2));
  3409. }
  3410. if (parameters.schema) {
  3411. this.fromSchema(parameters.schema);
  3412. }
  3413. }
  3414. static defaultValues(memberName) {
  3415. switch (memberName) {
  3416. case ID:
  3417. return EMPTY_STRING;
  3418. case TYPE$2:
  3419. return new asn1js__namespace.Null();
  3420. default:
  3421. return super.defaultValues(memberName);
  3422. }
  3423. }
  3424. static compareWithDefault(memberName, memberValue) {
  3425. switch (memberName) {
  3426. case ID:
  3427. return (memberValue === EMPTY_STRING);
  3428. case TYPE$2:
  3429. return (memberValue instanceof asn1js__namespace.Null);
  3430. default:
  3431. return super.defaultValues(memberName);
  3432. }
  3433. }
  3434. static schema(parameters = {}) {
  3435. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  3436. return (new asn1js__namespace.Sequence({
  3437. name: (names.blockName || EMPTY_STRING),
  3438. value: [
  3439. new asn1js__namespace.ObjectIdentifier({ name: (names.id || EMPTY_STRING) }),
  3440. new asn1js__namespace.Any({
  3441. name: (names.type || EMPTY_STRING),
  3442. optional: true
  3443. })
  3444. ]
  3445. }));
  3446. }
  3447. fromSchema(schema) {
  3448. pvutils__namespace.clearProps(schema, QC_STATEMENT_CLEAR_PROPS);
  3449. const asn1 = asn1js__namespace.compareSchema(schema, schema, QCStatement.schema({
  3450. names: {
  3451. id: ID,
  3452. type: TYPE$2
  3453. }
  3454. }));
  3455. AsnError.assertSchema(asn1, this.className);
  3456. this.id = asn1.result.id.valueBlock.toString();
  3457. if (TYPE$2 in asn1.result)
  3458. this.type = asn1.result.type;
  3459. }
  3460. toSchema() {
  3461. const value = [
  3462. new asn1js__namespace.ObjectIdentifier({ value: this.id })
  3463. ];
  3464. if (TYPE$2 in this)
  3465. value.push(this.type);
  3466. return (new asn1js__namespace.Sequence({
  3467. value,
  3468. }));
  3469. }
  3470. toJSON() {
  3471. const object = {
  3472. id: this.id
  3473. };
  3474. if (this.type) {
  3475. object.type = this.type.toJSON();
  3476. }
  3477. return object;
  3478. }
  3479. }
  3480. QCStatement.CLASS_NAME = "QCStatement";
  3481. class QCStatements extends PkiObject {
  3482. constructor(parameters = {}) {
  3483. super();
  3484. this.values = pvutils__namespace.getParametersValue(parameters, VALUES, QCStatements.defaultValues(VALUES));
  3485. if (parameters.schema) {
  3486. this.fromSchema(parameters.schema);
  3487. }
  3488. }
  3489. static defaultValues(memberName) {
  3490. switch (memberName) {
  3491. case VALUES:
  3492. return [];
  3493. default:
  3494. return super.defaultValues(memberName);
  3495. }
  3496. }
  3497. static compareWithDefault(memberName, memberValue) {
  3498. switch (memberName) {
  3499. case VALUES:
  3500. return (memberValue.length === 0);
  3501. default:
  3502. return super.defaultValues(memberName);
  3503. }
  3504. }
  3505. static schema(parameters = {}) {
  3506. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  3507. return (new asn1js__namespace.Sequence({
  3508. name: (names.blockName || EMPTY_STRING),
  3509. value: [
  3510. new asn1js__namespace.Repeated({
  3511. name: (names.values || EMPTY_STRING),
  3512. value: QCStatement.schema(names.value || {})
  3513. }),
  3514. ]
  3515. }));
  3516. }
  3517. fromSchema(schema) {
  3518. pvutils__namespace.clearProps(schema, QC_STATEMENTS_CLEAR_PROPS);
  3519. const asn1 = asn1js__namespace.compareSchema(schema, schema, QCStatements.schema({
  3520. names: {
  3521. values: VALUES
  3522. }
  3523. }));
  3524. AsnError.assertSchema(asn1, this.className);
  3525. this.values = Array.from(asn1.result.values, element => new QCStatement({ schema: element }));
  3526. }
  3527. toSchema() {
  3528. return (new asn1js__namespace.Sequence({
  3529. value: Array.from(this.values, o => o.toSchema())
  3530. }));
  3531. }
  3532. toJSON() {
  3533. return {
  3534. values: Array.from(this.values, o => o.toJSON())
  3535. };
  3536. }
  3537. }
  3538. QCStatements.CLASS_NAME = "QCStatements";
  3539. var _a;
  3540. class ECNamedCurves {
  3541. static register(name, id, size) {
  3542. this.namedCurves[name.toLowerCase()] = this.namedCurves[id] = { name, id, size };
  3543. }
  3544. static find(nameOrId) {
  3545. return this.namedCurves[nameOrId.toLowerCase()] || null;
  3546. }
  3547. }
  3548. _a = ECNamedCurves;
  3549. ECNamedCurves.namedCurves = {};
  3550. (() => {
  3551. _a.register("P-256", "1.2.840.10045.3.1.7", 32);
  3552. _a.register("P-384", "1.3.132.0.34", 48);
  3553. _a.register("P-521", "1.3.132.0.35", 66);
  3554. _a.register("brainpoolP256r1", "1.3.36.3.3.2.8.1.1.7", 32);
  3555. _a.register("brainpoolP384r1", "1.3.36.3.3.2.8.1.1.11", 48);
  3556. _a.register("brainpoolP512r1", "1.3.36.3.3.2.8.1.1.13", 64);
  3557. })();
  3558. const X = "x";
  3559. const Y = "y";
  3560. const NAMED_CURVE$1 = "namedCurve";
  3561. class ECPublicKey extends PkiObject {
  3562. constructor(parameters = {}) {
  3563. super();
  3564. this.x = pvutils__namespace.getParametersValue(parameters, X, ECPublicKey.defaultValues(X));
  3565. this.y = pvutils__namespace.getParametersValue(parameters, Y, ECPublicKey.defaultValues(Y));
  3566. this.namedCurve = pvutils__namespace.getParametersValue(parameters, NAMED_CURVE$1, ECPublicKey.defaultValues(NAMED_CURVE$1));
  3567. if (parameters.json) {
  3568. this.fromJSON(parameters.json);
  3569. }
  3570. if (parameters.schema) {
  3571. this.fromSchema(parameters.schema);
  3572. }
  3573. }
  3574. static defaultValues(memberName) {
  3575. switch (memberName) {
  3576. case X:
  3577. case Y:
  3578. return EMPTY_BUFFER;
  3579. case NAMED_CURVE$1:
  3580. return EMPTY_STRING;
  3581. default:
  3582. return super.defaultValues(memberName);
  3583. }
  3584. }
  3585. static compareWithDefault(memberName, memberValue) {
  3586. switch (memberName) {
  3587. case X:
  3588. case Y:
  3589. return memberValue instanceof ArrayBuffer &&
  3590. (pvutils__namespace.isEqualBuffer(memberValue, ECPublicKey.defaultValues(memberName)));
  3591. case NAMED_CURVE$1:
  3592. return typeof memberValue === "string" &&
  3593. memberValue === ECPublicKey.defaultValues(memberName);
  3594. default:
  3595. return super.defaultValues(memberName);
  3596. }
  3597. }
  3598. static schema() {
  3599. return new asn1js__namespace.RawData();
  3600. }
  3601. fromSchema(schema1) {
  3602. const view = pvtsutils.BufferSourceConverter.toUint8Array(schema1);
  3603. if (view[0] !== 0x04) {
  3604. throw new Error("Object's schema was not verified against input data for ECPublicKey");
  3605. }
  3606. const namedCurve = ECNamedCurves.find(this.namedCurve);
  3607. if (!namedCurve) {
  3608. throw new Error(`Incorrect curve OID: ${this.namedCurve}`);
  3609. }
  3610. const coordinateLength = namedCurve.size;
  3611. if (view.byteLength !== (coordinateLength * 2 + 1)) {
  3612. throw new Error("Object's schema was not verified against input data for ECPublicKey");
  3613. }
  3614. this.namedCurve = namedCurve.name;
  3615. this.x = view.slice(1, coordinateLength + 1).buffer;
  3616. this.y = view.slice(1 + coordinateLength, coordinateLength * 2 + 1).buffer;
  3617. }
  3618. toSchema() {
  3619. return new asn1js__namespace.RawData({
  3620. data: pvutils__namespace.utilConcatBuf((new Uint8Array([0x04])).buffer, this.x, this.y)
  3621. });
  3622. }
  3623. toJSON() {
  3624. const namedCurve = ECNamedCurves.find(this.namedCurve);
  3625. return {
  3626. crv: namedCurve ? namedCurve.name : this.namedCurve,
  3627. x: pvutils__namespace.toBase64(pvutils__namespace.arrayBufferToString(this.x), true, true, false),
  3628. y: pvutils__namespace.toBase64(pvutils__namespace.arrayBufferToString(this.y), true, true, false)
  3629. };
  3630. }
  3631. fromJSON(json) {
  3632. ParameterError.assert("json", json, "crv", "x", "y");
  3633. let coordinateLength = 0;
  3634. const namedCurve = ECNamedCurves.find(json.crv);
  3635. if (namedCurve) {
  3636. this.namedCurve = namedCurve.id;
  3637. coordinateLength = namedCurve.size;
  3638. }
  3639. const xConvertBuffer = pvutils__namespace.stringToArrayBuffer(pvutils__namespace.fromBase64(json.x, true));
  3640. if (xConvertBuffer.byteLength < coordinateLength) {
  3641. this.x = new ArrayBuffer(coordinateLength);
  3642. const view = new Uint8Array(this.x);
  3643. const convertBufferView = new Uint8Array(xConvertBuffer);
  3644. view.set(convertBufferView, 1);
  3645. }
  3646. else {
  3647. this.x = xConvertBuffer.slice(0, coordinateLength);
  3648. }
  3649. const yConvertBuffer = pvutils__namespace.stringToArrayBuffer(pvutils__namespace.fromBase64(json.y, true));
  3650. if (yConvertBuffer.byteLength < coordinateLength) {
  3651. this.y = new ArrayBuffer(coordinateLength);
  3652. const view = new Uint8Array(this.y);
  3653. const convertBufferView = new Uint8Array(yConvertBuffer);
  3654. view.set(convertBufferView, 1);
  3655. }
  3656. else {
  3657. this.y = yConvertBuffer.slice(0, coordinateLength);
  3658. }
  3659. }
  3660. }
  3661. ECPublicKey.CLASS_NAME = "ECPublicKey";
  3662. const MODULUS$1 = "modulus";
  3663. const PUBLIC_EXPONENT$1 = "publicExponent";
  3664. const CLEAR_PROPS$1b = [MODULUS$1, PUBLIC_EXPONENT$1];
  3665. class RSAPublicKey extends PkiObject {
  3666. constructor(parameters = {}) {
  3667. super();
  3668. this.modulus = pvutils__namespace.getParametersValue(parameters, MODULUS$1, RSAPublicKey.defaultValues(MODULUS$1));
  3669. this.publicExponent = pvutils__namespace.getParametersValue(parameters, PUBLIC_EXPONENT$1, RSAPublicKey.defaultValues(PUBLIC_EXPONENT$1));
  3670. if (parameters.json) {
  3671. this.fromJSON(parameters.json);
  3672. }
  3673. if (parameters.schema) {
  3674. this.fromSchema(parameters.schema);
  3675. }
  3676. }
  3677. static defaultValues(memberName) {
  3678. switch (memberName) {
  3679. case MODULUS$1:
  3680. return new asn1js__namespace.Integer();
  3681. case PUBLIC_EXPONENT$1:
  3682. return new asn1js__namespace.Integer();
  3683. default:
  3684. return super.defaultValues(memberName);
  3685. }
  3686. }
  3687. static schema(parameters = {}) {
  3688. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  3689. return (new asn1js__namespace.Sequence({
  3690. name: (names.blockName || EMPTY_STRING),
  3691. value: [
  3692. new asn1js__namespace.Integer({ name: (names.modulus || EMPTY_STRING) }),
  3693. new asn1js__namespace.Integer({ name: (names.publicExponent || EMPTY_STRING) })
  3694. ]
  3695. }));
  3696. }
  3697. fromSchema(schema) {
  3698. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1b);
  3699. const asn1 = asn1js__namespace.compareSchema(schema, schema, RSAPublicKey.schema({
  3700. names: {
  3701. modulus: MODULUS$1,
  3702. publicExponent: PUBLIC_EXPONENT$1
  3703. }
  3704. }));
  3705. AsnError.assertSchema(asn1, this.className);
  3706. this.modulus = asn1.result.modulus.convertFromDER(256);
  3707. this.publicExponent = asn1.result.publicExponent;
  3708. }
  3709. toSchema() {
  3710. return (new asn1js__namespace.Sequence({
  3711. value: [
  3712. this.modulus.convertToDER(),
  3713. this.publicExponent
  3714. ]
  3715. }));
  3716. }
  3717. toJSON() {
  3718. return {
  3719. n: pvtsutils__namespace.Convert.ToBase64Url(this.modulus.valueBlock.valueHexView),
  3720. e: pvtsutils__namespace.Convert.ToBase64Url(this.publicExponent.valueBlock.valueHexView),
  3721. };
  3722. }
  3723. fromJSON(json) {
  3724. ParameterError.assert("json", json, "n", "e");
  3725. const array = pvutils__namespace.stringToArrayBuffer(pvutils__namespace.fromBase64(json.n, true));
  3726. this.modulus = new asn1js__namespace.Integer({ valueHex: array.slice(0, Math.pow(2, pvutils__namespace.nearestPowerOf2(array.byteLength))) });
  3727. this.publicExponent = new asn1js__namespace.Integer({ valueHex: pvutils__namespace.stringToArrayBuffer(pvutils__namespace.fromBase64(json.e, true)).slice(0, 3) });
  3728. }
  3729. }
  3730. RSAPublicKey.CLASS_NAME = "RSAPublicKey";
  3731. const ALGORITHM$1 = "algorithm";
  3732. const SUBJECT_PUBLIC_KEY = "subjectPublicKey";
  3733. const CLEAR_PROPS$1a = [ALGORITHM$1, SUBJECT_PUBLIC_KEY];
  3734. class PublicKeyInfo extends PkiObject {
  3735. get parsedKey() {
  3736. if (this._parsedKey === undefined) {
  3737. switch (this.algorithm.algorithmId) {
  3738. case "1.2.840.10045.2.1":
  3739. if ("algorithmParams" in this.algorithm) {
  3740. if (this.algorithm.algorithmParams.constructor.blockName() === asn1js__namespace.ObjectIdentifier.blockName()) {
  3741. try {
  3742. this._parsedKey = new ECPublicKey({
  3743. namedCurve: this.algorithm.algorithmParams.valueBlock.toString(),
  3744. schema: this.subjectPublicKey.valueBlock.valueHexView
  3745. });
  3746. }
  3747. catch {
  3748. }
  3749. }
  3750. }
  3751. break;
  3752. case "1.2.840.113549.1.1.1":
  3753. {
  3754. const publicKeyASN1 = asn1js__namespace.fromBER(this.subjectPublicKey.valueBlock.valueHexView);
  3755. if (publicKeyASN1.offset !== -1) {
  3756. try {
  3757. this._parsedKey = new RSAPublicKey({ schema: publicKeyASN1.result });
  3758. }
  3759. catch {
  3760. }
  3761. }
  3762. }
  3763. break;
  3764. }
  3765. this._parsedKey || (this._parsedKey = null);
  3766. }
  3767. return this._parsedKey || undefined;
  3768. }
  3769. set parsedKey(value) {
  3770. this._parsedKey = value;
  3771. }
  3772. constructor(parameters = {}) {
  3773. super();
  3774. this.algorithm = pvutils__namespace.getParametersValue(parameters, ALGORITHM$1, PublicKeyInfo.defaultValues(ALGORITHM$1));
  3775. this.subjectPublicKey = pvutils__namespace.getParametersValue(parameters, SUBJECT_PUBLIC_KEY, PublicKeyInfo.defaultValues(SUBJECT_PUBLIC_KEY));
  3776. const parsedKey = pvutils__namespace.getParametersValue(parameters, "parsedKey", null);
  3777. if (parsedKey) {
  3778. this.parsedKey = parsedKey;
  3779. }
  3780. if (parameters.json) {
  3781. this.fromJSON(parameters.json);
  3782. }
  3783. if (parameters.schema) {
  3784. this.fromSchema(parameters.schema);
  3785. }
  3786. }
  3787. static defaultValues(memberName) {
  3788. switch (memberName) {
  3789. case ALGORITHM$1:
  3790. return new AlgorithmIdentifier();
  3791. case SUBJECT_PUBLIC_KEY:
  3792. return new asn1js__namespace.BitString();
  3793. default:
  3794. return super.defaultValues(memberName);
  3795. }
  3796. }
  3797. static schema(parameters = {}) {
  3798. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  3799. return (new asn1js__namespace.Sequence({
  3800. name: (names.blockName || EMPTY_STRING),
  3801. value: [
  3802. AlgorithmIdentifier.schema(names.algorithm || {}),
  3803. new asn1js__namespace.BitString({ name: (names.subjectPublicKey || EMPTY_STRING) })
  3804. ]
  3805. }));
  3806. }
  3807. fromSchema(schema) {
  3808. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1a);
  3809. const asn1 = asn1js__namespace.compareSchema(schema, schema, PublicKeyInfo.schema({
  3810. names: {
  3811. algorithm: {
  3812. names: {
  3813. blockName: ALGORITHM$1
  3814. }
  3815. },
  3816. subjectPublicKey: SUBJECT_PUBLIC_KEY
  3817. }
  3818. }));
  3819. AsnError.assertSchema(asn1, this.className);
  3820. this.algorithm = new AlgorithmIdentifier({ schema: asn1.result.algorithm });
  3821. this.subjectPublicKey = asn1.result.subjectPublicKey;
  3822. }
  3823. toSchema() {
  3824. return (new asn1js__namespace.Sequence({
  3825. value: [
  3826. this.algorithm.toSchema(),
  3827. this.subjectPublicKey
  3828. ]
  3829. }));
  3830. }
  3831. toJSON() {
  3832. if (!this.parsedKey) {
  3833. return {
  3834. algorithm: this.algorithm.toJSON(),
  3835. subjectPublicKey: this.subjectPublicKey.toJSON(),
  3836. };
  3837. }
  3838. const jwk = {};
  3839. switch (this.algorithm.algorithmId) {
  3840. case "1.2.840.10045.2.1":
  3841. jwk.kty = "EC";
  3842. break;
  3843. case "1.2.840.113549.1.1.1":
  3844. jwk.kty = "RSA";
  3845. break;
  3846. }
  3847. const publicKeyJWK = this.parsedKey.toJSON();
  3848. Object.assign(jwk, publicKeyJWK);
  3849. return jwk;
  3850. }
  3851. fromJSON(json) {
  3852. if ("kty" in json) {
  3853. switch (json.kty.toUpperCase()) {
  3854. case "EC":
  3855. this.parsedKey = new ECPublicKey({ json });
  3856. this.algorithm = new AlgorithmIdentifier({
  3857. algorithmId: "1.2.840.10045.2.1",
  3858. algorithmParams: new asn1js__namespace.ObjectIdentifier({ value: this.parsedKey.namedCurve })
  3859. });
  3860. break;
  3861. case "RSA":
  3862. this.parsedKey = new RSAPublicKey({ json });
  3863. this.algorithm = new AlgorithmIdentifier({
  3864. algorithmId: "1.2.840.113549.1.1.1",
  3865. algorithmParams: new asn1js__namespace.Null()
  3866. });
  3867. break;
  3868. default:
  3869. throw new Error(`Invalid value for "kty" parameter: ${json.kty}`);
  3870. }
  3871. this.subjectPublicKey = new asn1js__namespace.BitString({ valueHex: this.parsedKey.toSchema().toBER(false) });
  3872. }
  3873. }
  3874. async importKey(publicKey, crypto = getCrypto(true)) {
  3875. try {
  3876. if (!publicKey) {
  3877. throw new Error("Need to provide publicKey input parameter");
  3878. }
  3879. const exportedKey = await crypto.exportKey("spki", publicKey);
  3880. const asn1 = asn1js__namespace.fromBER(exportedKey);
  3881. try {
  3882. this.fromSchema(asn1.result);
  3883. }
  3884. catch {
  3885. throw new Error("Error during initializing object from schema");
  3886. }
  3887. }
  3888. catch (e) {
  3889. const message = e instanceof Error ? e.message : `${e}`;
  3890. throw new Error(`Error during exporting public key: ${message}`);
  3891. }
  3892. }
  3893. }
  3894. PublicKeyInfo.CLASS_NAME = "PublicKeyInfo";
  3895. const VERSION$l = "version";
  3896. const PRIVATE_KEY$1 = "privateKey";
  3897. const NAMED_CURVE = "namedCurve";
  3898. const PUBLIC_KEY$1 = "publicKey";
  3899. const CLEAR_PROPS$19 = [
  3900. VERSION$l,
  3901. PRIVATE_KEY$1,
  3902. NAMED_CURVE,
  3903. PUBLIC_KEY$1
  3904. ];
  3905. class ECPrivateKey extends PkiObject {
  3906. constructor(parameters = {}) {
  3907. super();
  3908. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$l, ECPrivateKey.defaultValues(VERSION$l));
  3909. this.privateKey = pvutils__namespace.getParametersValue(parameters, PRIVATE_KEY$1, ECPrivateKey.defaultValues(PRIVATE_KEY$1));
  3910. if (NAMED_CURVE in parameters) {
  3911. this.namedCurve = pvutils__namespace.getParametersValue(parameters, NAMED_CURVE, ECPrivateKey.defaultValues(NAMED_CURVE));
  3912. }
  3913. if (PUBLIC_KEY$1 in parameters) {
  3914. this.publicKey = pvutils__namespace.getParametersValue(parameters, PUBLIC_KEY$1, ECPrivateKey.defaultValues(PUBLIC_KEY$1));
  3915. }
  3916. if (parameters.json) {
  3917. this.fromJSON(parameters.json);
  3918. }
  3919. if (parameters.schema) {
  3920. this.fromSchema(parameters.schema);
  3921. }
  3922. }
  3923. static defaultValues(memberName) {
  3924. switch (memberName) {
  3925. case VERSION$l:
  3926. return 1;
  3927. case PRIVATE_KEY$1:
  3928. return new asn1js__namespace.OctetString();
  3929. case NAMED_CURVE:
  3930. return EMPTY_STRING;
  3931. case PUBLIC_KEY$1:
  3932. return new ECPublicKey();
  3933. default:
  3934. return super.defaultValues(memberName);
  3935. }
  3936. }
  3937. static compareWithDefault(memberName, memberValue) {
  3938. switch (memberName) {
  3939. case VERSION$l:
  3940. return (memberValue === ECPrivateKey.defaultValues(memberName));
  3941. case PRIVATE_KEY$1:
  3942. return (memberValue.isEqual(ECPrivateKey.defaultValues(memberName)));
  3943. case NAMED_CURVE:
  3944. return (memberValue === EMPTY_STRING);
  3945. case PUBLIC_KEY$1:
  3946. return ((ECPublicKey.compareWithDefault(NAMED_CURVE, memberValue.namedCurve)) &&
  3947. (ECPublicKey.compareWithDefault("x", memberValue.x)) &&
  3948. (ECPublicKey.compareWithDefault("y", memberValue.y)));
  3949. default:
  3950. return super.defaultValues(memberName);
  3951. }
  3952. }
  3953. static schema(parameters = {}) {
  3954. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  3955. return (new asn1js__namespace.Sequence({
  3956. name: (names.blockName || EMPTY_STRING),
  3957. value: [
  3958. new asn1js__namespace.Integer({ name: (names.version || EMPTY_STRING) }),
  3959. new asn1js__namespace.OctetString({ name: (names.privateKey || EMPTY_STRING) }),
  3960. new asn1js__namespace.Constructed({
  3961. optional: true,
  3962. idBlock: {
  3963. tagClass: 3,
  3964. tagNumber: 0
  3965. },
  3966. value: [
  3967. new asn1js__namespace.ObjectIdentifier({ name: (names.namedCurve || EMPTY_STRING) })
  3968. ]
  3969. }),
  3970. new asn1js__namespace.Constructed({
  3971. optional: true,
  3972. idBlock: {
  3973. tagClass: 3,
  3974. tagNumber: 1
  3975. },
  3976. value: [
  3977. new asn1js__namespace.BitString({ name: (names.publicKey || EMPTY_STRING) })
  3978. ]
  3979. })
  3980. ]
  3981. }));
  3982. }
  3983. fromSchema(schema) {
  3984. pvutils__namespace.clearProps(schema, CLEAR_PROPS$19);
  3985. const asn1 = asn1js__namespace.compareSchema(schema, schema, ECPrivateKey.schema({
  3986. names: {
  3987. version: VERSION$l,
  3988. privateKey: PRIVATE_KEY$1,
  3989. namedCurve: NAMED_CURVE,
  3990. publicKey: PUBLIC_KEY$1
  3991. }
  3992. }));
  3993. AsnError.assertSchema(asn1, this.className);
  3994. this.version = asn1.result.version.valueBlock.valueDec;
  3995. this.privateKey = asn1.result.privateKey;
  3996. if (NAMED_CURVE in asn1.result) {
  3997. this.namedCurve = asn1.result.namedCurve.valueBlock.toString();
  3998. }
  3999. if (PUBLIC_KEY$1 in asn1.result) {
  4000. const publicKeyData = { schema: asn1.result.publicKey.valueBlock.valueHex };
  4001. if (NAMED_CURVE in this) {
  4002. publicKeyData.namedCurve = this.namedCurve;
  4003. }
  4004. this.publicKey = new ECPublicKey(publicKeyData);
  4005. }
  4006. }
  4007. toSchema() {
  4008. const outputArray = [
  4009. new asn1js__namespace.Integer({ value: this.version }),
  4010. this.privateKey
  4011. ];
  4012. if (this.namedCurve) {
  4013. outputArray.push(new asn1js__namespace.Constructed({
  4014. idBlock: {
  4015. tagClass: 3,
  4016. tagNumber: 0
  4017. },
  4018. value: [
  4019. new asn1js__namespace.ObjectIdentifier({ value: this.namedCurve })
  4020. ]
  4021. }));
  4022. }
  4023. if (this.publicKey) {
  4024. outputArray.push(new asn1js__namespace.Constructed({
  4025. idBlock: {
  4026. tagClass: 3,
  4027. tagNumber: 1
  4028. },
  4029. value: [
  4030. new asn1js__namespace.BitString({ valueHex: this.publicKey.toSchema().toBER(false) })
  4031. ]
  4032. }));
  4033. }
  4034. return new asn1js__namespace.Sequence({
  4035. value: outputArray
  4036. });
  4037. }
  4038. toJSON() {
  4039. if (!this.namedCurve || ECPrivateKey.compareWithDefault(NAMED_CURVE, this.namedCurve)) {
  4040. throw new Error("Not enough information for making JSON: absent \"namedCurve\" value");
  4041. }
  4042. const curve = ECNamedCurves.find(this.namedCurve);
  4043. const privateKeyJSON = {
  4044. crv: curve ? curve.name : this.namedCurve,
  4045. d: pvtsutils__namespace.Convert.ToBase64Url(this.privateKey.valueBlock.valueHexView),
  4046. };
  4047. if (this.publicKey) {
  4048. const publicKeyJSON = this.publicKey.toJSON();
  4049. privateKeyJSON.x = publicKeyJSON.x;
  4050. privateKeyJSON.y = publicKeyJSON.y;
  4051. }
  4052. return privateKeyJSON;
  4053. }
  4054. fromJSON(json) {
  4055. ParameterError.assert("json", json, "crv", "d");
  4056. let coordinateLength = 0;
  4057. const curve = ECNamedCurves.find(json.crv);
  4058. if (curve) {
  4059. this.namedCurve = curve.id;
  4060. coordinateLength = curve.size;
  4061. }
  4062. const convertBuffer = pvtsutils__namespace.Convert.FromBase64Url(json.d);
  4063. if (convertBuffer.byteLength < coordinateLength) {
  4064. const buffer = new ArrayBuffer(coordinateLength);
  4065. const view = new Uint8Array(buffer);
  4066. const convertBufferView = new Uint8Array(convertBuffer);
  4067. view.set(convertBufferView, 1);
  4068. this.privateKey = new asn1js__namespace.OctetString({ valueHex: buffer });
  4069. }
  4070. else {
  4071. this.privateKey = new asn1js__namespace.OctetString({ valueHex: convertBuffer.slice(0, coordinateLength) });
  4072. }
  4073. if (json.x && json.y) {
  4074. this.publicKey = new ECPublicKey({ json });
  4075. }
  4076. }
  4077. }
  4078. ECPrivateKey.CLASS_NAME = "ECPrivateKey";
  4079. const PRIME = "prime";
  4080. const EXPONENT = "exponent";
  4081. const COEFFICIENT$1 = "coefficient";
  4082. const CLEAR_PROPS$18 = [
  4083. PRIME,
  4084. EXPONENT,
  4085. COEFFICIENT$1,
  4086. ];
  4087. class OtherPrimeInfo extends PkiObject {
  4088. constructor(parameters = {}) {
  4089. super();
  4090. this.prime = pvutils__namespace.getParametersValue(parameters, PRIME, OtherPrimeInfo.defaultValues(PRIME));
  4091. this.exponent = pvutils__namespace.getParametersValue(parameters, EXPONENT, OtherPrimeInfo.defaultValues(EXPONENT));
  4092. this.coefficient = pvutils__namespace.getParametersValue(parameters, COEFFICIENT$1, OtherPrimeInfo.defaultValues(COEFFICIENT$1));
  4093. if (parameters.json) {
  4094. this.fromJSON(parameters.json);
  4095. }
  4096. if (parameters.schema) {
  4097. this.fromSchema(parameters.schema);
  4098. }
  4099. }
  4100. static defaultValues(memberName) {
  4101. switch (memberName) {
  4102. case PRIME:
  4103. return new asn1js__namespace.Integer();
  4104. case EXPONENT:
  4105. return new asn1js__namespace.Integer();
  4106. case COEFFICIENT$1:
  4107. return new asn1js__namespace.Integer();
  4108. default:
  4109. return super.defaultValues(memberName);
  4110. }
  4111. }
  4112. static schema(parameters = {}) {
  4113. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  4114. return (new asn1js__namespace.Sequence({
  4115. name: (names.blockName || EMPTY_STRING),
  4116. value: [
  4117. new asn1js__namespace.Integer({ name: (names.prime || EMPTY_STRING) }),
  4118. new asn1js__namespace.Integer({ name: (names.exponent || EMPTY_STRING) }),
  4119. new asn1js__namespace.Integer({ name: (names.coefficient || EMPTY_STRING) })
  4120. ]
  4121. }));
  4122. }
  4123. fromSchema(schema) {
  4124. pvutils__namespace.clearProps(schema, CLEAR_PROPS$18);
  4125. const asn1 = asn1js__namespace.compareSchema(schema, schema, OtherPrimeInfo.schema({
  4126. names: {
  4127. prime: PRIME,
  4128. exponent: EXPONENT,
  4129. coefficient: COEFFICIENT$1
  4130. }
  4131. }));
  4132. AsnError.assertSchema(asn1, this.className);
  4133. this.prime = asn1.result.prime.convertFromDER();
  4134. this.exponent = asn1.result.exponent.convertFromDER();
  4135. this.coefficient = asn1.result.coefficient.convertFromDER();
  4136. }
  4137. toSchema() {
  4138. return (new asn1js__namespace.Sequence({
  4139. value: [
  4140. this.prime.convertToDER(),
  4141. this.exponent.convertToDER(),
  4142. this.coefficient.convertToDER()
  4143. ]
  4144. }));
  4145. }
  4146. toJSON() {
  4147. return {
  4148. r: pvtsutils__namespace.Convert.ToBase64Url(this.prime.valueBlock.valueHexView),
  4149. d: pvtsutils__namespace.Convert.ToBase64Url(this.exponent.valueBlock.valueHexView),
  4150. t: pvtsutils__namespace.Convert.ToBase64Url(this.coefficient.valueBlock.valueHexView),
  4151. };
  4152. }
  4153. fromJSON(json) {
  4154. ParameterError.assert("json", json, "r", "d", "r");
  4155. this.prime = new asn1js__namespace.Integer({ valueHex: pvtsutils__namespace.Convert.FromBase64Url(json.r) });
  4156. this.exponent = new asn1js__namespace.Integer({ valueHex: pvtsutils__namespace.Convert.FromBase64Url(json.d) });
  4157. this.coefficient = new asn1js__namespace.Integer({ valueHex: pvtsutils__namespace.Convert.FromBase64Url(json.t) });
  4158. }
  4159. }
  4160. OtherPrimeInfo.CLASS_NAME = "OtherPrimeInfo";
  4161. const VERSION$k = "version";
  4162. const MODULUS = "modulus";
  4163. const PUBLIC_EXPONENT = "publicExponent";
  4164. const PRIVATE_EXPONENT = "privateExponent";
  4165. const PRIME1 = "prime1";
  4166. const PRIME2 = "prime2";
  4167. const EXPONENT1 = "exponent1";
  4168. const EXPONENT2 = "exponent2";
  4169. const COEFFICIENT = "coefficient";
  4170. const OTHER_PRIME_INFOS = "otherPrimeInfos";
  4171. const CLEAR_PROPS$17 = [
  4172. VERSION$k,
  4173. MODULUS,
  4174. PUBLIC_EXPONENT,
  4175. PRIVATE_EXPONENT,
  4176. PRIME1,
  4177. PRIME2,
  4178. EXPONENT1,
  4179. EXPONENT2,
  4180. COEFFICIENT,
  4181. OTHER_PRIME_INFOS
  4182. ];
  4183. class RSAPrivateKey extends PkiObject {
  4184. constructor(parameters = {}) {
  4185. super();
  4186. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$k, RSAPrivateKey.defaultValues(VERSION$k));
  4187. this.modulus = pvutils__namespace.getParametersValue(parameters, MODULUS, RSAPrivateKey.defaultValues(MODULUS));
  4188. this.publicExponent = pvutils__namespace.getParametersValue(parameters, PUBLIC_EXPONENT, RSAPrivateKey.defaultValues(PUBLIC_EXPONENT));
  4189. this.privateExponent = pvutils__namespace.getParametersValue(parameters, PRIVATE_EXPONENT, RSAPrivateKey.defaultValues(PRIVATE_EXPONENT));
  4190. this.prime1 = pvutils__namespace.getParametersValue(parameters, PRIME1, RSAPrivateKey.defaultValues(PRIME1));
  4191. this.prime2 = pvutils__namespace.getParametersValue(parameters, PRIME2, RSAPrivateKey.defaultValues(PRIME2));
  4192. this.exponent1 = pvutils__namespace.getParametersValue(parameters, EXPONENT1, RSAPrivateKey.defaultValues(EXPONENT1));
  4193. this.exponent2 = pvutils__namespace.getParametersValue(parameters, EXPONENT2, RSAPrivateKey.defaultValues(EXPONENT2));
  4194. this.coefficient = pvutils__namespace.getParametersValue(parameters, COEFFICIENT, RSAPrivateKey.defaultValues(COEFFICIENT));
  4195. if (OTHER_PRIME_INFOS in parameters) {
  4196. this.otherPrimeInfos = pvutils__namespace.getParametersValue(parameters, OTHER_PRIME_INFOS, RSAPrivateKey.defaultValues(OTHER_PRIME_INFOS));
  4197. }
  4198. if (parameters.json) {
  4199. this.fromJSON(parameters.json);
  4200. }
  4201. if (parameters.schema) {
  4202. this.fromSchema(parameters.schema);
  4203. }
  4204. }
  4205. static defaultValues(memberName) {
  4206. switch (memberName) {
  4207. case VERSION$k:
  4208. return 0;
  4209. case MODULUS:
  4210. return new asn1js__namespace.Integer();
  4211. case PUBLIC_EXPONENT:
  4212. return new asn1js__namespace.Integer();
  4213. case PRIVATE_EXPONENT:
  4214. return new asn1js__namespace.Integer();
  4215. case PRIME1:
  4216. return new asn1js__namespace.Integer();
  4217. case PRIME2:
  4218. return new asn1js__namespace.Integer();
  4219. case EXPONENT1:
  4220. return new asn1js__namespace.Integer();
  4221. case EXPONENT2:
  4222. return new asn1js__namespace.Integer();
  4223. case COEFFICIENT:
  4224. return new asn1js__namespace.Integer();
  4225. case OTHER_PRIME_INFOS:
  4226. return [];
  4227. default:
  4228. return super.defaultValues(memberName);
  4229. }
  4230. }
  4231. static schema(parameters = {}) {
  4232. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  4233. return (new asn1js__namespace.Sequence({
  4234. name: (names.blockName || EMPTY_STRING),
  4235. value: [
  4236. new asn1js__namespace.Integer({ name: (names.version || EMPTY_STRING) }),
  4237. new asn1js__namespace.Integer({ name: (names.modulus || EMPTY_STRING) }),
  4238. new asn1js__namespace.Integer({ name: (names.publicExponent || EMPTY_STRING) }),
  4239. new asn1js__namespace.Integer({ name: (names.privateExponent || EMPTY_STRING) }),
  4240. new asn1js__namespace.Integer({ name: (names.prime1 || EMPTY_STRING) }),
  4241. new asn1js__namespace.Integer({ name: (names.prime2 || EMPTY_STRING) }),
  4242. new asn1js__namespace.Integer({ name: (names.exponent1 || EMPTY_STRING) }),
  4243. new asn1js__namespace.Integer({ name: (names.exponent2 || EMPTY_STRING) }),
  4244. new asn1js__namespace.Integer({ name: (names.coefficient || EMPTY_STRING) }),
  4245. new asn1js__namespace.Sequence({
  4246. optional: true,
  4247. value: [
  4248. new asn1js__namespace.Repeated({
  4249. name: (names.otherPrimeInfosName || EMPTY_STRING),
  4250. value: OtherPrimeInfo.schema(names.otherPrimeInfo || {})
  4251. })
  4252. ]
  4253. })
  4254. ]
  4255. }));
  4256. }
  4257. fromSchema(schema) {
  4258. pvutils__namespace.clearProps(schema, CLEAR_PROPS$17);
  4259. const asn1 = asn1js__namespace.compareSchema(schema, schema, RSAPrivateKey.schema({
  4260. names: {
  4261. version: VERSION$k,
  4262. modulus: MODULUS,
  4263. publicExponent: PUBLIC_EXPONENT,
  4264. privateExponent: PRIVATE_EXPONENT,
  4265. prime1: PRIME1,
  4266. prime2: PRIME2,
  4267. exponent1: EXPONENT1,
  4268. exponent2: EXPONENT2,
  4269. coefficient: COEFFICIENT,
  4270. otherPrimeInfo: {
  4271. names: {
  4272. blockName: OTHER_PRIME_INFOS
  4273. }
  4274. }
  4275. }
  4276. }));
  4277. AsnError.assertSchema(asn1, this.className);
  4278. this.version = asn1.result.version.valueBlock.valueDec;
  4279. this.modulus = asn1.result.modulus.convertFromDER(256);
  4280. this.publicExponent = asn1.result.publicExponent;
  4281. this.privateExponent = asn1.result.privateExponent.convertFromDER(256);
  4282. this.prime1 = asn1.result.prime1.convertFromDER(128);
  4283. this.prime2 = asn1.result.prime2.convertFromDER(128);
  4284. this.exponent1 = asn1.result.exponent1.convertFromDER(128);
  4285. this.exponent2 = asn1.result.exponent2.convertFromDER(128);
  4286. this.coefficient = asn1.result.coefficient.convertFromDER(128);
  4287. if (OTHER_PRIME_INFOS in asn1.result)
  4288. this.otherPrimeInfos = Array.from(asn1.result.otherPrimeInfos, element => new OtherPrimeInfo({ schema: element }));
  4289. }
  4290. toSchema() {
  4291. const outputArray = [];
  4292. outputArray.push(new asn1js__namespace.Integer({ value: this.version }));
  4293. outputArray.push(this.modulus.convertToDER());
  4294. outputArray.push(this.publicExponent);
  4295. outputArray.push(this.privateExponent.convertToDER());
  4296. outputArray.push(this.prime1.convertToDER());
  4297. outputArray.push(this.prime2.convertToDER());
  4298. outputArray.push(this.exponent1.convertToDER());
  4299. outputArray.push(this.exponent2.convertToDER());
  4300. outputArray.push(this.coefficient.convertToDER());
  4301. if (this.otherPrimeInfos) {
  4302. outputArray.push(new asn1js__namespace.Sequence({
  4303. value: Array.from(this.otherPrimeInfos, o => o.toSchema())
  4304. }));
  4305. }
  4306. return (new asn1js__namespace.Sequence({
  4307. value: outputArray
  4308. }));
  4309. }
  4310. toJSON() {
  4311. const jwk = {
  4312. n: pvtsutils__namespace.Convert.ToBase64Url(this.modulus.valueBlock.valueHexView),
  4313. e: pvtsutils__namespace.Convert.ToBase64Url(this.publicExponent.valueBlock.valueHexView),
  4314. d: pvtsutils__namespace.Convert.ToBase64Url(this.privateExponent.valueBlock.valueHexView),
  4315. p: pvtsutils__namespace.Convert.ToBase64Url(this.prime1.valueBlock.valueHexView),
  4316. q: pvtsutils__namespace.Convert.ToBase64Url(this.prime2.valueBlock.valueHexView),
  4317. dp: pvtsutils__namespace.Convert.ToBase64Url(this.exponent1.valueBlock.valueHexView),
  4318. dq: pvtsutils__namespace.Convert.ToBase64Url(this.exponent2.valueBlock.valueHexView),
  4319. qi: pvtsutils__namespace.Convert.ToBase64Url(this.coefficient.valueBlock.valueHexView),
  4320. };
  4321. if (this.otherPrimeInfos) {
  4322. jwk.oth = Array.from(this.otherPrimeInfos, o => o.toJSON());
  4323. }
  4324. return jwk;
  4325. }
  4326. fromJSON(json) {
  4327. ParameterError.assert("json", json, "n", "e", "d", "p", "q", "dp", "dq", "qi");
  4328. this.modulus = new asn1js__namespace.Integer({ valueHex: pvtsutils__namespace.Convert.FromBase64Url(json.n) });
  4329. this.publicExponent = new asn1js__namespace.Integer({ valueHex: pvtsutils__namespace.Convert.FromBase64Url(json.e) });
  4330. this.privateExponent = new asn1js__namespace.Integer({ valueHex: pvtsutils__namespace.Convert.FromBase64Url(json.d) });
  4331. this.prime1 = new asn1js__namespace.Integer({ valueHex: pvtsutils__namespace.Convert.FromBase64Url(json.p) });
  4332. this.prime2 = new asn1js__namespace.Integer({ valueHex: pvtsutils__namespace.Convert.FromBase64Url(json.q) });
  4333. this.exponent1 = new asn1js__namespace.Integer({ valueHex: pvtsutils__namespace.Convert.FromBase64Url(json.dp) });
  4334. this.exponent2 = new asn1js__namespace.Integer({ valueHex: pvtsutils__namespace.Convert.FromBase64Url(json.dq) });
  4335. this.coefficient = new asn1js__namespace.Integer({ valueHex: pvtsutils__namespace.Convert.FromBase64Url(json.qi) });
  4336. if (json.oth) {
  4337. this.otherPrimeInfos = Array.from(json.oth, (element) => new OtherPrimeInfo({ json: element }));
  4338. }
  4339. }
  4340. }
  4341. RSAPrivateKey.CLASS_NAME = "RSAPrivateKey";
  4342. const VERSION$j = "version";
  4343. const PRIVATE_KEY_ALGORITHM = "privateKeyAlgorithm";
  4344. const PRIVATE_KEY = "privateKey";
  4345. const ATTRIBUTES$5 = "attributes";
  4346. const PARSED_KEY = "parsedKey";
  4347. const CLEAR_PROPS$16 = [
  4348. VERSION$j,
  4349. PRIVATE_KEY_ALGORITHM,
  4350. PRIVATE_KEY,
  4351. ATTRIBUTES$5
  4352. ];
  4353. class PrivateKeyInfo extends PkiObject {
  4354. constructor(parameters = {}) {
  4355. super();
  4356. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$j, PrivateKeyInfo.defaultValues(VERSION$j));
  4357. this.privateKeyAlgorithm = pvutils__namespace.getParametersValue(parameters, PRIVATE_KEY_ALGORITHM, PrivateKeyInfo.defaultValues(PRIVATE_KEY_ALGORITHM));
  4358. this.privateKey = pvutils__namespace.getParametersValue(parameters, PRIVATE_KEY, PrivateKeyInfo.defaultValues(PRIVATE_KEY));
  4359. if (ATTRIBUTES$5 in parameters) {
  4360. this.attributes = pvutils__namespace.getParametersValue(parameters, ATTRIBUTES$5, PrivateKeyInfo.defaultValues(ATTRIBUTES$5));
  4361. }
  4362. if (PARSED_KEY in parameters) {
  4363. this.parsedKey = pvutils__namespace.getParametersValue(parameters, PARSED_KEY, PrivateKeyInfo.defaultValues(PARSED_KEY));
  4364. }
  4365. if (parameters.json) {
  4366. this.fromJSON(parameters.json);
  4367. }
  4368. if (parameters.schema) {
  4369. this.fromSchema(parameters.schema);
  4370. }
  4371. }
  4372. static defaultValues(memberName) {
  4373. switch (memberName) {
  4374. case VERSION$j:
  4375. return 0;
  4376. case PRIVATE_KEY_ALGORITHM:
  4377. return new AlgorithmIdentifier();
  4378. case PRIVATE_KEY:
  4379. return new asn1js__namespace.OctetString();
  4380. case ATTRIBUTES$5:
  4381. return [];
  4382. case PARSED_KEY:
  4383. return {};
  4384. default:
  4385. return super.defaultValues(memberName);
  4386. }
  4387. }
  4388. static schema(parameters = {}) {
  4389. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  4390. return (new asn1js__namespace.Sequence({
  4391. name: (names.blockName || EMPTY_STRING),
  4392. value: [
  4393. new asn1js__namespace.Integer({ name: (names.version || EMPTY_STRING) }),
  4394. AlgorithmIdentifier.schema(names.privateKeyAlgorithm || {}),
  4395. new asn1js__namespace.OctetString({ name: (names.privateKey || EMPTY_STRING) }),
  4396. new asn1js__namespace.Constructed({
  4397. optional: true,
  4398. idBlock: {
  4399. tagClass: 3,
  4400. tagNumber: 0
  4401. },
  4402. value: [
  4403. new asn1js__namespace.Repeated({
  4404. name: (names.attributes || EMPTY_STRING),
  4405. value: Attribute.schema()
  4406. })
  4407. ]
  4408. })
  4409. ]
  4410. }));
  4411. }
  4412. fromSchema(schema) {
  4413. pvutils__namespace.clearProps(schema, CLEAR_PROPS$16);
  4414. const asn1 = asn1js__namespace.compareSchema(schema, schema, PrivateKeyInfo.schema({
  4415. names: {
  4416. version: VERSION$j,
  4417. privateKeyAlgorithm: {
  4418. names: {
  4419. blockName: PRIVATE_KEY_ALGORITHM
  4420. }
  4421. },
  4422. privateKey: PRIVATE_KEY,
  4423. attributes: ATTRIBUTES$5
  4424. }
  4425. }));
  4426. AsnError.assertSchema(asn1, this.className);
  4427. this.version = asn1.result.version.valueBlock.valueDec;
  4428. this.privateKeyAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.privateKeyAlgorithm });
  4429. this.privateKey = asn1.result.privateKey;
  4430. if (ATTRIBUTES$5 in asn1.result)
  4431. this.attributes = Array.from(asn1.result.attributes, element => new Attribute({ schema: element }));
  4432. switch (this.privateKeyAlgorithm.algorithmId) {
  4433. case "1.2.840.113549.1.1.1":
  4434. {
  4435. const privateKeyASN1 = asn1js__namespace.fromBER(this.privateKey.valueBlock.valueHexView);
  4436. if (privateKeyASN1.offset !== -1)
  4437. this.parsedKey = new RSAPrivateKey({ schema: privateKeyASN1.result });
  4438. }
  4439. break;
  4440. case "1.2.840.10045.2.1":
  4441. if ("algorithmParams" in this.privateKeyAlgorithm) {
  4442. if (this.privateKeyAlgorithm.algorithmParams instanceof asn1js__namespace.ObjectIdentifier) {
  4443. const privateKeyASN1 = asn1js__namespace.fromBER(this.privateKey.valueBlock.valueHexView);
  4444. if (privateKeyASN1.offset !== -1) {
  4445. this.parsedKey = new ECPrivateKey({
  4446. namedCurve: this.privateKeyAlgorithm.algorithmParams.valueBlock.toString(),
  4447. schema: privateKeyASN1.result
  4448. });
  4449. }
  4450. }
  4451. }
  4452. break;
  4453. }
  4454. }
  4455. toSchema() {
  4456. const outputArray = [
  4457. new asn1js__namespace.Integer({ value: this.version }),
  4458. this.privateKeyAlgorithm.toSchema(),
  4459. this.privateKey
  4460. ];
  4461. if (this.attributes) {
  4462. outputArray.push(new asn1js__namespace.Constructed({
  4463. optional: true,
  4464. idBlock: {
  4465. tagClass: 3,
  4466. tagNumber: 0
  4467. },
  4468. value: Array.from(this.attributes, o => o.toSchema())
  4469. }));
  4470. }
  4471. return (new asn1js__namespace.Sequence({
  4472. value: outputArray
  4473. }));
  4474. }
  4475. toJSON() {
  4476. if (!this.parsedKey) {
  4477. const object = {
  4478. version: this.version,
  4479. privateKeyAlgorithm: this.privateKeyAlgorithm.toJSON(),
  4480. privateKey: this.privateKey.toJSON(),
  4481. };
  4482. if (this.attributes) {
  4483. object.attributes = Array.from(this.attributes, o => o.toJSON());
  4484. }
  4485. return object;
  4486. }
  4487. const jwk = {};
  4488. switch (this.privateKeyAlgorithm.algorithmId) {
  4489. case "1.2.840.10045.2.1":
  4490. jwk.kty = "EC";
  4491. break;
  4492. case "1.2.840.113549.1.1.1":
  4493. jwk.kty = "RSA";
  4494. break;
  4495. }
  4496. const publicKeyJWK = this.parsedKey.toJSON();
  4497. Object.assign(jwk, publicKeyJWK);
  4498. return jwk;
  4499. }
  4500. fromJSON(json) {
  4501. if ("kty" in json) {
  4502. switch (json.kty.toUpperCase()) {
  4503. case "EC":
  4504. this.parsedKey = new ECPrivateKey({ json });
  4505. this.privateKeyAlgorithm = new AlgorithmIdentifier({
  4506. algorithmId: "1.2.840.10045.2.1",
  4507. algorithmParams: new asn1js__namespace.ObjectIdentifier({ value: this.parsedKey.namedCurve })
  4508. });
  4509. break;
  4510. case "RSA":
  4511. this.parsedKey = new RSAPrivateKey({ json });
  4512. this.privateKeyAlgorithm = new AlgorithmIdentifier({
  4513. algorithmId: "1.2.840.113549.1.1.1",
  4514. algorithmParams: new asn1js__namespace.Null()
  4515. });
  4516. break;
  4517. default:
  4518. throw new Error(`Invalid value for "kty" parameter: ${json.kty}`);
  4519. }
  4520. this.privateKey = new asn1js__namespace.OctetString({ valueHex: this.parsedKey.toSchema().toBER(false) });
  4521. }
  4522. }
  4523. }
  4524. PrivateKeyInfo.CLASS_NAME = "PrivateKeyInfo";
  4525. const CONTENT_TYPE$1 = "contentType";
  4526. const CONTENT_ENCRYPTION_ALGORITHM = "contentEncryptionAlgorithm";
  4527. const ENCRYPTED_CONTENT = "encryptedContent";
  4528. const CLEAR_PROPS$15 = [
  4529. CONTENT_TYPE$1,
  4530. CONTENT_ENCRYPTION_ALGORITHM,
  4531. ENCRYPTED_CONTENT,
  4532. ];
  4533. const PIECE_SIZE = 1024;
  4534. class EncryptedContentInfo extends PkiObject {
  4535. constructor(parameters = {}) {
  4536. super();
  4537. this.contentType = pvutils__namespace.getParametersValue(parameters, CONTENT_TYPE$1, EncryptedContentInfo.defaultValues(CONTENT_TYPE$1));
  4538. this.contentEncryptionAlgorithm = pvutils__namespace.getParametersValue(parameters, CONTENT_ENCRYPTION_ALGORITHM, EncryptedContentInfo.defaultValues(CONTENT_ENCRYPTION_ALGORITHM));
  4539. if (ENCRYPTED_CONTENT in parameters && parameters.encryptedContent) {
  4540. this.encryptedContent = parameters.encryptedContent;
  4541. if ((this.encryptedContent.idBlock.tagClass === 1) &&
  4542. (this.encryptedContent.idBlock.tagNumber === 4)) {
  4543. if (this.encryptedContent.idBlock.isConstructed === false && !parameters.disableSplit) {
  4544. const constrString = new asn1js__namespace.OctetString({
  4545. idBlock: { isConstructed: true },
  4546. isConstructed: true
  4547. });
  4548. let offset = 0;
  4549. const valueHex = this.encryptedContent.valueBlock.valueHexView.slice().buffer;
  4550. let length = valueHex.byteLength;
  4551. while (length > 0) {
  4552. const pieceView = new Uint8Array(valueHex, offset, ((offset + PIECE_SIZE) > valueHex.byteLength) ? (valueHex.byteLength - offset) : PIECE_SIZE);
  4553. const _array = new ArrayBuffer(pieceView.length);
  4554. const _view = new Uint8Array(_array);
  4555. for (let i = 0; i < _view.length; i++)
  4556. _view[i] = pieceView[i];
  4557. constrString.valueBlock.value.push(new asn1js__namespace.OctetString({ valueHex: _array }));
  4558. length -= pieceView.length;
  4559. offset += pieceView.length;
  4560. }
  4561. this.encryptedContent = constrString;
  4562. }
  4563. }
  4564. }
  4565. if (parameters.schema) {
  4566. this.fromSchema(parameters.schema);
  4567. }
  4568. }
  4569. static defaultValues(memberName) {
  4570. switch (memberName) {
  4571. case CONTENT_TYPE$1:
  4572. return EMPTY_STRING;
  4573. case CONTENT_ENCRYPTION_ALGORITHM:
  4574. return new AlgorithmIdentifier();
  4575. case ENCRYPTED_CONTENT:
  4576. return new asn1js__namespace.OctetString();
  4577. default:
  4578. return super.defaultValues(memberName);
  4579. }
  4580. }
  4581. static compareWithDefault(memberName, memberValue) {
  4582. switch (memberName) {
  4583. case CONTENT_TYPE$1:
  4584. return (memberValue === EMPTY_STRING);
  4585. case CONTENT_ENCRYPTION_ALGORITHM:
  4586. return ((memberValue.algorithmId === EMPTY_STRING) && (("algorithmParams" in memberValue) === false));
  4587. case ENCRYPTED_CONTENT:
  4588. return (memberValue.isEqual(EncryptedContentInfo.defaultValues(ENCRYPTED_CONTENT)));
  4589. default:
  4590. return super.defaultValues(memberName);
  4591. }
  4592. }
  4593. static schema(parameters = {}) {
  4594. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  4595. return (new asn1js__namespace.Sequence({
  4596. name: (names.blockName || EMPTY_STRING),
  4597. value: [
  4598. new asn1js__namespace.ObjectIdentifier({ name: (names.contentType || EMPTY_STRING) }),
  4599. AlgorithmIdentifier.schema(names.contentEncryptionAlgorithm || {}),
  4600. new asn1js__namespace.Choice({
  4601. value: [
  4602. new asn1js__namespace.Constructed({
  4603. name: (names.encryptedContent || EMPTY_STRING),
  4604. idBlock: {
  4605. tagClass: 3,
  4606. tagNumber: 0
  4607. },
  4608. value: [
  4609. new asn1js__namespace.Repeated({
  4610. value: new asn1js__namespace.OctetString()
  4611. })
  4612. ]
  4613. }),
  4614. new asn1js__namespace.Primitive({
  4615. name: (names.encryptedContent || EMPTY_STRING),
  4616. idBlock: {
  4617. tagClass: 3,
  4618. tagNumber: 0
  4619. }
  4620. })
  4621. ]
  4622. })
  4623. ]
  4624. }));
  4625. }
  4626. fromSchema(schema) {
  4627. pvutils__namespace.clearProps(schema, CLEAR_PROPS$15);
  4628. const asn1 = asn1js__namespace.compareSchema(schema, schema, EncryptedContentInfo.schema({
  4629. names: {
  4630. contentType: CONTENT_TYPE$1,
  4631. contentEncryptionAlgorithm: {
  4632. names: {
  4633. blockName: CONTENT_ENCRYPTION_ALGORITHM
  4634. }
  4635. },
  4636. encryptedContent: ENCRYPTED_CONTENT
  4637. }
  4638. }));
  4639. AsnError.assertSchema(asn1, this.className);
  4640. this.contentType = asn1.result.contentType.valueBlock.toString();
  4641. this.contentEncryptionAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.contentEncryptionAlgorithm });
  4642. if (ENCRYPTED_CONTENT in asn1.result) {
  4643. this.encryptedContent = asn1.result.encryptedContent;
  4644. this.encryptedContent.idBlock.tagClass = 1;
  4645. this.encryptedContent.idBlock.tagNumber = 4;
  4646. }
  4647. }
  4648. toSchema() {
  4649. const sequenceLengthBlock = {
  4650. isIndefiniteForm: false
  4651. };
  4652. const outputArray = [];
  4653. outputArray.push(new asn1js__namespace.ObjectIdentifier({ value: this.contentType }));
  4654. outputArray.push(this.contentEncryptionAlgorithm.toSchema());
  4655. if (this.encryptedContent) {
  4656. sequenceLengthBlock.isIndefiniteForm = this.encryptedContent.idBlock.isConstructed;
  4657. const encryptedValue = this.encryptedContent;
  4658. encryptedValue.idBlock.tagClass = 3;
  4659. encryptedValue.idBlock.tagNumber = 0;
  4660. encryptedValue.lenBlock.isIndefiniteForm = this.encryptedContent.idBlock.isConstructed;
  4661. outputArray.push(encryptedValue);
  4662. }
  4663. return (new asn1js__namespace.Sequence({
  4664. lenBlock: sequenceLengthBlock,
  4665. value: outputArray
  4666. }));
  4667. }
  4668. toJSON() {
  4669. const res = {
  4670. contentType: this.contentType,
  4671. contentEncryptionAlgorithm: this.contentEncryptionAlgorithm.toJSON()
  4672. };
  4673. if (this.encryptedContent) {
  4674. res.encryptedContent = this.encryptedContent.toJSON();
  4675. }
  4676. return res;
  4677. }
  4678. getEncryptedContent() {
  4679. if (!this.encryptedContent) {
  4680. throw new Error("Parameter 'encryptedContent' is undefined");
  4681. }
  4682. return asn1js__namespace.OctetString.prototype.getValue.call(this.encryptedContent);
  4683. }
  4684. }
  4685. EncryptedContentInfo.CLASS_NAME = "EncryptedContentInfo";
  4686. const HASH_ALGORITHM$4 = "hashAlgorithm";
  4687. const MASK_GEN_ALGORITHM$1 = "maskGenAlgorithm";
  4688. const SALT_LENGTH = "saltLength";
  4689. const TRAILER_FIELD = "trailerField";
  4690. const CLEAR_PROPS$14 = [
  4691. HASH_ALGORITHM$4,
  4692. MASK_GEN_ALGORITHM$1,
  4693. SALT_LENGTH,
  4694. TRAILER_FIELD
  4695. ];
  4696. class RSASSAPSSParams extends PkiObject {
  4697. constructor(parameters = {}) {
  4698. super();
  4699. this.hashAlgorithm = pvutils__namespace.getParametersValue(parameters, HASH_ALGORITHM$4, RSASSAPSSParams.defaultValues(HASH_ALGORITHM$4));
  4700. this.maskGenAlgorithm = pvutils__namespace.getParametersValue(parameters, MASK_GEN_ALGORITHM$1, RSASSAPSSParams.defaultValues(MASK_GEN_ALGORITHM$1));
  4701. this.saltLength = pvutils__namespace.getParametersValue(parameters, SALT_LENGTH, RSASSAPSSParams.defaultValues(SALT_LENGTH));
  4702. this.trailerField = pvutils__namespace.getParametersValue(parameters, TRAILER_FIELD, RSASSAPSSParams.defaultValues(TRAILER_FIELD));
  4703. if (parameters.schema) {
  4704. this.fromSchema(parameters.schema);
  4705. }
  4706. }
  4707. static defaultValues(memberName) {
  4708. switch (memberName) {
  4709. case HASH_ALGORITHM$4:
  4710. return new AlgorithmIdentifier({
  4711. algorithmId: "1.3.14.3.2.26",
  4712. algorithmParams: new asn1js__namespace.Null()
  4713. });
  4714. case MASK_GEN_ALGORITHM$1:
  4715. return new AlgorithmIdentifier({
  4716. algorithmId: "1.2.840.113549.1.1.8",
  4717. algorithmParams: (new AlgorithmIdentifier({
  4718. algorithmId: "1.3.14.3.2.26",
  4719. algorithmParams: new asn1js__namespace.Null()
  4720. })).toSchema()
  4721. });
  4722. case SALT_LENGTH:
  4723. return 20;
  4724. case TRAILER_FIELD:
  4725. return 1;
  4726. default:
  4727. return super.defaultValues(memberName);
  4728. }
  4729. }
  4730. static schema(parameters = {}) {
  4731. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  4732. return (new asn1js__namespace.Sequence({
  4733. name: (names.blockName || EMPTY_STRING),
  4734. value: [
  4735. new asn1js__namespace.Constructed({
  4736. idBlock: {
  4737. tagClass: 3,
  4738. tagNumber: 0
  4739. },
  4740. optional: true,
  4741. value: [AlgorithmIdentifier.schema(names.hashAlgorithm || {})]
  4742. }),
  4743. new asn1js__namespace.Constructed({
  4744. idBlock: {
  4745. tagClass: 3,
  4746. tagNumber: 1
  4747. },
  4748. optional: true,
  4749. value: [AlgorithmIdentifier.schema(names.maskGenAlgorithm || {})]
  4750. }),
  4751. new asn1js__namespace.Constructed({
  4752. idBlock: {
  4753. tagClass: 3,
  4754. tagNumber: 2
  4755. },
  4756. optional: true,
  4757. value: [new asn1js__namespace.Integer({ name: (names.saltLength || EMPTY_STRING) })]
  4758. }),
  4759. new asn1js__namespace.Constructed({
  4760. idBlock: {
  4761. tagClass: 3,
  4762. tagNumber: 3
  4763. },
  4764. optional: true,
  4765. value: [new asn1js__namespace.Integer({ name: (names.trailerField || EMPTY_STRING) })]
  4766. })
  4767. ]
  4768. }));
  4769. }
  4770. fromSchema(schema) {
  4771. pvutils__namespace.clearProps(schema, CLEAR_PROPS$14);
  4772. const asn1 = asn1js__namespace.compareSchema(schema, schema, RSASSAPSSParams.schema({
  4773. names: {
  4774. hashAlgorithm: {
  4775. names: {
  4776. blockName: HASH_ALGORITHM$4
  4777. }
  4778. },
  4779. maskGenAlgorithm: {
  4780. names: {
  4781. blockName: MASK_GEN_ALGORITHM$1
  4782. }
  4783. },
  4784. saltLength: SALT_LENGTH,
  4785. trailerField: TRAILER_FIELD
  4786. }
  4787. }));
  4788. AsnError.assertSchema(asn1, this.className);
  4789. if (HASH_ALGORITHM$4 in asn1.result)
  4790. this.hashAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.hashAlgorithm });
  4791. if (MASK_GEN_ALGORITHM$1 in asn1.result)
  4792. this.maskGenAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.maskGenAlgorithm });
  4793. if (SALT_LENGTH in asn1.result)
  4794. this.saltLength = asn1.result.saltLength.valueBlock.valueDec;
  4795. if (TRAILER_FIELD in asn1.result)
  4796. this.trailerField = asn1.result.trailerField.valueBlock.valueDec;
  4797. }
  4798. toSchema() {
  4799. const outputArray = [];
  4800. if (!this.hashAlgorithm.isEqual(RSASSAPSSParams.defaultValues(HASH_ALGORITHM$4))) {
  4801. outputArray.push(new asn1js__namespace.Constructed({
  4802. idBlock: {
  4803. tagClass: 3,
  4804. tagNumber: 0
  4805. },
  4806. value: [this.hashAlgorithm.toSchema()]
  4807. }));
  4808. }
  4809. if (!this.maskGenAlgorithm.isEqual(RSASSAPSSParams.defaultValues(MASK_GEN_ALGORITHM$1))) {
  4810. outputArray.push(new asn1js__namespace.Constructed({
  4811. idBlock: {
  4812. tagClass: 3,
  4813. tagNumber: 1
  4814. },
  4815. value: [this.maskGenAlgorithm.toSchema()]
  4816. }));
  4817. }
  4818. if (this.saltLength !== RSASSAPSSParams.defaultValues(SALT_LENGTH)) {
  4819. outputArray.push(new asn1js__namespace.Constructed({
  4820. idBlock: {
  4821. tagClass: 3,
  4822. tagNumber: 2
  4823. },
  4824. value: [new asn1js__namespace.Integer({ value: this.saltLength })]
  4825. }));
  4826. }
  4827. if (this.trailerField !== RSASSAPSSParams.defaultValues(TRAILER_FIELD)) {
  4828. outputArray.push(new asn1js__namespace.Constructed({
  4829. idBlock: {
  4830. tagClass: 3,
  4831. tagNumber: 3
  4832. },
  4833. value: [new asn1js__namespace.Integer({ value: this.trailerField })]
  4834. }));
  4835. }
  4836. return (new asn1js__namespace.Sequence({
  4837. value: outputArray
  4838. }));
  4839. }
  4840. toJSON() {
  4841. const res = {};
  4842. if (!this.hashAlgorithm.isEqual(RSASSAPSSParams.defaultValues(HASH_ALGORITHM$4))) {
  4843. res.hashAlgorithm = this.hashAlgorithm.toJSON();
  4844. }
  4845. if (!this.maskGenAlgorithm.isEqual(RSASSAPSSParams.defaultValues(MASK_GEN_ALGORITHM$1))) {
  4846. res.maskGenAlgorithm = this.maskGenAlgorithm.toJSON();
  4847. }
  4848. if (this.saltLength !== RSASSAPSSParams.defaultValues(SALT_LENGTH)) {
  4849. res.saltLength = this.saltLength;
  4850. }
  4851. if (this.trailerField !== RSASSAPSSParams.defaultValues(TRAILER_FIELD)) {
  4852. res.trailerField = this.trailerField;
  4853. }
  4854. return res;
  4855. }
  4856. }
  4857. RSASSAPSSParams.CLASS_NAME = "RSASSAPSSParams";
  4858. const SALT = "salt";
  4859. const ITERATION_COUNT = "iterationCount";
  4860. const KEY_LENGTH = "keyLength";
  4861. const PRF = "prf";
  4862. const CLEAR_PROPS$13 = [
  4863. SALT,
  4864. ITERATION_COUNT,
  4865. KEY_LENGTH,
  4866. PRF
  4867. ];
  4868. class PBKDF2Params extends PkiObject {
  4869. constructor(parameters = {}) {
  4870. super();
  4871. this.salt = pvutils__namespace.getParametersValue(parameters, SALT, PBKDF2Params.defaultValues(SALT));
  4872. this.iterationCount = pvutils__namespace.getParametersValue(parameters, ITERATION_COUNT, PBKDF2Params.defaultValues(ITERATION_COUNT));
  4873. if (KEY_LENGTH in parameters) {
  4874. this.keyLength = pvutils__namespace.getParametersValue(parameters, KEY_LENGTH, PBKDF2Params.defaultValues(KEY_LENGTH));
  4875. }
  4876. if (PRF in parameters) {
  4877. this.prf = pvutils__namespace.getParametersValue(parameters, PRF, PBKDF2Params.defaultValues(PRF));
  4878. }
  4879. if (parameters.schema) {
  4880. this.fromSchema(parameters.schema);
  4881. }
  4882. }
  4883. static defaultValues(memberName) {
  4884. switch (memberName) {
  4885. case SALT:
  4886. return {};
  4887. case ITERATION_COUNT:
  4888. return (-1);
  4889. case KEY_LENGTH:
  4890. return 0;
  4891. case PRF:
  4892. return new AlgorithmIdentifier({
  4893. algorithmId: "1.3.14.3.2.26",
  4894. algorithmParams: new asn1js__namespace.Null()
  4895. });
  4896. default:
  4897. return super.defaultValues(memberName);
  4898. }
  4899. }
  4900. static schema(parameters = {}) {
  4901. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  4902. return (new asn1js__namespace.Sequence({
  4903. name: (names.blockName || EMPTY_STRING),
  4904. value: [
  4905. new asn1js__namespace.Choice({
  4906. value: [
  4907. new asn1js__namespace.OctetString({ name: (names.saltPrimitive || EMPTY_STRING) }),
  4908. AlgorithmIdentifier.schema(names.saltConstructed || {})
  4909. ]
  4910. }),
  4911. new asn1js__namespace.Integer({ name: (names.iterationCount || EMPTY_STRING) }),
  4912. new asn1js__namespace.Integer({
  4913. name: (names.keyLength || EMPTY_STRING),
  4914. optional: true
  4915. }),
  4916. AlgorithmIdentifier.schema(names.prf || {
  4917. names: {
  4918. optional: true
  4919. }
  4920. })
  4921. ]
  4922. }));
  4923. }
  4924. fromSchema(schema) {
  4925. pvutils__namespace.clearProps(schema, CLEAR_PROPS$13);
  4926. const asn1 = asn1js__namespace.compareSchema(schema, schema, PBKDF2Params.schema({
  4927. names: {
  4928. saltPrimitive: SALT,
  4929. saltConstructed: {
  4930. names: {
  4931. blockName: SALT
  4932. }
  4933. },
  4934. iterationCount: ITERATION_COUNT,
  4935. keyLength: KEY_LENGTH,
  4936. prf: {
  4937. names: {
  4938. blockName: PRF,
  4939. optional: true
  4940. }
  4941. }
  4942. }
  4943. }));
  4944. AsnError.assertSchema(asn1, this.className);
  4945. this.salt = asn1.result.salt;
  4946. this.iterationCount = asn1.result.iterationCount.valueBlock.valueDec;
  4947. if (KEY_LENGTH in asn1.result)
  4948. this.keyLength = asn1.result.keyLength.valueBlock.valueDec;
  4949. if (PRF in asn1.result)
  4950. this.prf = new AlgorithmIdentifier({ schema: asn1.result.prf });
  4951. }
  4952. toSchema() {
  4953. const outputArray = [];
  4954. outputArray.push(this.salt);
  4955. outputArray.push(new asn1js__namespace.Integer({ value: this.iterationCount }));
  4956. if (KEY_LENGTH in this) {
  4957. if (PBKDF2Params.defaultValues(KEY_LENGTH) !== this.keyLength)
  4958. outputArray.push(new asn1js__namespace.Integer({ value: this.keyLength }));
  4959. }
  4960. if (this.prf) {
  4961. if (PBKDF2Params.defaultValues(PRF).isEqual(this.prf) === false)
  4962. outputArray.push(this.prf.toSchema());
  4963. }
  4964. return (new asn1js__namespace.Sequence({
  4965. value: outputArray
  4966. }));
  4967. }
  4968. toJSON() {
  4969. const res = {
  4970. salt: this.salt.toJSON(),
  4971. iterationCount: this.iterationCount
  4972. };
  4973. if (KEY_LENGTH in this) {
  4974. if (PBKDF2Params.defaultValues(KEY_LENGTH) !== this.keyLength)
  4975. res.keyLength = this.keyLength;
  4976. }
  4977. if (this.prf) {
  4978. if (PBKDF2Params.defaultValues(PRF).isEqual(this.prf) === false)
  4979. res.prf = this.prf.toJSON();
  4980. }
  4981. return res;
  4982. }
  4983. }
  4984. PBKDF2Params.CLASS_NAME = "PBKDF2Params";
  4985. const KEY_DERIVATION_FUNC = "keyDerivationFunc";
  4986. const ENCRYPTION_SCHEME = "encryptionScheme";
  4987. const CLEAR_PROPS$12 = [
  4988. KEY_DERIVATION_FUNC,
  4989. ENCRYPTION_SCHEME
  4990. ];
  4991. class PBES2Params extends PkiObject {
  4992. constructor(parameters = {}) {
  4993. super();
  4994. this.keyDerivationFunc = pvutils__namespace.getParametersValue(parameters, KEY_DERIVATION_FUNC, PBES2Params.defaultValues(KEY_DERIVATION_FUNC));
  4995. this.encryptionScheme = pvutils__namespace.getParametersValue(parameters, ENCRYPTION_SCHEME, PBES2Params.defaultValues(ENCRYPTION_SCHEME));
  4996. if (parameters.schema) {
  4997. this.fromSchema(parameters.schema);
  4998. }
  4999. }
  5000. static defaultValues(memberName) {
  5001. switch (memberName) {
  5002. case KEY_DERIVATION_FUNC:
  5003. return new AlgorithmIdentifier();
  5004. case ENCRYPTION_SCHEME:
  5005. return new AlgorithmIdentifier();
  5006. default:
  5007. return super.defaultValues(memberName);
  5008. }
  5009. }
  5010. static schema(parameters = {}) {
  5011. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  5012. return (new asn1js__namespace.Sequence({
  5013. name: (names.blockName || EMPTY_STRING),
  5014. value: [
  5015. AlgorithmIdentifier.schema(names.keyDerivationFunc || {}),
  5016. AlgorithmIdentifier.schema(names.encryptionScheme || {})
  5017. ]
  5018. }));
  5019. }
  5020. fromSchema(schema) {
  5021. pvutils__namespace.clearProps(schema, CLEAR_PROPS$12);
  5022. const asn1 = asn1js__namespace.compareSchema(schema, schema, PBES2Params.schema({
  5023. names: {
  5024. keyDerivationFunc: {
  5025. names: {
  5026. blockName: KEY_DERIVATION_FUNC
  5027. }
  5028. },
  5029. encryptionScheme: {
  5030. names: {
  5031. blockName: ENCRYPTION_SCHEME
  5032. }
  5033. }
  5034. }
  5035. }));
  5036. AsnError.assertSchema(asn1, this.className);
  5037. this.keyDerivationFunc = new AlgorithmIdentifier({ schema: asn1.result.keyDerivationFunc });
  5038. this.encryptionScheme = new AlgorithmIdentifier({ schema: asn1.result.encryptionScheme });
  5039. }
  5040. toSchema() {
  5041. return (new asn1js__namespace.Sequence({
  5042. value: [
  5043. this.keyDerivationFunc.toSchema(),
  5044. this.encryptionScheme.toSchema()
  5045. ]
  5046. }));
  5047. }
  5048. toJSON() {
  5049. return {
  5050. keyDerivationFunc: this.keyDerivationFunc.toJSON(),
  5051. encryptionScheme: this.encryptionScheme.toJSON()
  5052. };
  5053. }
  5054. }
  5055. PBES2Params.CLASS_NAME = "PBES2Params";
  5056. class AbstractCryptoEngine {
  5057. constructor(parameters) {
  5058. this.crypto = parameters.crypto;
  5059. this.subtle = "webkitSubtle" in parameters.crypto
  5060. ? parameters.crypto.webkitSubtle
  5061. : parameters.crypto.subtle;
  5062. this.name = pvutils__namespace.getParametersValue(parameters, "name", EMPTY_STRING);
  5063. }
  5064. async encrypt(...args) {
  5065. return this.subtle.encrypt(...args);
  5066. }
  5067. async decrypt(...args) {
  5068. return this.subtle.decrypt(...args);
  5069. }
  5070. sign(...args) {
  5071. return this.subtle.sign(...args);
  5072. }
  5073. async verify(...args) {
  5074. return this.subtle.verify(...args);
  5075. }
  5076. async digest(...args) {
  5077. return this.subtle.digest(...args);
  5078. }
  5079. async generateKey(...args) {
  5080. return this.subtle.generateKey(...args);
  5081. }
  5082. async deriveKey(...args) {
  5083. return this.subtle.deriveKey(...args);
  5084. }
  5085. async deriveBits(...args) {
  5086. return this.subtle.deriveBits(...args);
  5087. }
  5088. async wrapKey(...args) {
  5089. return this.subtle.wrapKey(...args);
  5090. }
  5091. async unwrapKey(...args) {
  5092. return this.subtle.unwrapKey(...args);
  5093. }
  5094. exportKey(...args) {
  5095. return this.subtle.exportKey(...args);
  5096. }
  5097. importKey(...args) {
  5098. return this.subtle.importKey(...args);
  5099. }
  5100. getRandomValues(array) {
  5101. if (array === null) {
  5102. throw new Error("Argument \"array\" must not be null");
  5103. }
  5104. return this.crypto.getRandomValues(array);
  5105. }
  5106. }
  5107. async function makePKCS12B2Key(hashAlgorithm, keyLength, password, salt, iterationCount) {
  5108. let u;
  5109. let v;
  5110. let md;
  5111. switch (hashAlgorithm.toUpperCase()) {
  5112. case "SHA-1":
  5113. u = 20;
  5114. v = 64;
  5115. md = sha1.sha1;
  5116. break;
  5117. case "SHA-256":
  5118. u = 32;
  5119. v = 64;
  5120. md = sha2.sha256;
  5121. break;
  5122. case "SHA-384":
  5123. u = 48;
  5124. v = 128;
  5125. md = sha2.sha384;
  5126. break;
  5127. case "SHA-512":
  5128. u = 64;
  5129. v = 128;
  5130. md = sha2.sha512;
  5131. break;
  5132. default:
  5133. throw new Error("Unsupported hashing algorithm");
  5134. }
  5135. const originalPassword = new Uint8Array(password);
  5136. let decodedPassword = new TextDecoder().decode(password);
  5137. const encodedPassword = new TextEncoder().encode(decodedPassword);
  5138. if (encodedPassword.some((byte, i) => byte !== originalPassword[i])) {
  5139. decodedPassword = String.fromCharCode(...originalPassword);
  5140. }
  5141. const passwordTransformed = new Uint8Array(decodedPassword.length * 2 + 2);
  5142. const passwordView = new DataView(passwordTransformed.buffer);
  5143. for (let i = 0; i < decodedPassword.length; i++) {
  5144. passwordView.setUint16(i * 2, decodedPassword.charCodeAt(i), false);
  5145. }
  5146. passwordView.setUint16(decodedPassword.length * 2, 0, false);
  5147. const D = new Uint8Array(v).fill(3);
  5148. const saltView = new Uint8Array(salt);
  5149. const S = new Uint8Array(v * Math.ceil(saltView.length / v)).map((_, i) => saltView[i % saltView.length]);
  5150. const P = new Uint8Array(v * Math.ceil(passwordTransformed.length / v)).map((_, i) => passwordTransformed[i % passwordTransformed.length]);
  5151. let I = new Uint8Array(S.length + P.length);
  5152. I.set(S);
  5153. I.set(P, S.length);
  5154. const c = Math.ceil((keyLength >> 3) / u);
  5155. const result = [];
  5156. for (let i = 0; i < c; i++) {
  5157. let A = new Uint8Array(D.length + I.length);
  5158. A.set(D);
  5159. A.set(I, D.length);
  5160. for (let j = 0; j < iterationCount; j++) {
  5161. A = md(A);
  5162. }
  5163. const B = new Uint8Array(v).map((_, i) => A[i % A.length]);
  5164. const k = Math.ceil(saltView.length / v) + Math.ceil(passwordTransformed.length / v);
  5165. const iRound = [];
  5166. for (let j = 0; j < k; j++) {
  5167. const chunk = Array.from(I.slice(j * v, (j + 1) * v));
  5168. let x = 0x1ff;
  5169. for (let l = B.length - 1; l >= 0; l--) {
  5170. x >>= 8;
  5171. x += B[l] + (chunk[l] || 0);
  5172. chunk[l] = x & 0xff;
  5173. }
  5174. iRound.push(...chunk);
  5175. }
  5176. I = new Uint8Array(iRound);
  5177. result.push(...A);
  5178. }
  5179. return new Uint8Array(result.slice(0, keyLength >> 3)).buffer;
  5180. }
  5181. function prepareAlgorithm(data) {
  5182. const res = typeof data === "string"
  5183. ? { name: data }
  5184. : data;
  5185. if ("hash" in res) {
  5186. return {
  5187. ...res,
  5188. hash: prepareAlgorithm(res.hash)
  5189. };
  5190. }
  5191. return res;
  5192. }
  5193. class CryptoEngine extends AbstractCryptoEngine {
  5194. async importKey(format, keyData, algorithm, extractable, keyUsages) {
  5195. var _a, _b, _c, _d, _e, _f;
  5196. let jwk = {};
  5197. const alg = prepareAlgorithm(algorithm);
  5198. switch (format.toLowerCase()) {
  5199. case "raw":
  5200. return this.subtle.importKey("raw", keyData, algorithm, extractable, keyUsages);
  5201. case "spki":
  5202. {
  5203. const asn1 = asn1js__namespace.fromBER(pvtsutils__namespace.BufferSourceConverter.toArrayBuffer(keyData));
  5204. AsnError.assert(asn1, "keyData");
  5205. const publicKeyInfo = new PublicKeyInfo();
  5206. try {
  5207. publicKeyInfo.fromSchema(asn1.result);
  5208. }
  5209. catch {
  5210. throw new ArgumentError("Incorrect keyData");
  5211. }
  5212. switch (alg.name.toUpperCase()) {
  5213. case "RSA-PSS":
  5214. {
  5215. if (!alg.hash) {
  5216. throw new ParameterError("hash", "algorithm.hash", "Incorrect hash algorithm: Hash algorithm is missed");
  5217. }
  5218. switch (alg.hash.name.toUpperCase()) {
  5219. case "SHA-1":
  5220. jwk.alg = "PS1";
  5221. break;
  5222. case "SHA-256":
  5223. jwk.alg = "PS256";
  5224. break;
  5225. case "SHA-384":
  5226. jwk.alg = "PS384";
  5227. break;
  5228. case "SHA-512":
  5229. jwk.alg = "PS512";
  5230. break;
  5231. default:
  5232. throw new Error(`Incorrect hash algorithm: ${alg.hash.name.toUpperCase()}`);
  5233. }
  5234. }
  5235. case "RSASSA-PKCS1-V1_5":
  5236. {
  5237. keyUsages = ["verify"];
  5238. jwk.kty = "RSA";
  5239. jwk.ext = extractable;
  5240. jwk.key_ops = keyUsages;
  5241. if (publicKeyInfo.algorithm.algorithmId !== "1.2.840.113549.1.1.1")
  5242. throw new Error(`Incorrect public key algorithm: ${publicKeyInfo.algorithm.algorithmId}`);
  5243. if (!jwk.alg) {
  5244. if (!alg.hash) {
  5245. throw new ParameterError("hash", "algorithm.hash", "Incorrect hash algorithm: Hash algorithm is missed");
  5246. }
  5247. switch (alg.hash.name.toUpperCase()) {
  5248. case "SHA-1":
  5249. jwk.alg = "RS1";
  5250. break;
  5251. case "SHA-256":
  5252. jwk.alg = "RS256";
  5253. break;
  5254. case "SHA-384":
  5255. jwk.alg = "RS384";
  5256. break;
  5257. case "SHA-512":
  5258. jwk.alg = "RS512";
  5259. break;
  5260. default:
  5261. throw new Error(`Incorrect hash algorithm: ${alg.hash.name.toUpperCase()}`);
  5262. }
  5263. }
  5264. const publicKeyJSON = publicKeyInfo.toJSON();
  5265. Object.assign(jwk, publicKeyJSON);
  5266. }
  5267. break;
  5268. case "ECDSA":
  5269. keyUsages = ["verify"];
  5270. case "ECDH":
  5271. {
  5272. jwk = {
  5273. kty: "EC",
  5274. ext: extractable,
  5275. key_ops: keyUsages
  5276. };
  5277. if (publicKeyInfo.algorithm.algorithmId !== "1.2.840.10045.2.1") {
  5278. throw new Error(`Incorrect public key algorithm: ${publicKeyInfo.algorithm.algorithmId}`);
  5279. }
  5280. const publicKeyJSON = publicKeyInfo.toJSON();
  5281. Object.assign(jwk, publicKeyJSON);
  5282. }
  5283. break;
  5284. case "RSA-OAEP":
  5285. {
  5286. jwk.kty = "RSA";
  5287. jwk.ext = extractable;
  5288. jwk.key_ops = keyUsages;
  5289. if (this.name.toLowerCase() === "safari")
  5290. jwk.alg = "RSA-OAEP";
  5291. else {
  5292. if (!alg.hash) {
  5293. throw new ParameterError("hash", "algorithm.hash", "Incorrect hash algorithm: Hash algorithm is missed");
  5294. }
  5295. switch (alg.hash.name.toUpperCase()) {
  5296. case "SHA-1":
  5297. jwk.alg = "RSA-OAEP";
  5298. break;
  5299. case "SHA-256":
  5300. jwk.alg = "RSA-OAEP-256";
  5301. break;
  5302. case "SHA-384":
  5303. jwk.alg = "RSA-OAEP-384";
  5304. break;
  5305. case "SHA-512":
  5306. jwk.alg = "RSA-OAEP-512";
  5307. break;
  5308. default:
  5309. throw new Error(`Incorrect hash algorithm: ${alg.hash.name.toUpperCase()}`);
  5310. }
  5311. }
  5312. const publicKeyJSON = publicKeyInfo.toJSON();
  5313. Object.assign(jwk, publicKeyJSON);
  5314. }
  5315. break;
  5316. case "RSAES-PKCS1-V1_5":
  5317. {
  5318. jwk.kty = "RSA";
  5319. jwk.ext = extractable;
  5320. jwk.key_ops = keyUsages;
  5321. jwk.alg = "PS1";
  5322. const publicKeyJSON = publicKeyInfo.toJSON();
  5323. Object.assign(jwk, publicKeyJSON);
  5324. }
  5325. break;
  5326. default:
  5327. throw new Error(`Incorrect algorithm name: ${alg.name.toUpperCase()}`);
  5328. }
  5329. }
  5330. break;
  5331. case "pkcs8":
  5332. {
  5333. const privateKeyInfo = new PrivateKeyInfo();
  5334. const asn1 = asn1js__namespace.fromBER(pvtsutils__namespace.BufferSourceConverter.toArrayBuffer(keyData));
  5335. AsnError.assert(asn1, "keyData");
  5336. try {
  5337. privateKeyInfo.fromSchema(asn1.result);
  5338. }
  5339. catch {
  5340. throw new Error("Incorrect keyData");
  5341. }
  5342. if (!privateKeyInfo.parsedKey)
  5343. throw new Error("Incorrect keyData");
  5344. switch (alg.name.toUpperCase()) {
  5345. case "RSA-PSS":
  5346. {
  5347. switch ((_a = alg.hash) === null || _a === void 0 ? void 0 : _a.name.toUpperCase()) {
  5348. case "SHA-1":
  5349. jwk.alg = "PS1";
  5350. break;
  5351. case "SHA-256":
  5352. jwk.alg = "PS256";
  5353. break;
  5354. case "SHA-384":
  5355. jwk.alg = "PS384";
  5356. break;
  5357. case "SHA-512":
  5358. jwk.alg = "PS512";
  5359. break;
  5360. default:
  5361. throw new Error(`Incorrect hash algorithm: ${(_b = alg.hash) === null || _b === void 0 ? void 0 : _b.name.toUpperCase()}`);
  5362. }
  5363. }
  5364. case "RSASSA-PKCS1-V1_5":
  5365. {
  5366. keyUsages = ["sign"];
  5367. jwk.kty = "RSA";
  5368. jwk.ext = extractable;
  5369. jwk.key_ops = keyUsages;
  5370. if (privateKeyInfo.privateKeyAlgorithm.algorithmId !== "1.2.840.113549.1.1.1")
  5371. throw new Error(`Incorrect private key algorithm: ${privateKeyInfo.privateKeyAlgorithm.algorithmId}`);
  5372. if (("alg" in jwk) === false) {
  5373. switch ((_c = alg.hash) === null || _c === void 0 ? void 0 : _c.name.toUpperCase()) {
  5374. case "SHA-1":
  5375. jwk.alg = "RS1";
  5376. break;
  5377. case "SHA-256":
  5378. jwk.alg = "RS256";
  5379. break;
  5380. case "SHA-384":
  5381. jwk.alg = "RS384";
  5382. break;
  5383. case "SHA-512":
  5384. jwk.alg = "RS512";
  5385. break;
  5386. default:
  5387. throw new Error(`Incorrect hash algorithm: ${(_d = alg.hash) === null || _d === void 0 ? void 0 : _d.name.toUpperCase()}`);
  5388. }
  5389. }
  5390. const privateKeyJSON = privateKeyInfo.toJSON();
  5391. Object.assign(jwk, privateKeyJSON);
  5392. }
  5393. break;
  5394. case "ECDSA":
  5395. keyUsages = ["sign"];
  5396. case "ECDH":
  5397. {
  5398. jwk = {
  5399. kty: "EC",
  5400. ext: extractable,
  5401. key_ops: keyUsages
  5402. };
  5403. if (privateKeyInfo.privateKeyAlgorithm.algorithmId !== "1.2.840.10045.2.1")
  5404. throw new Error(`Incorrect algorithm: ${privateKeyInfo.privateKeyAlgorithm.algorithmId}`);
  5405. const privateKeyJSON = privateKeyInfo.toJSON();
  5406. Object.assign(jwk, privateKeyJSON);
  5407. }
  5408. break;
  5409. case "RSA-OAEP":
  5410. {
  5411. jwk.kty = "RSA";
  5412. jwk.ext = extractable;
  5413. jwk.key_ops = keyUsages;
  5414. if (this.name.toLowerCase() === "safari")
  5415. jwk.alg = "RSA-OAEP";
  5416. else {
  5417. switch ((_e = alg.hash) === null || _e === void 0 ? void 0 : _e.name.toUpperCase()) {
  5418. case "SHA-1":
  5419. jwk.alg = "RSA-OAEP";
  5420. break;
  5421. case "SHA-256":
  5422. jwk.alg = "RSA-OAEP-256";
  5423. break;
  5424. case "SHA-384":
  5425. jwk.alg = "RSA-OAEP-384";
  5426. break;
  5427. case "SHA-512":
  5428. jwk.alg = "RSA-OAEP-512";
  5429. break;
  5430. default:
  5431. throw new Error(`Incorrect hash algorithm: ${(_f = alg.hash) === null || _f === void 0 ? void 0 : _f.name.toUpperCase()}`);
  5432. }
  5433. }
  5434. const privateKeyJSON = privateKeyInfo.toJSON();
  5435. Object.assign(jwk, privateKeyJSON);
  5436. }
  5437. break;
  5438. case "RSAES-PKCS1-V1_5":
  5439. {
  5440. keyUsages = ["decrypt"];
  5441. jwk.kty = "RSA";
  5442. jwk.ext = extractable;
  5443. jwk.key_ops = keyUsages;
  5444. jwk.alg = "PS1";
  5445. const privateKeyJSON = privateKeyInfo.toJSON();
  5446. Object.assign(jwk, privateKeyJSON);
  5447. }
  5448. break;
  5449. default:
  5450. throw new Error(`Incorrect algorithm name: ${alg.name.toUpperCase()}`);
  5451. }
  5452. }
  5453. break;
  5454. case "jwk":
  5455. jwk = keyData;
  5456. break;
  5457. default:
  5458. throw new Error(`Incorrect format: ${format}`);
  5459. }
  5460. if (this.name.toLowerCase() === "safari") {
  5461. try {
  5462. return this.subtle.importKey("jwk", pvutils__namespace.stringToArrayBuffer(JSON.stringify(jwk)), algorithm, extractable, keyUsages);
  5463. }
  5464. catch {
  5465. return this.subtle.importKey("jwk", jwk, algorithm, extractable, keyUsages);
  5466. }
  5467. }
  5468. return this.subtle.importKey("jwk", jwk, algorithm, extractable, keyUsages);
  5469. }
  5470. async exportKey(format, key) {
  5471. let jwk = await this.subtle.exportKey("jwk", key);
  5472. if (this.name.toLowerCase() === "safari") {
  5473. if (jwk instanceof ArrayBuffer) {
  5474. jwk = JSON.parse(pvutils__namespace.arrayBufferToString(jwk));
  5475. }
  5476. }
  5477. switch (format.toLowerCase()) {
  5478. case "raw":
  5479. return this.subtle.exportKey("raw", key);
  5480. case "spki": {
  5481. const publicKeyInfo = new PublicKeyInfo();
  5482. try {
  5483. publicKeyInfo.fromJSON(jwk);
  5484. }
  5485. catch {
  5486. throw new Error("Incorrect key data");
  5487. }
  5488. return publicKeyInfo.toSchema().toBER(false);
  5489. }
  5490. case "pkcs8": {
  5491. const privateKeyInfo = new PrivateKeyInfo();
  5492. try {
  5493. privateKeyInfo.fromJSON(jwk);
  5494. }
  5495. catch {
  5496. throw new Error("Incorrect key data");
  5497. }
  5498. return privateKeyInfo.toSchema().toBER(false);
  5499. }
  5500. case "jwk":
  5501. return jwk;
  5502. default:
  5503. throw new Error(`Incorrect format: ${format}`);
  5504. }
  5505. }
  5506. async convert(inputFormat, outputFormat, keyData, algorithm, extractable, keyUsages) {
  5507. if (inputFormat.toLowerCase() === outputFormat.toLowerCase()) {
  5508. return keyData;
  5509. }
  5510. const key = await this.importKey(inputFormat, keyData, algorithm, extractable, keyUsages);
  5511. return this.exportKey(outputFormat, key);
  5512. }
  5513. getAlgorithmByOID(oid, safety = false, target) {
  5514. switch (oid) {
  5515. case "1.2.840.113549.1.1.1":
  5516. return {
  5517. name: "RSAES-PKCS1-v1_5"
  5518. };
  5519. case "1.2.840.113549.1.1.5":
  5520. return {
  5521. name: "RSASSA-PKCS1-v1_5",
  5522. hash: {
  5523. name: "SHA-1"
  5524. }
  5525. };
  5526. case "1.2.840.113549.1.1.11":
  5527. return {
  5528. name: "RSASSA-PKCS1-v1_5",
  5529. hash: {
  5530. name: "SHA-256"
  5531. }
  5532. };
  5533. case "1.2.840.113549.1.1.12":
  5534. return {
  5535. name: "RSASSA-PKCS1-v1_5",
  5536. hash: {
  5537. name: "SHA-384"
  5538. }
  5539. };
  5540. case "1.2.840.113549.1.1.13":
  5541. return {
  5542. name: "RSASSA-PKCS1-v1_5",
  5543. hash: {
  5544. name: "SHA-512"
  5545. }
  5546. };
  5547. case "1.2.840.113549.1.1.10":
  5548. return {
  5549. name: "RSA-PSS"
  5550. };
  5551. case "1.2.840.113549.1.1.7":
  5552. return {
  5553. name: "RSA-OAEP"
  5554. };
  5555. case "1.2.840.10045.2.1":
  5556. case "1.2.840.10045.4.1":
  5557. return {
  5558. name: "ECDSA",
  5559. hash: {
  5560. name: "SHA-1"
  5561. }
  5562. };
  5563. case "1.2.840.10045.4.3.2":
  5564. return {
  5565. name: "ECDSA",
  5566. hash: {
  5567. name: "SHA-256"
  5568. }
  5569. };
  5570. case "1.2.840.10045.4.3.3":
  5571. return {
  5572. name: "ECDSA",
  5573. hash: {
  5574. name: "SHA-384"
  5575. }
  5576. };
  5577. case "1.2.840.10045.4.3.4":
  5578. return {
  5579. name: "ECDSA",
  5580. hash: {
  5581. name: "SHA-512"
  5582. }
  5583. };
  5584. case "1.3.133.16.840.63.0.2":
  5585. return {
  5586. name: "ECDH",
  5587. kdf: "SHA-1"
  5588. };
  5589. case "1.3.132.1.11.1":
  5590. return {
  5591. name: "ECDH",
  5592. kdf: "SHA-256"
  5593. };
  5594. case "1.3.132.1.11.2":
  5595. return {
  5596. name: "ECDH",
  5597. kdf: "SHA-384"
  5598. };
  5599. case "1.3.132.1.11.3":
  5600. return {
  5601. name: "ECDH",
  5602. kdf: "SHA-512"
  5603. };
  5604. case "2.16.840.1.101.3.4.1.2":
  5605. return {
  5606. name: "AES-CBC",
  5607. length: 128
  5608. };
  5609. case "2.16.840.1.101.3.4.1.22":
  5610. return {
  5611. name: "AES-CBC",
  5612. length: 192
  5613. };
  5614. case "2.16.840.1.101.3.4.1.42":
  5615. return {
  5616. name: "AES-CBC",
  5617. length: 256
  5618. };
  5619. case "2.16.840.1.101.3.4.1.6":
  5620. return {
  5621. name: "AES-GCM",
  5622. length: 128
  5623. };
  5624. case "2.16.840.1.101.3.4.1.26":
  5625. return {
  5626. name: "AES-GCM",
  5627. length: 192
  5628. };
  5629. case "2.16.840.1.101.3.4.1.46":
  5630. return {
  5631. name: "AES-GCM",
  5632. length: 256
  5633. };
  5634. case "2.16.840.1.101.3.4.1.4":
  5635. return {
  5636. name: "AES-CFB",
  5637. length: 128
  5638. };
  5639. case "2.16.840.1.101.3.4.1.24":
  5640. return {
  5641. name: "AES-CFB",
  5642. length: 192
  5643. };
  5644. case "2.16.840.1.101.3.4.1.44":
  5645. return {
  5646. name: "AES-CFB",
  5647. length: 256
  5648. };
  5649. case "2.16.840.1.101.3.4.1.5":
  5650. return {
  5651. name: "AES-KW",
  5652. length: 128
  5653. };
  5654. case "2.16.840.1.101.3.4.1.25":
  5655. return {
  5656. name: "AES-KW",
  5657. length: 192
  5658. };
  5659. case "2.16.840.1.101.3.4.1.45":
  5660. return {
  5661. name: "AES-KW",
  5662. length: 256
  5663. };
  5664. case "1.2.840.113549.2.7":
  5665. return {
  5666. name: "HMAC",
  5667. hash: {
  5668. name: "SHA-1"
  5669. }
  5670. };
  5671. case "1.2.840.113549.2.9":
  5672. return {
  5673. name: "HMAC",
  5674. hash: {
  5675. name: "SHA-256"
  5676. }
  5677. };
  5678. case "1.2.840.113549.2.10":
  5679. return {
  5680. name: "HMAC",
  5681. hash: {
  5682. name: "SHA-384"
  5683. }
  5684. };
  5685. case "1.2.840.113549.2.11":
  5686. return {
  5687. name: "HMAC",
  5688. hash: {
  5689. name: "SHA-512"
  5690. }
  5691. };
  5692. case "1.2.840.113549.1.9.16.3.5":
  5693. return {
  5694. name: "DH"
  5695. };
  5696. case "1.3.14.3.2.26":
  5697. return {
  5698. name: "SHA-1"
  5699. };
  5700. case "2.16.840.1.101.3.4.2.1":
  5701. return {
  5702. name: "SHA-256"
  5703. };
  5704. case "2.16.840.1.101.3.4.2.2":
  5705. return {
  5706. name: "SHA-384"
  5707. };
  5708. case "2.16.840.1.101.3.4.2.3":
  5709. return {
  5710. name: "SHA-512"
  5711. };
  5712. case "1.2.840.113549.1.5.12":
  5713. return {
  5714. name: "PBKDF2"
  5715. };
  5716. case "1.2.840.10045.3.1.7":
  5717. return {
  5718. name: "P-256"
  5719. };
  5720. case "1.3.132.0.34":
  5721. return {
  5722. name: "P-384"
  5723. };
  5724. case "1.3.132.0.35":
  5725. return {
  5726. name: "P-521"
  5727. };
  5728. }
  5729. if (safety) {
  5730. throw new Error(`Unsupported algorithm identifier ${target ? `for ${target} ` : EMPTY_STRING}: ${oid}`);
  5731. }
  5732. return {};
  5733. }
  5734. getOIDByAlgorithm(algorithm, safety = false, target) {
  5735. let result = EMPTY_STRING;
  5736. switch (algorithm.name.toUpperCase()) {
  5737. case "RSAES-PKCS1-V1_5":
  5738. result = "1.2.840.113549.1.1.1";
  5739. break;
  5740. case "RSASSA-PKCS1-V1_5":
  5741. switch (algorithm.hash.name.toUpperCase()) {
  5742. case "SHA-1":
  5743. result = "1.2.840.113549.1.1.5";
  5744. break;
  5745. case "SHA-256":
  5746. result = "1.2.840.113549.1.1.11";
  5747. break;
  5748. case "SHA-384":
  5749. result = "1.2.840.113549.1.1.12";
  5750. break;
  5751. case "SHA-512":
  5752. result = "1.2.840.113549.1.1.13";
  5753. break;
  5754. }
  5755. break;
  5756. case "RSA-PSS":
  5757. result = "1.2.840.113549.1.1.10";
  5758. break;
  5759. case "RSA-OAEP":
  5760. result = "1.2.840.113549.1.1.7";
  5761. break;
  5762. case "ECDSA":
  5763. switch (algorithm.hash.name.toUpperCase()) {
  5764. case "SHA-1":
  5765. result = "1.2.840.10045.4.1";
  5766. break;
  5767. case "SHA-256":
  5768. result = "1.2.840.10045.4.3.2";
  5769. break;
  5770. case "SHA-384":
  5771. result = "1.2.840.10045.4.3.3";
  5772. break;
  5773. case "SHA-512":
  5774. result = "1.2.840.10045.4.3.4";
  5775. break;
  5776. }
  5777. break;
  5778. case "ECDH":
  5779. switch (algorithm.kdf.toUpperCase()) {
  5780. case "SHA-1":
  5781. result = "1.3.133.16.840.63.0.2";
  5782. break;
  5783. case "SHA-256":
  5784. result = "1.3.132.1.11.1";
  5785. break;
  5786. case "SHA-384":
  5787. result = "1.3.132.1.11.2";
  5788. break;
  5789. case "SHA-512":
  5790. result = "1.3.132.1.11.3";
  5791. break;
  5792. }
  5793. break;
  5794. case "AES-CTR":
  5795. break;
  5796. case "AES-CBC":
  5797. switch (algorithm.length) {
  5798. case 128:
  5799. result = "2.16.840.1.101.3.4.1.2";
  5800. break;
  5801. case 192:
  5802. result = "2.16.840.1.101.3.4.1.22";
  5803. break;
  5804. case 256:
  5805. result = "2.16.840.1.101.3.4.1.42";
  5806. break;
  5807. }
  5808. break;
  5809. case "AES-CMAC":
  5810. break;
  5811. case "AES-GCM":
  5812. switch (algorithm.length) {
  5813. case 128:
  5814. result = "2.16.840.1.101.3.4.1.6";
  5815. break;
  5816. case 192:
  5817. result = "2.16.840.1.101.3.4.1.26";
  5818. break;
  5819. case 256:
  5820. result = "2.16.840.1.101.3.4.1.46";
  5821. break;
  5822. }
  5823. break;
  5824. case "AES-CFB":
  5825. switch (algorithm.length) {
  5826. case 128:
  5827. result = "2.16.840.1.101.3.4.1.4";
  5828. break;
  5829. case 192:
  5830. result = "2.16.840.1.101.3.4.1.24";
  5831. break;
  5832. case 256:
  5833. result = "2.16.840.1.101.3.4.1.44";
  5834. break;
  5835. }
  5836. break;
  5837. case "AES-KW":
  5838. switch (algorithm.length) {
  5839. case 128:
  5840. result = "2.16.840.1.101.3.4.1.5";
  5841. break;
  5842. case 192:
  5843. result = "2.16.840.1.101.3.4.1.25";
  5844. break;
  5845. case 256:
  5846. result = "2.16.840.1.101.3.4.1.45";
  5847. break;
  5848. }
  5849. break;
  5850. case "HMAC":
  5851. switch (algorithm.hash.name.toUpperCase()) {
  5852. case "SHA-1":
  5853. result = "1.2.840.113549.2.7";
  5854. break;
  5855. case "SHA-256":
  5856. result = "1.2.840.113549.2.9";
  5857. break;
  5858. case "SHA-384":
  5859. result = "1.2.840.113549.2.10";
  5860. break;
  5861. case "SHA-512":
  5862. result = "1.2.840.113549.2.11";
  5863. break;
  5864. }
  5865. break;
  5866. case "DH":
  5867. result = "1.2.840.113549.1.9.16.3.5";
  5868. break;
  5869. case "SHA-1":
  5870. result = "1.3.14.3.2.26";
  5871. break;
  5872. case "SHA-256":
  5873. result = "2.16.840.1.101.3.4.2.1";
  5874. break;
  5875. case "SHA-384":
  5876. result = "2.16.840.1.101.3.4.2.2";
  5877. break;
  5878. case "SHA-512":
  5879. result = "2.16.840.1.101.3.4.2.3";
  5880. break;
  5881. case "CONCAT":
  5882. break;
  5883. case "HKDF":
  5884. break;
  5885. case "PBKDF2":
  5886. result = "1.2.840.113549.1.5.12";
  5887. break;
  5888. case "P-256":
  5889. result = "1.2.840.10045.3.1.7";
  5890. break;
  5891. case "P-384":
  5892. result = "1.3.132.0.34";
  5893. break;
  5894. case "P-521":
  5895. result = "1.3.132.0.35";
  5896. break;
  5897. }
  5898. if (!result && safety) {
  5899. throw new Error(`Unsupported algorithm ${target ? `for ${target} ` : EMPTY_STRING}: ${algorithm.name}`);
  5900. }
  5901. return result;
  5902. }
  5903. getAlgorithmParameters(algorithmName, operation) {
  5904. let result = {
  5905. algorithm: {},
  5906. usages: []
  5907. };
  5908. switch (algorithmName.toUpperCase()) {
  5909. case "RSAES-PKCS1-V1_5":
  5910. case "RSASSA-PKCS1-V1_5":
  5911. switch (operation.toLowerCase()) {
  5912. case "generatekey":
  5913. result = {
  5914. algorithm: {
  5915. name: "RSASSA-PKCS1-v1_5",
  5916. modulusLength: 2048,
  5917. publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
  5918. hash: {
  5919. name: "SHA-256"
  5920. }
  5921. },
  5922. usages: ["sign", "verify"]
  5923. };
  5924. break;
  5925. case "verify":
  5926. case "sign":
  5927. case "importkey":
  5928. result = {
  5929. algorithm: {
  5930. name: "RSASSA-PKCS1-v1_5",
  5931. hash: {
  5932. name: "SHA-256"
  5933. }
  5934. },
  5935. usages: ["verify"]
  5936. };
  5937. break;
  5938. case "exportkey":
  5939. default:
  5940. return {
  5941. algorithm: {
  5942. name: "RSASSA-PKCS1-v1_5"
  5943. },
  5944. usages: []
  5945. };
  5946. }
  5947. break;
  5948. case "RSA-PSS":
  5949. switch (operation.toLowerCase()) {
  5950. case "sign":
  5951. case "verify":
  5952. result = {
  5953. algorithm: {
  5954. name: "RSA-PSS",
  5955. hash: {
  5956. name: "SHA-1"
  5957. },
  5958. saltLength: 20
  5959. },
  5960. usages: ["sign", "verify"]
  5961. };
  5962. break;
  5963. case "generatekey":
  5964. result = {
  5965. algorithm: {
  5966. name: "RSA-PSS",
  5967. modulusLength: 2048,
  5968. publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
  5969. hash: {
  5970. name: "SHA-1"
  5971. }
  5972. },
  5973. usages: ["sign", "verify"]
  5974. };
  5975. break;
  5976. case "importkey":
  5977. result = {
  5978. algorithm: {
  5979. name: "RSA-PSS",
  5980. hash: {
  5981. name: "SHA-1"
  5982. }
  5983. },
  5984. usages: ["verify"]
  5985. };
  5986. break;
  5987. case "exportkey":
  5988. default:
  5989. return {
  5990. algorithm: {
  5991. name: "RSA-PSS"
  5992. },
  5993. usages: []
  5994. };
  5995. }
  5996. break;
  5997. case "RSA-OAEP":
  5998. switch (operation.toLowerCase()) {
  5999. case "encrypt":
  6000. case "decrypt":
  6001. result = {
  6002. algorithm: {
  6003. name: "RSA-OAEP"
  6004. },
  6005. usages: ["encrypt", "decrypt"]
  6006. };
  6007. break;
  6008. case "generatekey":
  6009. result = {
  6010. algorithm: {
  6011. name: "RSA-OAEP",
  6012. modulusLength: 2048,
  6013. publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
  6014. hash: {
  6015. name: "SHA-256"
  6016. }
  6017. },
  6018. usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"]
  6019. };
  6020. break;
  6021. case "importkey":
  6022. result = {
  6023. algorithm: {
  6024. name: "RSA-OAEP",
  6025. hash: {
  6026. name: "SHA-256"
  6027. }
  6028. },
  6029. usages: ["encrypt"]
  6030. };
  6031. break;
  6032. case "exportkey":
  6033. default:
  6034. return {
  6035. algorithm: {
  6036. name: "RSA-OAEP"
  6037. },
  6038. usages: []
  6039. };
  6040. }
  6041. break;
  6042. case "ECDSA":
  6043. switch (operation.toLowerCase()) {
  6044. case "generatekey":
  6045. result = {
  6046. algorithm: {
  6047. name: "ECDSA",
  6048. namedCurve: "P-256"
  6049. },
  6050. usages: ["sign", "verify"]
  6051. };
  6052. break;
  6053. case "importkey":
  6054. result = {
  6055. algorithm: {
  6056. name: "ECDSA",
  6057. namedCurve: "P-256"
  6058. },
  6059. usages: ["verify"]
  6060. };
  6061. break;
  6062. case "verify":
  6063. case "sign":
  6064. result = {
  6065. algorithm: {
  6066. name: "ECDSA",
  6067. hash: {
  6068. name: "SHA-256"
  6069. }
  6070. },
  6071. usages: ["sign"]
  6072. };
  6073. break;
  6074. default:
  6075. return {
  6076. algorithm: {
  6077. name: "ECDSA"
  6078. },
  6079. usages: []
  6080. };
  6081. }
  6082. break;
  6083. case "ECDH":
  6084. switch (operation.toLowerCase()) {
  6085. case "exportkey":
  6086. case "importkey":
  6087. case "generatekey":
  6088. result = {
  6089. algorithm: {
  6090. name: "ECDH",
  6091. namedCurve: "P-256"
  6092. },
  6093. usages: ["deriveKey", "deriveBits"]
  6094. };
  6095. break;
  6096. case "derivekey":
  6097. case "derivebits":
  6098. result = {
  6099. algorithm: {
  6100. name: "ECDH",
  6101. namedCurve: "P-256",
  6102. public: []
  6103. },
  6104. usages: ["encrypt", "decrypt"]
  6105. };
  6106. break;
  6107. default:
  6108. return {
  6109. algorithm: {
  6110. name: "ECDH"
  6111. },
  6112. usages: []
  6113. };
  6114. }
  6115. break;
  6116. case "AES-CTR":
  6117. switch (operation.toLowerCase()) {
  6118. case "importkey":
  6119. case "exportkey":
  6120. case "generatekey":
  6121. result = {
  6122. algorithm: {
  6123. name: "AES-CTR",
  6124. length: 256
  6125. },
  6126. usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"]
  6127. };
  6128. break;
  6129. case "decrypt":
  6130. case "encrypt":
  6131. result = {
  6132. algorithm: {
  6133. name: "AES-CTR",
  6134. counter: new Uint8Array(16),
  6135. length: 10
  6136. },
  6137. usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"]
  6138. };
  6139. break;
  6140. default:
  6141. return {
  6142. algorithm: {
  6143. name: "AES-CTR"
  6144. },
  6145. usages: []
  6146. };
  6147. }
  6148. break;
  6149. case "AES-CBC":
  6150. switch (operation.toLowerCase()) {
  6151. case "importkey":
  6152. case "exportkey":
  6153. case "generatekey":
  6154. result = {
  6155. algorithm: {
  6156. name: "AES-CBC",
  6157. length: 256
  6158. },
  6159. usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"]
  6160. };
  6161. break;
  6162. case "decrypt":
  6163. case "encrypt":
  6164. result = {
  6165. algorithm: {
  6166. name: "AES-CBC",
  6167. iv: this.getRandomValues(new Uint8Array(16))
  6168. },
  6169. usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"]
  6170. };
  6171. break;
  6172. default:
  6173. return {
  6174. algorithm: {
  6175. name: "AES-CBC"
  6176. },
  6177. usages: []
  6178. };
  6179. }
  6180. break;
  6181. case "AES-GCM":
  6182. switch (operation.toLowerCase()) {
  6183. case "importkey":
  6184. case "exportkey":
  6185. case "generatekey":
  6186. result = {
  6187. algorithm: {
  6188. name: "AES-GCM",
  6189. length: 256
  6190. },
  6191. usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"]
  6192. };
  6193. break;
  6194. case "decrypt":
  6195. case "encrypt":
  6196. result = {
  6197. algorithm: {
  6198. name: "AES-GCM",
  6199. iv: this.getRandomValues(new Uint8Array(16))
  6200. },
  6201. usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"]
  6202. };
  6203. break;
  6204. default:
  6205. return {
  6206. algorithm: {
  6207. name: "AES-GCM"
  6208. },
  6209. usages: []
  6210. };
  6211. }
  6212. break;
  6213. case "AES-KW":
  6214. switch (operation.toLowerCase()) {
  6215. case "importkey":
  6216. case "exportkey":
  6217. case "generatekey":
  6218. case "wrapkey":
  6219. case "unwrapkey":
  6220. result = {
  6221. algorithm: {
  6222. name: "AES-KW",
  6223. length: 256
  6224. },
  6225. usages: ["wrapKey", "unwrapKey"]
  6226. };
  6227. break;
  6228. default:
  6229. return {
  6230. algorithm: {
  6231. name: "AES-KW"
  6232. },
  6233. usages: []
  6234. };
  6235. }
  6236. break;
  6237. case "HMAC":
  6238. switch (operation.toLowerCase()) {
  6239. case "sign":
  6240. case "verify":
  6241. result = {
  6242. algorithm: {
  6243. name: "HMAC"
  6244. },
  6245. usages: ["sign", "verify"]
  6246. };
  6247. break;
  6248. case "importkey":
  6249. case "exportkey":
  6250. case "generatekey":
  6251. result = {
  6252. algorithm: {
  6253. name: "HMAC",
  6254. length: 32,
  6255. hash: {
  6256. name: "SHA-256"
  6257. }
  6258. },
  6259. usages: ["sign", "verify"]
  6260. };
  6261. break;
  6262. default:
  6263. return {
  6264. algorithm: {
  6265. name: "HMAC"
  6266. },
  6267. usages: []
  6268. };
  6269. }
  6270. break;
  6271. case "HKDF":
  6272. switch (operation.toLowerCase()) {
  6273. case "derivekey":
  6274. result = {
  6275. algorithm: {
  6276. name: "HKDF",
  6277. hash: "SHA-256",
  6278. salt: new Uint8Array([]),
  6279. info: new Uint8Array([])
  6280. },
  6281. usages: ["encrypt", "decrypt"]
  6282. };
  6283. break;
  6284. default:
  6285. return {
  6286. algorithm: {
  6287. name: "HKDF"
  6288. },
  6289. usages: []
  6290. };
  6291. }
  6292. break;
  6293. case "PBKDF2":
  6294. switch (operation.toLowerCase()) {
  6295. case "derivekey":
  6296. result = {
  6297. algorithm: {
  6298. name: "PBKDF2",
  6299. hash: { name: "SHA-256" },
  6300. salt: new Uint8Array([]),
  6301. iterations: 10000
  6302. },
  6303. usages: ["encrypt", "decrypt"]
  6304. };
  6305. break;
  6306. default:
  6307. return {
  6308. algorithm: {
  6309. name: "PBKDF2"
  6310. },
  6311. usages: []
  6312. };
  6313. }
  6314. break;
  6315. }
  6316. return result;
  6317. }
  6318. getHashAlgorithm(signatureAlgorithm) {
  6319. let result = EMPTY_STRING;
  6320. switch (signatureAlgorithm.algorithmId) {
  6321. case "1.2.840.10045.4.1":
  6322. case "1.2.840.113549.1.1.5":
  6323. result = "SHA-1";
  6324. break;
  6325. case "1.2.840.10045.4.3.2":
  6326. case "1.2.840.113549.1.1.11":
  6327. result = "SHA-256";
  6328. break;
  6329. case "1.2.840.10045.4.3.3":
  6330. case "1.2.840.113549.1.1.12":
  6331. result = "SHA-384";
  6332. break;
  6333. case "1.2.840.10045.4.3.4":
  6334. case "1.2.840.113549.1.1.13":
  6335. result = "SHA-512";
  6336. break;
  6337. case "1.2.840.113549.1.1.10":
  6338. {
  6339. try {
  6340. const params = new RSASSAPSSParams({ schema: signatureAlgorithm.algorithmParams });
  6341. if (params.hashAlgorithm) {
  6342. const algorithm = this.getAlgorithmByOID(params.hashAlgorithm.algorithmId);
  6343. if ("name" in algorithm) {
  6344. result = algorithm.name;
  6345. }
  6346. else {
  6347. return EMPTY_STRING;
  6348. }
  6349. }
  6350. else
  6351. result = "SHA-1";
  6352. }
  6353. catch {
  6354. }
  6355. }
  6356. break;
  6357. }
  6358. return result;
  6359. }
  6360. async encryptEncryptedContentInfo(parameters) {
  6361. ParameterError.assert(parameters, "password", "contentEncryptionAlgorithm", "hmacHashAlgorithm", "iterationCount", "contentToEncrypt", "contentToEncrypt", "contentType");
  6362. const contentEncryptionOID = this.getOIDByAlgorithm(parameters.contentEncryptionAlgorithm, true, "contentEncryptionAlgorithm");
  6363. const pbkdf2OID = this.getOIDByAlgorithm({
  6364. name: "PBKDF2"
  6365. }, true, "PBKDF2");
  6366. const hmacOID = this.getOIDByAlgorithm({
  6367. name: "HMAC",
  6368. hash: {
  6369. name: parameters.hmacHashAlgorithm
  6370. }
  6371. }, true, "hmacHashAlgorithm");
  6372. const ivBuffer = new ArrayBuffer(16);
  6373. const ivView = new Uint8Array(ivBuffer);
  6374. this.getRandomValues(ivView);
  6375. const saltBuffer = new ArrayBuffer(64);
  6376. const saltView = new Uint8Array(saltBuffer);
  6377. this.getRandomValues(saltView);
  6378. const contentView = new Uint8Array(parameters.contentToEncrypt);
  6379. const pbkdf2Params = new PBKDF2Params({
  6380. salt: new asn1js__namespace.OctetString({ valueHex: saltBuffer }),
  6381. iterationCount: parameters.iterationCount,
  6382. prf: new AlgorithmIdentifier({
  6383. algorithmId: hmacOID,
  6384. algorithmParams: new asn1js__namespace.Null()
  6385. })
  6386. });
  6387. const passwordView = new Uint8Array(parameters.password);
  6388. const pbkdfKey = await this.importKey("raw", passwordView, "PBKDF2", false, ["deriveKey"]);
  6389. const derivedKey = await this.deriveKey({
  6390. name: "PBKDF2",
  6391. hash: {
  6392. name: parameters.hmacHashAlgorithm
  6393. },
  6394. salt: saltView,
  6395. iterations: parameters.iterationCount
  6396. }, pbkdfKey, parameters.contentEncryptionAlgorithm, false, ["encrypt"]);
  6397. const encryptedData = await this.encrypt({
  6398. name: parameters.contentEncryptionAlgorithm.name,
  6399. iv: ivView
  6400. }, derivedKey, contentView);
  6401. const pbes2Parameters = new PBES2Params({
  6402. keyDerivationFunc: new AlgorithmIdentifier({
  6403. algorithmId: pbkdf2OID,
  6404. algorithmParams: pbkdf2Params.toSchema()
  6405. }),
  6406. encryptionScheme: new AlgorithmIdentifier({
  6407. algorithmId: contentEncryptionOID,
  6408. algorithmParams: new asn1js__namespace.OctetString({ valueHex: ivBuffer })
  6409. })
  6410. });
  6411. return new EncryptedContentInfo({
  6412. contentType: parameters.contentType,
  6413. contentEncryptionAlgorithm: new AlgorithmIdentifier({
  6414. algorithmId: "1.2.840.113549.1.5.13",
  6415. algorithmParams: pbes2Parameters.toSchema()
  6416. }),
  6417. encryptedContent: new asn1js__namespace.OctetString({ valueHex: encryptedData })
  6418. });
  6419. }
  6420. async decryptEncryptedContentInfo(parameters) {
  6421. ParameterError.assert(parameters, "password", "encryptedContentInfo");
  6422. if (parameters.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId !== "1.2.840.113549.1.5.13")
  6423. throw new Error(`Unknown "contentEncryptionAlgorithm": ${parameters.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId}`);
  6424. let pbes2Parameters;
  6425. try {
  6426. pbes2Parameters = new PBES2Params({ schema: parameters.encryptedContentInfo.contentEncryptionAlgorithm.algorithmParams });
  6427. }
  6428. catch {
  6429. throw new Error("Incorrectly encoded \"pbes2Parameters\"");
  6430. }
  6431. let pbkdf2Params;
  6432. try {
  6433. pbkdf2Params = new PBKDF2Params({ schema: pbes2Parameters.keyDerivationFunc.algorithmParams });
  6434. }
  6435. catch {
  6436. throw new Error("Incorrectly encoded \"pbkdf2Params\"");
  6437. }
  6438. const contentEncryptionAlgorithm = this.getAlgorithmByOID(pbes2Parameters.encryptionScheme.algorithmId, true);
  6439. const ivBuffer = pbes2Parameters.encryptionScheme.algorithmParams.valueBlock.valueHex;
  6440. const ivView = new Uint8Array(ivBuffer);
  6441. const saltBuffer = pbkdf2Params.salt.valueBlock.valueHex;
  6442. const saltView = new Uint8Array(saltBuffer);
  6443. const iterationCount = pbkdf2Params.iterationCount;
  6444. let hmacHashAlgorithm = "SHA-1";
  6445. if (pbkdf2Params.prf) {
  6446. const algorithm = this.getAlgorithmByOID(pbkdf2Params.prf.algorithmId, true);
  6447. hmacHashAlgorithm = algorithm.hash.name;
  6448. }
  6449. const pbkdfKey = await this.importKey("raw", parameters.password, "PBKDF2", false, ["deriveKey"]);
  6450. const result = await this.deriveKey({
  6451. name: "PBKDF2",
  6452. hash: {
  6453. name: hmacHashAlgorithm
  6454. },
  6455. salt: saltView,
  6456. iterations: iterationCount
  6457. }, pbkdfKey, contentEncryptionAlgorithm, false, ["decrypt"]);
  6458. const dataBuffer = parameters.encryptedContentInfo.getEncryptedContent();
  6459. return this.decrypt({
  6460. name: contentEncryptionAlgorithm.name,
  6461. iv: ivView
  6462. }, result, dataBuffer);
  6463. }
  6464. async stampDataWithPassword(parameters) {
  6465. if ((parameters instanceof Object) === false)
  6466. throw new Error("Parameters must have type \"Object\"");
  6467. ParameterError.assert(parameters, "password", "hashAlgorithm", "iterationCount", "salt", "contentToStamp");
  6468. let length;
  6469. switch (parameters.hashAlgorithm.toLowerCase()) {
  6470. case "sha-1":
  6471. length = 160;
  6472. break;
  6473. case "sha-256":
  6474. length = 256;
  6475. break;
  6476. case "sha-384":
  6477. length = 384;
  6478. break;
  6479. case "sha-512":
  6480. length = 512;
  6481. break;
  6482. default:
  6483. throw new Error(`Incorrect "parameters.hashAlgorithm" parameter: ${parameters.hashAlgorithm}`);
  6484. }
  6485. const hmacAlgorithm = {
  6486. name: "HMAC",
  6487. length,
  6488. hash: {
  6489. name: parameters.hashAlgorithm
  6490. }
  6491. };
  6492. const pkcsKey = await makePKCS12B2Key(parameters.hashAlgorithm, length, parameters.password, parameters.salt, parameters.iterationCount);
  6493. const hmacKey = await this.importKey("raw", new Uint8Array(pkcsKey), hmacAlgorithm, false, ["sign"]);
  6494. return this.sign(hmacAlgorithm, hmacKey, new Uint8Array(parameters.contentToStamp));
  6495. }
  6496. async verifyDataStampedWithPassword(parameters) {
  6497. ParameterError.assert(parameters, "password", "hashAlgorithm", "salt", "iterationCount", "contentToVerify", "signatureToVerify");
  6498. let length = 0;
  6499. switch (parameters.hashAlgorithm.toLowerCase()) {
  6500. case "sha-1":
  6501. length = 160;
  6502. break;
  6503. case "sha-256":
  6504. length = 256;
  6505. break;
  6506. case "sha-384":
  6507. length = 384;
  6508. break;
  6509. case "sha-512":
  6510. length = 512;
  6511. break;
  6512. default:
  6513. throw new Error(`Incorrect "parameters.hashAlgorithm" parameter: ${parameters.hashAlgorithm}`);
  6514. }
  6515. const hmacAlgorithm = {
  6516. name: "HMAC",
  6517. length,
  6518. hash: {
  6519. name: parameters.hashAlgorithm
  6520. }
  6521. };
  6522. const pkcsKey = await makePKCS12B2Key(parameters.hashAlgorithm, length, parameters.password, parameters.salt, parameters.iterationCount);
  6523. const hmacKey = await this.importKey("raw", new Uint8Array(pkcsKey), hmacAlgorithm, false, ["verify"]);
  6524. return this.verify(hmacAlgorithm, hmacKey, new Uint8Array(parameters.signatureToVerify), new Uint8Array(parameters.contentToVerify));
  6525. }
  6526. async getSignatureParameters(privateKey, hashAlgorithm = "SHA-1") {
  6527. this.getOIDByAlgorithm({ name: hashAlgorithm }, true, "hashAlgorithm");
  6528. const signatureAlgorithm = new AlgorithmIdentifier();
  6529. const parameters = this.getAlgorithmParameters(privateKey.algorithm.name, "sign");
  6530. if (!Object.keys(parameters.algorithm).length) {
  6531. throw new Error("Parameter 'algorithm' is empty");
  6532. }
  6533. const algorithm = parameters.algorithm;
  6534. if ("hash" in privateKey.algorithm && privateKey.algorithm.hash && privateKey.algorithm.hash.name) {
  6535. algorithm.hash.name = privateKey.algorithm.hash.name;
  6536. }
  6537. else {
  6538. algorithm.hash.name = hashAlgorithm;
  6539. }
  6540. switch (privateKey.algorithm.name.toUpperCase()) {
  6541. case "RSASSA-PKCS1-V1_5":
  6542. case "ECDSA":
  6543. signatureAlgorithm.algorithmId = this.getOIDByAlgorithm(algorithm, true);
  6544. break;
  6545. case "RSA-PSS":
  6546. {
  6547. switch (algorithm.hash.name.toUpperCase()) {
  6548. case "SHA-256":
  6549. algorithm.saltLength = 32;
  6550. break;
  6551. case "SHA-384":
  6552. algorithm.saltLength = 48;
  6553. break;
  6554. case "SHA-512":
  6555. algorithm.saltLength = 64;
  6556. break;
  6557. }
  6558. const paramsObject = {};
  6559. if (algorithm.hash.name.toUpperCase() !== "SHA-1") {
  6560. const hashAlgorithmOID = this.getOIDByAlgorithm({ name: algorithm.hash.name }, true, "hashAlgorithm");
  6561. paramsObject.hashAlgorithm = new AlgorithmIdentifier({
  6562. algorithmId: hashAlgorithmOID,
  6563. algorithmParams: new asn1js__namespace.Null()
  6564. });
  6565. paramsObject.maskGenAlgorithm = new AlgorithmIdentifier({
  6566. algorithmId: "1.2.840.113549.1.1.8",
  6567. algorithmParams: paramsObject.hashAlgorithm.toSchema()
  6568. });
  6569. }
  6570. if (algorithm.saltLength !== 20)
  6571. paramsObject.saltLength = algorithm.saltLength;
  6572. const pssParameters = new RSASSAPSSParams(paramsObject);
  6573. signatureAlgorithm.algorithmId = "1.2.840.113549.1.1.10";
  6574. signatureAlgorithm.algorithmParams = pssParameters.toSchema();
  6575. }
  6576. break;
  6577. default:
  6578. throw new Error(`Unsupported signature algorithm: ${privateKey.algorithm.name}`);
  6579. }
  6580. return {
  6581. signatureAlgorithm,
  6582. parameters
  6583. };
  6584. }
  6585. async signWithPrivateKey(data, privateKey, parameters) {
  6586. const signature = await this.sign(parameters.algorithm, privateKey, data);
  6587. if (parameters.algorithm.name === "ECDSA") {
  6588. return createCMSECDSASignature(signature);
  6589. }
  6590. return signature;
  6591. }
  6592. fillPublicKeyParameters(publicKeyInfo, signatureAlgorithm) {
  6593. const parameters = {};
  6594. const shaAlgorithm = this.getHashAlgorithm(signatureAlgorithm);
  6595. if (shaAlgorithm === EMPTY_STRING)
  6596. throw new Error(`Unsupported signature algorithm: ${signatureAlgorithm.algorithmId}`);
  6597. let algorithmId;
  6598. if (signatureAlgorithm.algorithmId === "1.2.840.113549.1.1.10")
  6599. algorithmId = signatureAlgorithm.algorithmId;
  6600. else
  6601. algorithmId = publicKeyInfo.algorithm.algorithmId;
  6602. const algorithmObject = this.getAlgorithmByOID(algorithmId, true);
  6603. parameters.algorithm = this.getAlgorithmParameters(algorithmObject.name, "importKey");
  6604. if ("hash" in parameters.algorithm.algorithm)
  6605. parameters.algorithm.algorithm.hash.name = shaAlgorithm;
  6606. if (algorithmObject.name === "ECDSA") {
  6607. const publicKeyAlgorithm = publicKeyInfo.algorithm;
  6608. if (!publicKeyAlgorithm.algorithmParams) {
  6609. throw new Error("Algorithm parameters for ECDSA public key are missed");
  6610. }
  6611. const publicKeyAlgorithmParams = publicKeyAlgorithm.algorithmParams;
  6612. if ("idBlock" in publicKeyAlgorithm.algorithmParams) {
  6613. if (!((publicKeyAlgorithmParams.idBlock.tagClass === 1) && (publicKeyAlgorithmParams.idBlock.tagNumber === 6))) {
  6614. throw new Error("Incorrect type for ECDSA public key parameters");
  6615. }
  6616. }
  6617. const curveObject = this.getAlgorithmByOID(publicKeyAlgorithmParams.valueBlock.toString(), true);
  6618. parameters.algorithm.algorithm.namedCurve = curveObject.name;
  6619. }
  6620. return parameters;
  6621. }
  6622. async getPublicKey(publicKeyInfo, signatureAlgorithm, parameters) {
  6623. if (!parameters) {
  6624. parameters = this.fillPublicKeyParameters(publicKeyInfo, signatureAlgorithm);
  6625. }
  6626. const publicKeyInfoBuffer = publicKeyInfo.toSchema().toBER(false);
  6627. return this.importKey("spki", publicKeyInfoBuffer, parameters.algorithm.algorithm, true, parameters.algorithm.usages);
  6628. }
  6629. async verifyWithPublicKey(data, signature, publicKeyInfo, signatureAlgorithm, shaAlgorithm) {
  6630. let publicKey;
  6631. if (!shaAlgorithm) {
  6632. shaAlgorithm = this.getHashAlgorithm(signatureAlgorithm);
  6633. if (!shaAlgorithm)
  6634. throw new Error(`Unsupported signature algorithm: ${signatureAlgorithm.algorithmId}`);
  6635. publicKey = await this.getPublicKey(publicKeyInfo, signatureAlgorithm);
  6636. }
  6637. else {
  6638. const parameters = {};
  6639. let algorithmId;
  6640. if (signatureAlgorithm.algorithmId === "1.2.840.113549.1.1.10")
  6641. algorithmId = signatureAlgorithm.algorithmId;
  6642. else
  6643. algorithmId = publicKeyInfo.algorithm.algorithmId;
  6644. const algorithmObject = this.getAlgorithmByOID(algorithmId, true);
  6645. parameters.algorithm = this.getAlgorithmParameters(algorithmObject.name, "importKey");
  6646. if ("hash" in parameters.algorithm.algorithm)
  6647. parameters.algorithm.algorithm.hash.name = shaAlgorithm;
  6648. if (algorithmObject.name === "ECDSA") {
  6649. let algorithmParamsChecked = false;
  6650. if (("algorithmParams" in publicKeyInfo.algorithm) === true) {
  6651. if ("idBlock" in publicKeyInfo.algorithm.algorithmParams) {
  6652. if ((publicKeyInfo.algorithm.algorithmParams.idBlock.tagClass === 1) && (publicKeyInfo.algorithm.algorithmParams.idBlock.tagNumber === 6))
  6653. algorithmParamsChecked = true;
  6654. }
  6655. }
  6656. if (algorithmParamsChecked === false) {
  6657. throw new Error("Incorrect type for ECDSA public key parameters");
  6658. }
  6659. const curveObject = this.getAlgorithmByOID(publicKeyInfo.algorithm.algorithmParams.valueBlock.toString(), true);
  6660. parameters.algorithm.algorithm.namedCurve = curveObject.name;
  6661. }
  6662. publicKey = await this.getPublicKey(publicKeyInfo, null, parameters);
  6663. }
  6664. const algorithm = this.getAlgorithmParameters(publicKey.algorithm.name, "verify");
  6665. if ("hash" in algorithm.algorithm)
  6666. algorithm.algorithm.hash.name = shaAlgorithm;
  6667. let signatureValue = signature.valueBlock.valueHexView;
  6668. if (publicKey.algorithm.name === "ECDSA") {
  6669. const namedCurve = ECNamedCurves.find(publicKey.algorithm.namedCurve);
  6670. if (!namedCurve) {
  6671. throw new Error("Unsupported named curve in use");
  6672. }
  6673. const asn1 = asn1js__namespace.fromBER(signatureValue);
  6674. AsnError.assert(asn1, "Signature value");
  6675. signatureValue = createECDSASignatureFromCMS(asn1.result, namedCurve.size);
  6676. }
  6677. if (publicKey.algorithm.name === "RSA-PSS") {
  6678. const pssParameters = new RSASSAPSSParams({ schema: signatureAlgorithm.algorithmParams });
  6679. if ("saltLength" in pssParameters)
  6680. algorithm.algorithm.saltLength = pssParameters.saltLength;
  6681. else
  6682. algorithm.algorithm.saltLength = 20;
  6683. let hashAlgo = "SHA-1";
  6684. if ("hashAlgorithm" in pssParameters) {
  6685. const hashAlgorithm = this.getAlgorithmByOID(pssParameters.hashAlgorithm.algorithmId, true);
  6686. hashAlgo = hashAlgorithm.name;
  6687. }
  6688. algorithm.algorithm.hash.name = hashAlgo;
  6689. }
  6690. return this.verify(algorithm.algorithm, publicKey, signatureValue, data);
  6691. }
  6692. }
  6693. exports.engine = {
  6694. name: "none",
  6695. crypto: null,
  6696. };
  6697. function isCryptoEngine(engine) {
  6698. return engine
  6699. && typeof engine === "object"
  6700. && "crypto" in engine
  6701. ? true
  6702. : false;
  6703. }
  6704. function setEngine(name, ...args) {
  6705. let crypto = null;
  6706. if (args.length < 2) {
  6707. if (args.length) {
  6708. crypto = args[0];
  6709. }
  6710. else {
  6711. crypto = typeof self !== "undefined" && self.crypto ? new CryptoEngine({ name: "browser", crypto: self.crypto }) : null;
  6712. }
  6713. }
  6714. else {
  6715. const cryptoArg = args[0];
  6716. const subtleArg = args[1];
  6717. if (isCryptoEngine(subtleArg)) {
  6718. crypto = subtleArg;
  6719. }
  6720. else if (isCryptoEngine(cryptoArg)) {
  6721. crypto = cryptoArg;
  6722. }
  6723. else if ("subtle" in cryptoArg && "getRandomValues" in cryptoArg) {
  6724. crypto = new CryptoEngine({
  6725. crypto: cryptoArg,
  6726. });
  6727. }
  6728. }
  6729. if ((typeof process !== "undefined") && ("pid" in process) && (typeof global !== "undefined") && (typeof window === "undefined")) {
  6730. if (typeof global[process.pid] === "undefined") {
  6731. global[process.pid] = {};
  6732. }
  6733. else {
  6734. if (typeof global[process.pid] !== "object") {
  6735. throw new Error(`Name global.${process.pid} already exists and it is not an object`);
  6736. }
  6737. }
  6738. if (typeof global[process.pid].pkijs === "undefined") {
  6739. global[process.pid].pkijs = {};
  6740. }
  6741. else {
  6742. if (typeof global[process.pid].pkijs !== "object") {
  6743. throw new Error(`Name global.${process.pid}.pkijs already exists and it is not an object`);
  6744. }
  6745. }
  6746. global[process.pid].pkijs.engine = {
  6747. name: name,
  6748. crypto,
  6749. };
  6750. }
  6751. else {
  6752. exports.engine = {
  6753. name: name,
  6754. crypto,
  6755. };
  6756. }
  6757. }
  6758. function getEngine() {
  6759. if ((typeof process !== "undefined") && ("pid" in process) && (typeof global !== "undefined") && (typeof window === "undefined")) {
  6760. let _engine;
  6761. try {
  6762. _engine = global[process.pid].pkijs.engine;
  6763. }
  6764. catch {
  6765. throw new Error("Please call 'setEngine' before call to 'getEngine'");
  6766. }
  6767. return _engine;
  6768. }
  6769. return exports.engine;
  6770. }
  6771. function getCrypto(safety = false) {
  6772. const _engine = getEngine();
  6773. if (!_engine.crypto && safety) {
  6774. throw new Error("Unable to create WebCrypto object");
  6775. }
  6776. return _engine.crypto;
  6777. }
  6778. function getRandomValues(view) {
  6779. return getCrypto(true).getRandomValues(view);
  6780. }
  6781. function getOIDByAlgorithm(algorithm, safety, target) {
  6782. return getCrypto(true).getOIDByAlgorithm(algorithm, safety, target);
  6783. }
  6784. function getAlgorithmParameters(algorithmName, operation) {
  6785. return getCrypto(true).getAlgorithmParameters(algorithmName, operation);
  6786. }
  6787. function createCMSECDSASignature(signatureBuffer) {
  6788. if ((signatureBuffer.byteLength % 2) !== 0)
  6789. return EMPTY_BUFFER;
  6790. const length = signatureBuffer.byteLength / 2;
  6791. const rBuffer = new ArrayBuffer(length);
  6792. const rView = new Uint8Array(rBuffer);
  6793. rView.set(new Uint8Array(signatureBuffer, 0, length));
  6794. const rInteger = new asn1js__namespace.Integer({ valueHex: rBuffer });
  6795. const sBuffer = new ArrayBuffer(length);
  6796. const sView = new Uint8Array(sBuffer);
  6797. sView.set(new Uint8Array(signatureBuffer, length, length));
  6798. const sInteger = new asn1js__namespace.Integer({ valueHex: sBuffer });
  6799. return (new asn1js__namespace.Sequence({
  6800. value: [
  6801. rInteger.convertToDER(),
  6802. sInteger.convertToDER()
  6803. ]
  6804. })).toBER(false);
  6805. }
  6806. function createECDSASignatureFromCMS(cmsSignature, pointSize) {
  6807. if (!(cmsSignature instanceof asn1js__namespace.Sequence
  6808. && cmsSignature.valueBlock.value.length === 2
  6809. && cmsSignature.valueBlock.value[0] instanceof asn1js__namespace.Integer
  6810. && cmsSignature.valueBlock.value[1] instanceof asn1js__namespace.Integer))
  6811. return EMPTY_BUFFER;
  6812. const rValueView = cmsSignature.valueBlock.value[0].convertFromDER().valueBlock.valueHexView;
  6813. const sValueView = cmsSignature.valueBlock.value[1].convertFromDER().valueBlock.valueHexView;
  6814. const res = new Uint8Array(pointSize * 2);
  6815. res.set(rValueView, pointSize - rValueView.byteLength);
  6816. res.set(sValueView, (2 * pointSize) - sValueView.byteLength);
  6817. return res.buffer;
  6818. }
  6819. function getAlgorithmByOID(oid, safety = false, target) {
  6820. return getCrypto(true).getAlgorithmByOID(oid, safety, target);
  6821. }
  6822. function getHashAlgorithm(signatureAlgorithm) {
  6823. return getCrypto(true).getHashAlgorithm(signatureAlgorithm);
  6824. }
  6825. async function kdfWithCounter(hashFunction, zBuffer, Counter, SharedInfo, crypto) {
  6826. switch (hashFunction.toUpperCase()) {
  6827. case "SHA-1":
  6828. case "SHA-256":
  6829. case "SHA-384":
  6830. case "SHA-512":
  6831. break;
  6832. default:
  6833. throw new ArgumentError(`Unknown hash function: ${hashFunction}`);
  6834. }
  6835. ArgumentError.assert(zBuffer, "zBuffer", "ArrayBuffer");
  6836. if (zBuffer.byteLength === 0)
  6837. throw new ArgumentError("'zBuffer' has zero length, error");
  6838. ArgumentError.assert(SharedInfo, "SharedInfo", "ArrayBuffer");
  6839. if (Counter > 255)
  6840. throw new ArgumentError("Please set 'Counter' argument to value less or equal to 255");
  6841. const counterBuffer = new ArrayBuffer(4);
  6842. const counterView = new Uint8Array(counterBuffer);
  6843. counterView[0] = 0x00;
  6844. counterView[1] = 0x00;
  6845. counterView[2] = 0x00;
  6846. counterView[3] = Counter;
  6847. let combinedBuffer = EMPTY_BUFFER;
  6848. combinedBuffer = pvutils__namespace.utilConcatBuf(combinedBuffer, zBuffer);
  6849. combinedBuffer = pvutils__namespace.utilConcatBuf(combinedBuffer, counterBuffer);
  6850. combinedBuffer = pvutils__namespace.utilConcatBuf(combinedBuffer, SharedInfo);
  6851. const result = await crypto.digest({ name: hashFunction }, combinedBuffer);
  6852. return {
  6853. counter: Counter,
  6854. result
  6855. };
  6856. }
  6857. async function kdf(hashFunction, Zbuffer, keydatalen, SharedInfo, crypto = getCrypto(true)) {
  6858. let hashLength = 0;
  6859. let maxCounter = 1;
  6860. switch (hashFunction.toUpperCase()) {
  6861. case "SHA-1":
  6862. hashLength = 160;
  6863. break;
  6864. case "SHA-256":
  6865. hashLength = 256;
  6866. break;
  6867. case "SHA-384":
  6868. hashLength = 384;
  6869. break;
  6870. case "SHA-512":
  6871. hashLength = 512;
  6872. break;
  6873. default:
  6874. throw new ArgumentError(`Unknown hash function: ${hashFunction}`);
  6875. }
  6876. ArgumentError.assert(Zbuffer, "Zbuffer", "ArrayBuffer");
  6877. if (Zbuffer.byteLength === 0)
  6878. throw new ArgumentError("'Zbuffer' has zero length, error");
  6879. ArgumentError.assert(SharedInfo, "SharedInfo", "ArrayBuffer");
  6880. const quotient = keydatalen / hashLength;
  6881. if (Math.floor(quotient) > 0) {
  6882. maxCounter = Math.floor(quotient);
  6883. if ((quotient - maxCounter) > 0)
  6884. maxCounter++;
  6885. }
  6886. const incomingResult = [];
  6887. for (let i = 1; i <= maxCounter; i++)
  6888. incomingResult.push(await kdfWithCounter(hashFunction, Zbuffer, i, SharedInfo, crypto));
  6889. let combinedBuffer = EMPTY_BUFFER;
  6890. let currentCounter = 1;
  6891. let found = true;
  6892. while (found) {
  6893. found = false;
  6894. for (const result of incomingResult) {
  6895. if (result.counter === currentCounter) {
  6896. combinedBuffer = pvutils__namespace.utilConcatBuf(combinedBuffer, result.result);
  6897. found = true;
  6898. break;
  6899. }
  6900. }
  6901. currentCounter++;
  6902. }
  6903. keydatalen >>= 3;
  6904. if (combinedBuffer.byteLength > keydatalen) {
  6905. const newBuffer = new ArrayBuffer(keydatalen);
  6906. const newView = new Uint8Array(newBuffer);
  6907. const combinedView = new Uint8Array(combinedBuffer);
  6908. for (let i = 0; i < keydatalen; i++)
  6909. newView[i] = combinedView[i];
  6910. return newBuffer;
  6911. }
  6912. return combinedBuffer;
  6913. }
  6914. const VERSION$i = "version";
  6915. const LOG_ID = "logID";
  6916. const EXTENSIONS$6 = "extensions";
  6917. const TIMESTAMP = "timestamp";
  6918. const HASH_ALGORITHM$3 = "hashAlgorithm";
  6919. const SIGNATURE_ALGORITHM$8 = "signatureAlgorithm";
  6920. const SIGNATURE$7 = "signature";
  6921. const NONE = "none";
  6922. const MD5 = "md5";
  6923. const SHA1 = "sha1";
  6924. const SHA224 = "sha224";
  6925. const SHA256 = "sha256";
  6926. const SHA384 = "sha384";
  6927. const SHA512 = "sha512";
  6928. const ANONYMOUS = "anonymous";
  6929. const RSA = "rsa";
  6930. const DSA = "dsa";
  6931. const ECDSA = "ecdsa";
  6932. class SignedCertificateTimestamp extends PkiObject {
  6933. constructor(parameters = {}) {
  6934. super();
  6935. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$i, SignedCertificateTimestamp.defaultValues(VERSION$i));
  6936. this.logID = pvutils__namespace.getParametersValue(parameters, LOG_ID, SignedCertificateTimestamp.defaultValues(LOG_ID));
  6937. this.timestamp = pvutils__namespace.getParametersValue(parameters, TIMESTAMP, SignedCertificateTimestamp.defaultValues(TIMESTAMP));
  6938. this.extensions = pvutils__namespace.getParametersValue(parameters, EXTENSIONS$6, SignedCertificateTimestamp.defaultValues(EXTENSIONS$6));
  6939. this.hashAlgorithm = pvutils__namespace.getParametersValue(parameters, HASH_ALGORITHM$3, SignedCertificateTimestamp.defaultValues(HASH_ALGORITHM$3));
  6940. this.signatureAlgorithm = pvutils__namespace.getParametersValue(parameters, SIGNATURE_ALGORITHM$8, SignedCertificateTimestamp.defaultValues(SIGNATURE_ALGORITHM$8));
  6941. this.signature = pvutils__namespace.getParametersValue(parameters, SIGNATURE$7, SignedCertificateTimestamp.defaultValues(SIGNATURE$7));
  6942. if ("stream" in parameters && parameters.stream) {
  6943. this.fromStream(parameters.stream);
  6944. }
  6945. if (parameters.schema) {
  6946. this.fromSchema(parameters.schema);
  6947. }
  6948. }
  6949. static defaultValues(memberName) {
  6950. switch (memberName) {
  6951. case VERSION$i:
  6952. return 0;
  6953. case LOG_ID:
  6954. case EXTENSIONS$6:
  6955. return EMPTY_BUFFER;
  6956. case TIMESTAMP:
  6957. return new Date(0);
  6958. case HASH_ALGORITHM$3:
  6959. case SIGNATURE_ALGORITHM$8:
  6960. return EMPTY_STRING;
  6961. case SIGNATURE$7:
  6962. return EMPTY_BUFFER;
  6963. default:
  6964. return super.defaultValues(memberName);
  6965. }
  6966. }
  6967. fromSchema(schema) {
  6968. if ((schema instanceof asn1js__namespace.RawData) === false)
  6969. throw new Error("Object's schema was not verified against input data for SignedCertificateTimestamp");
  6970. const seqStream = new bs__namespace.SeqStream({
  6971. stream: new bs__namespace.ByteStream({
  6972. buffer: schema.data
  6973. })
  6974. });
  6975. this.fromStream(seqStream);
  6976. }
  6977. fromStream(stream) {
  6978. const blockLength = stream.getUint16();
  6979. this.version = (stream.getBlock(1))[0];
  6980. if (this.version === 0) {
  6981. this.logID = (new Uint8Array(stream.getBlock(32))).buffer.slice(0);
  6982. this.timestamp = new Date(pvutils__namespace.utilFromBase(new Uint8Array(stream.getBlock(8)), 8));
  6983. const extensionsLength = stream.getUint16();
  6984. this.extensions = (new Uint8Array(stream.getBlock(extensionsLength))).buffer.slice(0);
  6985. switch ((stream.getBlock(1))[0]) {
  6986. case 0:
  6987. this.hashAlgorithm = NONE;
  6988. break;
  6989. case 1:
  6990. this.hashAlgorithm = MD5;
  6991. break;
  6992. case 2:
  6993. this.hashAlgorithm = SHA1;
  6994. break;
  6995. case 3:
  6996. this.hashAlgorithm = SHA224;
  6997. break;
  6998. case 4:
  6999. this.hashAlgorithm = SHA256;
  7000. break;
  7001. case 5:
  7002. this.hashAlgorithm = SHA384;
  7003. break;
  7004. case 6:
  7005. this.hashAlgorithm = SHA512;
  7006. break;
  7007. default:
  7008. throw new Error("Object's stream was not correct for SignedCertificateTimestamp");
  7009. }
  7010. switch ((stream.getBlock(1))[0]) {
  7011. case 0:
  7012. this.signatureAlgorithm = ANONYMOUS;
  7013. break;
  7014. case 1:
  7015. this.signatureAlgorithm = RSA;
  7016. break;
  7017. case 2:
  7018. this.signatureAlgorithm = DSA;
  7019. break;
  7020. case 3:
  7021. this.signatureAlgorithm = ECDSA;
  7022. break;
  7023. default:
  7024. throw new Error("Object's stream was not correct for SignedCertificateTimestamp");
  7025. }
  7026. const signatureLength = stream.getUint16();
  7027. this.signature = new Uint8Array(stream.getBlock(signatureLength)).buffer.slice(0);
  7028. if (blockLength !== (47 + extensionsLength + signatureLength)) {
  7029. throw new Error("Object's stream was not correct for SignedCertificateTimestamp");
  7030. }
  7031. }
  7032. }
  7033. toSchema() {
  7034. const stream = this.toStream();
  7035. return new asn1js__namespace.RawData({ data: stream.stream.buffer });
  7036. }
  7037. toStream() {
  7038. const stream = new bs__namespace.SeqStream();
  7039. stream.appendUint16(47 + this.extensions.byteLength + this.signature.byteLength);
  7040. stream.appendChar(this.version);
  7041. stream.appendView(new Uint8Array(this.logID));
  7042. const timeBuffer = new ArrayBuffer(8);
  7043. const timeView = new Uint8Array(timeBuffer);
  7044. const baseArray = pvutils__namespace.utilToBase(this.timestamp.valueOf(), 8);
  7045. timeView.set(new Uint8Array(baseArray), 8 - baseArray.byteLength);
  7046. stream.appendView(timeView);
  7047. stream.appendUint16(this.extensions.byteLength);
  7048. if (this.extensions.byteLength)
  7049. stream.appendView(new Uint8Array(this.extensions));
  7050. let _hashAlgorithm;
  7051. switch (this.hashAlgorithm.toLowerCase()) {
  7052. case NONE:
  7053. _hashAlgorithm = 0;
  7054. break;
  7055. case MD5:
  7056. _hashAlgorithm = 1;
  7057. break;
  7058. case SHA1:
  7059. _hashAlgorithm = 2;
  7060. break;
  7061. case SHA224:
  7062. _hashAlgorithm = 3;
  7063. break;
  7064. case SHA256:
  7065. _hashAlgorithm = 4;
  7066. break;
  7067. case SHA384:
  7068. _hashAlgorithm = 5;
  7069. break;
  7070. case SHA512:
  7071. _hashAlgorithm = 6;
  7072. break;
  7073. default:
  7074. throw new Error(`Incorrect data for hashAlgorithm: ${this.hashAlgorithm}`);
  7075. }
  7076. stream.appendChar(_hashAlgorithm);
  7077. let _signatureAlgorithm;
  7078. switch (this.signatureAlgorithm.toLowerCase()) {
  7079. case ANONYMOUS:
  7080. _signatureAlgorithm = 0;
  7081. break;
  7082. case RSA:
  7083. _signatureAlgorithm = 1;
  7084. break;
  7085. case DSA:
  7086. _signatureAlgorithm = 2;
  7087. break;
  7088. case ECDSA:
  7089. _signatureAlgorithm = 3;
  7090. break;
  7091. default:
  7092. throw new Error(`Incorrect data for signatureAlgorithm: ${this.signatureAlgorithm}`);
  7093. }
  7094. stream.appendChar(_signatureAlgorithm);
  7095. stream.appendUint16(this.signature.byteLength);
  7096. stream.appendView(new Uint8Array(this.signature));
  7097. return stream;
  7098. }
  7099. toJSON() {
  7100. return {
  7101. version: this.version,
  7102. logID: pvutils__namespace.bufferToHexCodes(this.logID),
  7103. timestamp: this.timestamp,
  7104. extensions: pvutils__namespace.bufferToHexCodes(this.extensions),
  7105. hashAlgorithm: this.hashAlgorithm,
  7106. signatureAlgorithm: this.signatureAlgorithm,
  7107. signature: pvutils__namespace.bufferToHexCodes(this.signature),
  7108. };
  7109. }
  7110. async verify(logs, data, dataType = 0, crypto = getCrypto(true)) {
  7111. const logId = pvutils__namespace.toBase64(pvutils__namespace.arrayBufferToString(this.logID));
  7112. let publicKeyBase64 = null;
  7113. const stream = new bs__namespace.SeqStream();
  7114. for (const log of logs) {
  7115. if (log.log_id === logId) {
  7116. publicKeyBase64 = log.key;
  7117. break;
  7118. }
  7119. }
  7120. if (!publicKeyBase64) {
  7121. throw new Error(`Public key not found for CT with logId: ${logId}`);
  7122. }
  7123. const pki = pvutils__namespace.stringToArrayBuffer(pvutils__namespace.fromBase64(publicKeyBase64));
  7124. const publicKeyInfo = PublicKeyInfo.fromBER(pki);
  7125. stream.appendChar(0x00);
  7126. stream.appendChar(0x00);
  7127. const timeBuffer = new ArrayBuffer(8);
  7128. const timeView = new Uint8Array(timeBuffer);
  7129. const baseArray = pvutils__namespace.utilToBase(this.timestamp.valueOf(), 8);
  7130. timeView.set(new Uint8Array(baseArray), 8 - baseArray.byteLength);
  7131. stream.appendView(timeView);
  7132. stream.appendUint16(dataType);
  7133. if (dataType === 0)
  7134. stream.appendUint24(data.byteLength);
  7135. stream.appendView(new Uint8Array(data));
  7136. stream.appendUint16(this.extensions.byteLength);
  7137. if (this.extensions.byteLength !== 0)
  7138. stream.appendView(new Uint8Array(this.extensions));
  7139. return crypto.verifyWithPublicKey(stream.buffer.slice(0, stream.length), new asn1js__namespace.OctetString({ valueHex: this.signature }), publicKeyInfo, { algorithmId: EMPTY_STRING }, "SHA-256");
  7140. }
  7141. }
  7142. SignedCertificateTimestamp.CLASS_NAME = "SignedCertificateTimestamp";
  7143. async function verifySCTsForCertificate(certificate, issuerCertificate, logs, index = (-1), crypto = getCrypto(true)) {
  7144. let parsedValue = null;
  7145. const stream = new bs__namespace.SeqStream();
  7146. if (certificate.extensions) {
  7147. for (let i = certificate.extensions.length - 1; i >= 0; i--) {
  7148. switch (certificate.extensions[i].extnID) {
  7149. case id_SignedCertificateTimestampList:
  7150. {
  7151. parsedValue = certificate.extensions[i].parsedValue;
  7152. if (!parsedValue || parsedValue.timestamps.length === 0)
  7153. throw new Error("Nothing to verify in the certificate");
  7154. certificate.extensions.splice(i, 1);
  7155. }
  7156. break;
  7157. }
  7158. }
  7159. }
  7160. if (parsedValue === null)
  7161. throw new Error("No SignedCertificateTimestampList extension in the specified certificate");
  7162. const tbs = certificate.encodeTBS().toBER();
  7163. const issuerId = await crypto.digest({ name: "SHA-256" }, new Uint8Array(issuerCertificate.subjectPublicKeyInfo.toSchema().toBER(false)));
  7164. stream.appendView(new Uint8Array(issuerId));
  7165. stream.appendUint24(tbs.byteLength);
  7166. stream.appendView(new Uint8Array(tbs));
  7167. const preCert = stream.stream.slice(0, stream.length);
  7168. if (index === (-1)) {
  7169. const verifyArray = [];
  7170. for (const timestamp of parsedValue.timestamps) {
  7171. const verifyResult = await timestamp.verify(logs, preCert.buffer, 1, crypto);
  7172. verifyArray.push(verifyResult);
  7173. }
  7174. return verifyArray;
  7175. }
  7176. if (index >= parsedValue.timestamps.length)
  7177. index = (parsedValue.timestamps.length - 1);
  7178. return [await parsedValue.timestamps[index].verify(logs, preCert.buffer, 1, crypto)];
  7179. }
  7180. const TIMESTAMPS = "timestamps";
  7181. class SignedCertificateTimestampList extends PkiObject {
  7182. constructor(parameters = {}) {
  7183. super();
  7184. this.timestamps = pvutils__namespace.getParametersValue(parameters, TIMESTAMPS, SignedCertificateTimestampList.defaultValues(TIMESTAMPS));
  7185. if (parameters.schema) {
  7186. this.fromSchema(parameters.schema);
  7187. }
  7188. }
  7189. static defaultValues(memberName) {
  7190. switch (memberName) {
  7191. case TIMESTAMPS:
  7192. return [];
  7193. default:
  7194. return super.defaultValues(memberName);
  7195. }
  7196. }
  7197. static compareWithDefault(memberName, memberValue) {
  7198. switch (memberName) {
  7199. case TIMESTAMPS:
  7200. return (memberValue.length === 0);
  7201. default:
  7202. return super.defaultValues(memberName);
  7203. }
  7204. }
  7205. static schema(parameters = {}) {
  7206. var _a;
  7207. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  7208. (_a = names.optional) !== null && _a !== void 0 ? _a : (names.optional = false);
  7209. return (new asn1js__namespace.OctetString({
  7210. name: (names.blockName || "SignedCertificateTimestampList"),
  7211. optional: names.optional
  7212. }));
  7213. }
  7214. fromSchema(schema) {
  7215. if ((schema instanceof asn1js__namespace.OctetString) === false) {
  7216. throw new Error("Object's schema was not verified against input data for SignedCertificateTimestampList");
  7217. }
  7218. const seqStream = new bs__namespace.SeqStream({
  7219. stream: new bs__namespace.ByteStream({
  7220. buffer: schema.valueBlock.valueHex
  7221. })
  7222. });
  7223. const dataLength = seqStream.getUint16();
  7224. if (dataLength !== seqStream.length) {
  7225. throw new Error("Object's schema was not verified against input data for SignedCertificateTimestampList");
  7226. }
  7227. while (seqStream.length) {
  7228. this.timestamps.push(new SignedCertificateTimestamp({ stream: seqStream }));
  7229. }
  7230. }
  7231. toSchema() {
  7232. const stream = new bs__namespace.SeqStream();
  7233. let overallLength = 0;
  7234. const timestampsData = [];
  7235. for (const timestamp of this.timestamps) {
  7236. const timestampStream = timestamp.toStream();
  7237. timestampsData.push(timestampStream);
  7238. overallLength += timestampStream.stream.buffer.byteLength;
  7239. }
  7240. stream.appendUint16(overallLength);
  7241. for (const timestamp of timestampsData) {
  7242. stream.appendView(timestamp.stream.view);
  7243. }
  7244. return new asn1js__namespace.OctetString({ valueHex: stream.stream.buffer.slice(0) });
  7245. }
  7246. toJSON() {
  7247. return {
  7248. timestamps: Array.from(this.timestamps, o => o.toJSON())
  7249. };
  7250. }
  7251. }
  7252. SignedCertificateTimestampList.CLASS_NAME = "SignedCertificateTimestampList";
  7253. const ATTRIBUTES$4 = "attributes";
  7254. const CLEAR_PROPS$11 = [
  7255. ATTRIBUTES$4
  7256. ];
  7257. class SubjectDirectoryAttributes extends PkiObject {
  7258. constructor(parameters = {}) {
  7259. super();
  7260. this.attributes = pvutils__namespace.getParametersValue(parameters, ATTRIBUTES$4, SubjectDirectoryAttributes.defaultValues(ATTRIBUTES$4));
  7261. if (parameters.schema) {
  7262. this.fromSchema(parameters.schema);
  7263. }
  7264. }
  7265. static defaultValues(memberName) {
  7266. switch (memberName) {
  7267. case ATTRIBUTES$4:
  7268. return [];
  7269. default:
  7270. return super.defaultValues(memberName);
  7271. }
  7272. }
  7273. static schema(parameters = {}) {
  7274. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  7275. return (new asn1js__namespace.Sequence({
  7276. name: (names.blockName || EMPTY_STRING),
  7277. value: [
  7278. new asn1js__namespace.Repeated({
  7279. name: (names.attributes || EMPTY_STRING),
  7280. value: Attribute.schema()
  7281. })
  7282. ]
  7283. }));
  7284. }
  7285. fromSchema(schema) {
  7286. pvutils__namespace.clearProps(schema, CLEAR_PROPS$11);
  7287. const asn1 = asn1js__namespace.compareSchema(schema, schema, SubjectDirectoryAttributes.schema({
  7288. names: {
  7289. attributes: ATTRIBUTES$4
  7290. }
  7291. }));
  7292. AsnError.assertSchema(asn1, this.className);
  7293. this.attributes = Array.from(asn1.result.attributes, element => new Attribute({ schema: element }));
  7294. }
  7295. toSchema() {
  7296. return (new asn1js__namespace.Sequence({
  7297. value: Array.from(this.attributes, o => o.toSchema())
  7298. }));
  7299. }
  7300. toJSON() {
  7301. return {
  7302. attributes: Array.from(this.attributes, o => o.toJSON())
  7303. };
  7304. }
  7305. }
  7306. SubjectDirectoryAttributes.CLASS_NAME = "SubjectDirectoryAttributes";
  7307. class ExtensionValueFactory {
  7308. static getItems() {
  7309. if (!this.types) {
  7310. this.types = {};
  7311. ExtensionValueFactory.register(id_SubjectAltName, "SubjectAltName", AltName);
  7312. ExtensionValueFactory.register(id_IssuerAltName, "IssuerAltName", AltName);
  7313. ExtensionValueFactory.register(id_AuthorityKeyIdentifier, "AuthorityKeyIdentifier", AuthorityKeyIdentifier);
  7314. ExtensionValueFactory.register(id_BasicConstraints, "BasicConstraints", BasicConstraints);
  7315. ExtensionValueFactory.register(id_MicrosoftCaVersion, "MicrosoftCaVersion", CAVersion);
  7316. ExtensionValueFactory.register(id_CertificatePolicies, "CertificatePolicies", CertificatePolicies);
  7317. ExtensionValueFactory.register(id_MicrosoftAppPolicies, "CertificatePoliciesMicrosoft", CertificatePolicies);
  7318. ExtensionValueFactory.register(id_MicrosoftCertTemplateV2, "MicrosoftCertTemplateV2", CertificateTemplate);
  7319. ExtensionValueFactory.register(id_CRLDistributionPoints, "CRLDistributionPoints", CRLDistributionPoints);
  7320. ExtensionValueFactory.register(id_FreshestCRL, "FreshestCRL", CRLDistributionPoints);
  7321. ExtensionValueFactory.register(id_ExtKeyUsage, "ExtKeyUsage", ExtKeyUsage);
  7322. ExtensionValueFactory.register(id_CertificateIssuer, "CertificateIssuer", GeneralNames);
  7323. ExtensionValueFactory.register(id_AuthorityInfoAccess, "AuthorityInfoAccess", InfoAccess);
  7324. ExtensionValueFactory.register(id_SubjectInfoAccess, "SubjectInfoAccess", InfoAccess);
  7325. ExtensionValueFactory.register(id_IssuingDistributionPoint, "IssuingDistributionPoint", IssuingDistributionPoint);
  7326. ExtensionValueFactory.register(id_NameConstraints, "NameConstraints", NameConstraints);
  7327. ExtensionValueFactory.register(id_PolicyConstraints, "PolicyConstraints", PolicyConstraints);
  7328. ExtensionValueFactory.register(id_PolicyMappings, "PolicyMappings", PolicyMappings);
  7329. ExtensionValueFactory.register(id_PrivateKeyUsagePeriod, "PrivateKeyUsagePeriod", PrivateKeyUsagePeriod);
  7330. ExtensionValueFactory.register(id_QCStatements, "QCStatements", QCStatements);
  7331. ExtensionValueFactory.register(id_SignedCertificateTimestampList, "SignedCertificateTimestampList", SignedCertificateTimestampList);
  7332. ExtensionValueFactory.register(id_SubjectDirectoryAttributes, "SubjectDirectoryAttributes", SubjectDirectoryAttributes);
  7333. }
  7334. return this.types;
  7335. }
  7336. static fromBER(id, raw) {
  7337. const asn1 = asn1js__namespace.fromBER(raw);
  7338. if (asn1.offset === -1) {
  7339. return null;
  7340. }
  7341. const item = this.find(id);
  7342. if (item) {
  7343. try {
  7344. return new item.type({ schema: asn1.result });
  7345. }
  7346. catch {
  7347. const res = new item.type();
  7348. res.parsingError = `Incorrectly formatted value of extension ${item.name} (${id})`;
  7349. return res;
  7350. }
  7351. }
  7352. return asn1.result;
  7353. }
  7354. static find(id) {
  7355. const types = this.getItems();
  7356. return types[id] || null;
  7357. }
  7358. static register(id, name, type) {
  7359. this.getItems()[id] = { name, type };
  7360. }
  7361. }
  7362. const EXTN_ID = "extnID";
  7363. const CRITICAL = "critical";
  7364. const EXTN_VALUE = "extnValue";
  7365. const PARSED_VALUE$5 = "parsedValue";
  7366. const CLEAR_PROPS$10 = [
  7367. EXTN_ID,
  7368. CRITICAL,
  7369. EXTN_VALUE
  7370. ];
  7371. class Extension extends PkiObject {
  7372. get parsedValue() {
  7373. if (this._parsedValue === undefined) {
  7374. const parsedValue = ExtensionValueFactory.fromBER(this.extnID, this.extnValue.valueBlock.valueHexView);
  7375. this._parsedValue = parsedValue;
  7376. }
  7377. return this._parsedValue || undefined;
  7378. }
  7379. set parsedValue(value) {
  7380. this._parsedValue = value;
  7381. }
  7382. constructor(parameters = {}) {
  7383. super();
  7384. this.extnID = pvutils__namespace.getParametersValue(parameters, EXTN_ID, Extension.defaultValues(EXTN_ID));
  7385. this.critical = pvutils__namespace.getParametersValue(parameters, CRITICAL, Extension.defaultValues(CRITICAL));
  7386. if (EXTN_VALUE in parameters) {
  7387. this.extnValue = new asn1js__namespace.OctetString({ valueHex: parameters.extnValue });
  7388. }
  7389. else {
  7390. this.extnValue = Extension.defaultValues(EXTN_VALUE);
  7391. }
  7392. if (PARSED_VALUE$5 in parameters) {
  7393. this.parsedValue = pvutils__namespace.getParametersValue(parameters, PARSED_VALUE$5, Extension.defaultValues(PARSED_VALUE$5));
  7394. }
  7395. if (parameters.schema) {
  7396. this.fromSchema(parameters.schema);
  7397. }
  7398. }
  7399. static defaultValues(memberName) {
  7400. switch (memberName) {
  7401. case EXTN_ID:
  7402. return EMPTY_STRING;
  7403. case CRITICAL:
  7404. return false;
  7405. case EXTN_VALUE:
  7406. return new asn1js__namespace.OctetString();
  7407. case PARSED_VALUE$5:
  7408. return {};
  7409. default:
  7410. return super.defaultValues(memberName);
  7411. }
  7412. }
  7413. static schema(parameters = {}) {
  7414. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  7415. return (new asn1js__namespace.Sequence({
  7416. name: (names.blockName || EMPTY_STRING),
  7417. value: [
  7418. new asn1js__namespace.ObjectIdentifier({ name: (names.extnID || EMPTY_STRING) }),
  7419. new asn1js__namespace.Boolean({
  7420. name: (names.critical || EMPTY_STRING),
  7421. optional: true
  7422. }),
  7423. new asn1js__namespace.OctetString({ name: (names.extnValue || EMPTY_STRING) })
  7424. ]
  7425. }));
  7426. }
  7427. fromSchema(schema) {
  7428. pvutils__namespace.clearProps(schema, CLEAR_PROPS$10);
  7429. const asn1 = asn1js__namespace.compareSchema(schema, schema, Extension.schema({
  7430. names: {
  7431. extnID: EXTN_ID,
  7432. critical: CRITICAL,
  7433. extnValue: EXTN_VALUE
  7434. }
  7435. }));
  7436. AsnError.assertSchema(asn1, this.className);
  7437. this.extnID = asn1.result.extnID.valueBlock.toString();
  7438. if (CRITICAL in asn1.result) {
  7439. this.critical = asn1.result.critical.valueBlock.value;
  7440. }
  7441. this.extnValue = asn1.result.extnValue;
  7442. }
  7443. toSchema() {
  7444. const outputArray = [];
  7445. outputArray.push(new asn1js__namespace.ObjectIdentifier({ value: this.extnID }));
  7446. if (this.critical !== Extension.defaultValues(CRITICAL)) {
  7447. outputArray.push(new asn1js__namespace.Boolean({ value: this.critical }));
  7448. }
  7449. outputArray.push(this.extnValue);
  7450. return (new asn1js__namespace.Sequence({
  7451. value: outputArray
  7452. }));
  7453. }
  7454. toJSON() {
  7455. const object = {
  7456. extnID: this.extnID,
  7457. extnValue: this.extnValue.toJSON(),
  7458. };
  7459. if (this.critical !== Extension.defaultValues(CRITICAL)) {
  7460. object.critical = this.critical;
  7461. }
  7462. if (this.parsedValue && this.parsedValue.toJSON) {
  7463. object.parsedValue = this.parsedValue.toJSON();
  7464. }
  7465. return object;
  7466. }
  7467. }
  7468. Extension.CLASS_NAME = "Extension";
  7469. const EXTENSIONS$5 = "extensions";
  7470. const CLEAR_PROPS$$ = [
  7471. EXTENSIONS$5,
  7472. ];
  7473. class Extensions extends PkiObject {
  7474. constructor(parameters = {}) {
  7475. super();
  7476. this.extensions = pvutils__namespace.getParametersValue(parameters, EXTENSIONS$5, Extensions.defaultValues(EXTENSIONS$5));
  7477. if (parameters.schema) {
  7478. this.fromSchema(parameters.schema);
  7479. }
  7480. }
  7481. static defaultValues(memberName) {
  7482. switch (memberName) {
  7483. case EXTENSIONS$5:
  7484. return [];
  7485. default:
  7486. return super.defaultValues(memberName);
  7487. }
  7488. }
  7489. static schema(parameters = {}, optional = false) {
  7490. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  7491. return (new asn1js__namespace.Sequence({
  7492. optional,
  7493. name: (names.blockName || EMPTY_STRING),
  7494. value: [
  7495. new asn1js__namespace.Repeated({
  7496. name: (names.extensions || EMPTY_STRING),
  7497. value: Extension.schema(names.extension || {})
  7498. })
  7499. ]
  7500. }));
  7501. }
  7502. fromSchema(schema) {
  7503. pvutils__namespace.clearProps(schema, CLEAR_PROPS$$);
  7504. const asn1 = asn1js__namespace.compareSchema(schema, schema, Extensions.schema({
  7505. names: {
  7506. extensions: EXTENSIONS$5
  7507. }
  7508. }));
  7509. AsnError.assertSchema(asn1, this.className);
  7510. this.extensions = Array.from(asn1.result.extensions, element => new Extension({ schema: element }));
  7511. }
  7512. toSchema() {
  7513. return (new asn1js__namespace.Sequence({
  7514. value: Array.from(this.extensions, o => o.toSchema())
  7515. }));
  7516. }
  7517. toJSON() {
  7518. return {
  7519. extensions: this.extensions.map(o => o.toJSON())
  7520. };
  7521. }
  7522. }
  7523. Extensions.CLASS_NAME = "Extensions";
  7524. const ISSUER$5 = "issuer";
  7525. const SERIAL_NUMBER$6 = "serialNumber";
  7526. const ISSUER_UID = "issuerUID";
  7527. const CLEAR_PROPS$_ = [
  7528. ISSUER$5,
  7529. SERIAL_NUMBER$6,
  7530. ISSUER_UID,
  7531. ];
  7532. class IssuerSerial extends PkiObject {
  7533. constructor(parameters = {}) {
  7534. super();
  7535. this.issuer = pvutils__namespace.getParametersValue(parameters, ISSUER$5, IssuerSerial.defaultValues(ISSUER$5));
  7536. this.serialNumber = pvutils__namespace.getParametersValue(parameters, SERIAL_NUMBER$6, IssuerSerial.defaultValues(SERIAL_NUMBER$6));
  7537. if (ISSUER_UID in parameters) {
  7538. this.issuerUID = pvutils__namespace.getParametersValue(parameters, ISSUER_UID, IssuerSerial.defaultValues(ISSUER_UID));
  7539. }
  7540. if (parameters.schema) {
  7541. this.fromSchema(parameters.schema);
  7542. }
  7543. }
  7544. static defaultValues(memberName) {
  7545. switch (memberName) {
  7546. case ISSUER$5:
  7547. return new GeneralNames();
  7548. case SERIAL_NUMBER$6:
  7549. return new asn1js__namespace.Integer();
  7550. case ISSUER_UID:
  7551. return new asn1js__namespace.BitString();
  7552. default:
  7553. return super.defaultValues(memberName);
  7554. }
  7555. }
  7556. static schema(parameters = {}) {
  7557. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  7558. return (new asn1js__namespace.Sequence({
  7559. name: (names.blockName || EMPTY_STRING),
  7560. value: [
  7561. GeneralNames.schema(names.issuer || {}),
  7562. new asn1js__namespace.Integer({ name: (names.serialNumber || EMPTY_STRING) }),
  7563. new asn1js__namespace.BitString({
  7564. optional: true,
  7565. name: (names.issuerUID || EMPTY_STRING)
  7566. })
  7567. ]
  7568. }));
  7569. }
  7570. fromSchema(schema) {
  7571. pvutils__namespace.clearProps(schema, CLEAR_PROPS$_);
  7572. const asn1 = asn1js__namespace.compareSchema(schema, schema, IssuerSerial.schema({
  7573. names: {
  7574. issuer: {
  7575. names: {
  7576. blockName: ISSUER$5
  7577. }
  7578. },
  7579. serialNumber: SERIAL_NUMBER$6,
  7580. issuerUID: ISSUER_UID
  7581. }
  7582. }));
  7583. AsnError.assertSchema(asn1, this.className);
  7584. this.issuer = new GeneralNames({ schema: asn1.result.issuer });
  7585. this.serialNumber = asn1.result.serialNumber;
  7586. if (ISSUER_UID in asn1.result)
  7587. this.issuerUID = asn1.result.issuerUID;
  7588. }
  7589. toSchema() {
  7590. const result = new asn1js__namespace.Sequence({
  7591. value: [
  7592. this.issuer.toSchema(),
  7593. this.serialNumber
  7594. ]
  7595. });
  7596. if (this.issuerUID) {
  7597. result.valueBlock.value.push(this.issuerUID);
  7598. }
  7599. return result;
  7600. }
  7601. toJSON() {
  7602. const result = {
  7603. issuer: this.issuer.toJSON(),
  7604. serialNumber: this.serialNumber.toJSON()
  7605. };
  7606. if (this.issuerUID) {
  7607. result.issuerUID = this.issuerUID.toJSON();
  7608. }
  7609. return result;
  7610. }
  7611. }
  7612. IssuerSerial.CLASS_NAME = "IssuerSerial";
  7613. const VERSION$h = "version";
  7614. const BASE_CERTIFICATE_ID$2 = "baseCertificateID";
  7615. const SUBJECT_NAME = "subjectName";
  7616. const ISSUER$4 = "issuer";
  7617. const SIGNATURE$6 = "signature";
  7618. const SERIAL_NUMBER$5 = "serialNumber";
  7619. const ATTR_CERT_VALIDITY_PERIOD$1 = "attrCertValidityPeriod";
  7620. const ATTRIBUTES$3 = "attributes";
  7621. const ISSUER_UNIQUE_ID$2 = "issuerUniqueID";
  7622. const EXTENSIONS$4 = "extensions";
  7623. const CLEAR_PROPS$Z = [
  7624. VERSION$h,
  7625. BASE_CERTIFICATE_ID$2,
  7626. SUBJECT_NAME,
  7627. ISSUER$4,
  7628. SIGNATURE$6,
  7629. SERIAL_NUMBER$5,
  7630. ATTR_CERT_VALIDITY_PERIOD$1,
  7631. ATTRIBUTES$3,
  7632. ISSUER_UNIQUE_ID$2,
  7633. EXTENSIONS$4,
  7634. ];
  7635. class AttributeCertificateInfoV1 extends PkiObject {
  7636. constructor(parameters = {}) {
  7637. super();
  7638. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$h, AttributeCertificateInfoV1.defaultValues(VERSION$h));
  7639. if (BASE_CERTIFICATE_ID$2 in parameters) {
  7640. this.baseCertificateID = pvutils__namespace.getParametersValue(parameters, BASE_CERTIFICATE_ID$2, AttributeCertificateInfoV1.defaultValues(BASE_CERTIFICATE_ID$2));
  7641. }
  7642. if (SUBJECT_NAME in parameters) {
  7643. this.subjectName = pvutils__namespace.getParametersValue(parameters, SUBJECT_NAME, AttributeCertificateInfoV1.defaultValues(SUBJECT_NAME));
  7644. }
  7645. this.issuer = pvutils__namespace.getParametersValue(parameters, ISSUER$4, AttributeCertificateInfoV1.defaultValues(ISSUER$4));
  7646. this.signature = pvutils__namespace.getParametersValue(parameters, SIGNATURE$6, AttributeCertificateInfoV1.defaultValues(SIGNATURE$6));
  7647. this.serialNumber = pvutils__namespace.getParametersValue(parameters, SERIAL_NUMBER$5, AttributeCertificateInfoV1.defaultValues(SERIAL_NUMBER$5));
  7648. this.attrCertValidityPeriod = pvutils__namespace.getParametersValue(parameters, ATTR_CERT_VALIDITY_PERIOD$1, AttributeCertificateInfoV1.defaultValues(ATTR_CERT_VALIDITY_PERIOD$1));
  7649. this.attributes = pvutils__namespace.getParametersValue(parameters, ATTRIBUTES$3, AttributeCertificateInfoV1.defaultValues(ATTRIBUTES$3));
  7650. if (ISSUER_UNIQUE_ID$2 in parameters)
  7651. this.issuerUniqueID = pvutils__namespace.getParametersValue(parameters, ISSUER_UNIQUE_ID$2, AttributeCertificateInfoV1.defaultValues(ISSUER_UNIQUE_ID$2));
  7652. if (EXTENSIONS$4 in parameters) {
  7653. this.extensions = pvutils__namespace.getParametersValue(parameters, EXTENSIONS$4, AttributeCertificateInfoV1.defaultValues(EXTENSIONS$4));
  7654. }
  7655. if (parameters.schema) {
  7656. this.fromSchema(parameters.schema);
  7657. }
  7658. }
  7659. static defaultValues(memberName) {
  7660. switch (memberName) {
  7661. case VERSION$h:
  7662. return 0;
  7663. case BASE_CERTIFICATE_ID$2:
  7664. return new IssuerSerial();
  7665. case SUBJECT_NAME:
  7666. return new GeneralNames();
  7667. case ISSUER$4:
  7668. return new GeneralNames();
  7669. case SIGNATURE$6:
  7670. return new AlgorithmIdentifier();
  7671. case SERIAL_NUMBER$5:
  7672. return new asn1js__namespace.Integer();
  7673. case ATTR_CERT_VALIDITY_PERIOD$1:
  7674. return new AttCertValidityPeriod();
  7675. case ATTRIBUTES$3:
  7676. return [];
  7677. case ISSUER_UNIQUE_ID$2:
  7678. return new asn1js__namespace.BitString();
  7679. case EXTENSIONS$4:
  7680. return new Extensions();
  7681. default:
  7682. return super.defaultValues(memberName);
  7683. }
  7684. }
  7685. static schema(parameters = {}) {
  7686. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  7687. return (new asn1js__namespace.Sequence({
  7688. name: (names.blockName || EMPTY_STRING),
  7689. value: [
  7690. new asn1js__namespace.Integer({ name: (names.version || EMPTY_STRING) }),
  7691. new asn1js__namespace.Choice({
  7692. value: [
  7693. new asn1js__namespace.Constructed({
  7694. name: (names.baseCertificateID || EMPTY_STRING),
  7695. idBlock: {
  7696. tagClass: 3,
  7697. tagNumber: 0
  7698. },
  7699. value: IssuerSerial.schema().valueBlock.value
  7700. }),
  7701. new asn1js__namespace.Constructed({
  7702. name: (names.subjectName || EMPTY_STRING),
  7703. idBlock: {
  7704. tagClass: 3,
  7705. tagNumber: 1
  7706. },
  7707. value: GeneralNames.schema().valueBlock.value
  7708. }),
  7709. ]
  7710. }),
  7711. GeneralNames.schema({
  7712. names: {
  7713. blockName: (names.issuer || EMPTY_STRING)
  7714. }
  7715. }),
  7716. AlgorithmIdentifier.schema(names.signature || {}),
  7717. new asn1js__namespace.Integer({ name: (names.serialNumber || EMPTY_STRING) }),
  7718. AttCertValidityPeriod.schema(names.attrCertValidityPeriod || {}),
  7719. new asn1js__namespace.Sequence({
  7720. name: (names.attributes || EMPTY_STRING),
  7721. value: [
  7722. new asn1js__namespace.Repeated({
  7723. value: Attribute.schema()
  7724. })
  7725. ]
  7726. }),
  7727. new asn1js__namespace.BitString({
  7728. optional: true,
  7729. name: (names.issuerUniqueID || EMPTY_STRING)
  7730. }),
  7731. Extensions.schema(names.extensions || {}, true)
  7732. ]
  7733. }));
  7734. }
  7735. fromSchema(schema) {
  7736. pvutils__namespace.clearProps(schema, CLEAR_PROPS$Z);
  7737. const asn1 = asn1js__namespace.compareSchema(schema, schema, AttributeCertificateInfoV1.schema({
  7738. names: {
  7739. version: VERSION$h,
  7740. baseCertificateID: BASE_CERTIFICATE_ID$2,
  7741. subjectName: SUBJECT_NAME,
  7742. issuer: ISSUER$4,
  7743. signature: {
  7744. names: {
  7745. blockName: SIGNATURE$6
  7746. }
  7747. },
  7748. serialNumber: SERIAL_NUMBER$5,
  7749. attrCertValidityPeriod: {
  7750. names: {
  7751. blockName: ATTR_CERT_VALIDITY_PERIOD$1
  7752. }
  7753. },
  7754. attributes: ATTRIBUTES$3,
  7755. issuerUniqueID: ISSUER_UNIQUE_ID$2,
  7756. extensions: {
  7757. names: {
  7758. blockName: EXTENSIONS$4
  7759. }
  7760. }
  7761. }
  7762. }));
  7763. AsnError.assertSchema(asn1, this.className);
  7764. this.version = asn1.result.version.valueBlock.valueDec;
  7765. if (BASE_CERTIFICATE_ID$2 in asn1.result) {
  7766. this.baseCertificateID = new IssuerSerial({
  7767. schema: new asn1js__namespace.Sequence({
  7768. value: asn1.result.baseCertificateID.valueBlock.value
  7769. })
  7770. });
  7771. }
  7772. if (SUBJECT_NAME in asn1.result) {
  7773. this.subjectName = new GeneralNames({
  7774. schema: new asn1js__namespace.Sequence({
  7775. value: asn1.result.subjectName.valueBlock.value
  7776. })
  7777. });
  7778. }
  7779. this.issuer = asn1.result.issuer;
  7780. this.signature = new AlgorithmIdentifier({ schema: asn1.result.signature });
  7781. this.serialNumber = asn1.result.serialNumber;
  7782. this.attrCertValidityPeriod = new AttCertValidityPeriod({ schema: asn1.result.attrCertValidityPeriod });
  7783. this.attributes = Array.from(asn1.result.attributes.valueBlock.value, element => new Attribute({ schema: element }));
  7784. if (ISSUER_UNIQUE_ID$2 in asn1.result) {
  7785. this.issuerUniqueID = asn1.result.issuerUniqueID;
  7786. }
  7787. if (EXTENSIONS$4 in asn1.result) {
  7788. this.extensions = new Extensions({ schema: asn1.result.extensions });
  7789. }
  7790. }
  7791. toSchema() {
  7792. const result = new asn1js__namespace.Sequence({
  7793. value: [new asn1js__namespace.Integer({ value: this.version })]
  7794. });
  7795. if (this.baseCertificateID) {
  7796. result.valueBlock.value.push(new asn1js__namespace.Constructed({
  7797. idBlock: {
  7798. tagClass: 3,
  7799. tagNumber: 0
  7800. },
  7801. value: this.baseCertificateID.toSchema().valueBlock.value
  7802. }));
  7803. }
  7804. if (this.subjectName) {
  7805. result.valueBlock.value.push(new asn1js__namespace.Constructed({
  7806. idBlock: {
  7807. tagClass: 3,
  7808. tagNumber: 1
  7809. },
  7810. value: this.subjectName.toSchema().valueBlock.value
  7811. }));
  7812. }
  7813. result.valueBlock.value.push(this.issuer.toSchema());
  7814. result.valueBlock.value.push(this.signature.toSchema());
  7815. result.valueBlock.value.push(this.serialNumber);
  7816. result.valueBlock.value.push(this.attrCertValidityPeriod.toSchema());
  7817. result.valueBlock.value.push(new asn1js__namespace.Sequence({
  7818. value: Array.from(this.attributes, o => o.toSchema())
  7819. }));
  7820. if (this.issuerUniqueID) {
  7821. result.valueBlock.value.push(this.issuerUniqueID);
  7822. }
  7823. if (this.extensions) {
  7824. result.valueBlock.value.push(this.extensions.toSchema());
  7825. }
  7826. return result;
  7827. }
  7828. toJSON() {
  7829. const result = {
  7830. version: this.version
  7831. };
  7832. if (this.baseCertificateID) {
  7833. result.baseCertificateID = this.baseCertificateID.toJSON();
  7834. }
  7835. if (this.subjectName) {
  7836. result.subjectName = this.subjectName.toJSON();
  7837. }
  7838. result.issuer = this.issuer.toJSON();
  7839. result.signature = this.signature.toJSON();
  7840. result.serialNumber = this.serialNumber.toJSON();
  7841. result.attrCertValidityPeriod = this.attrCertValidityPeriod.toJSON();
  7842. result.attributes = Array.from(this.attributes, o => o.toJSON());
  7843. if (this.issuerUniqueID) {
  7844. result.issuerUniqueID = this.issuerUniqueID.toJSON();
  7845. }
  7846. if (this.extensions) {
  7847. result.extensions = this.extensions.toJSON();
  7848. }
  7849. return result;
  7850. }
  7851. }
  7852. AttributeCertificateInfoV1.CLASS_NAME = "AttributeCertificateInfoV1";
  7853. const ACINFO$1 = "acinfo";
  7854. const SIGNATURE_ALGORITHM$7 = "signatureAlgorithm";
  7855. const SIGNATURE_VALUE$4 = "signatureValue";
  7856. const CLEAR_PROPS$Y = [
  7857. ACINFO$1,
  7858. SIGNATURE_VALUE$4,
  7859. SIGNATURE_ALGORITHM$7
  7860. ];
  7861. class AttributeCertificateV1 extends PkiObject {
  7862. constructor(parameters = {}) {
  7863. super();
  7864. this.acinfo = pvutils__namespace.getParametersValue(parameters, ACINFO$1, AttributeCertificateV1.defaultValues(ACINFO$1));
  7865. this.signatureAlgorithm = pvutils__namespace.getParametersValue(parameters, SIGNATURE_ALGORITHM$7, AttributeCertificateV1.defaultValues(SIGNATURE_ALGORITHM$7));
  7866. this.signatureValue = pvutils__namespace.getParametersValue(parameters, SIGNATURE_VALUE$4, AttributeCertificateV1.defaultValues(SIGNATURE_VALUE$4));
  7867. if (parameters.schema) {
  7868. this.fromSchema(parameters.schema);
  7869. }
  7870. }
  7871. static defaultValues(memberName) {
  7872. switch (memberName) {
  7873. case ACINFO$1:
  7874. return new AttributeCertificateInfoV1();
  7875. case SIGNATURE_ALGORITHM$7:
  7876. return new AlgorithmIdentifier();
  7877. case SIGNATURE_VALUE$4:
  7878. return new asn1js__namespace.BitString();
  7879. default:
  7880. return super.defaultValues(memberName);
  7881. }
  7882. }
  7883. static schema(parameters = {}) {
  7884. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  7885. return (new asn1js__namespace.Sequence({
  7886. name: (names.blockName || EMPTY_STRING),
  7887. value: [
  7888. AttributeCertificateInfoV1.schema(names.acinfo || {}),
  7889. AlgorithmIdentifier.schema(names.signatureAlgorithm || {}),
  7890. new asn1js__namespace.BitString({ name: (names.signatureValue || EMPTY_STRING) })
  7891. ]
  7892. }));
  7893. }
  7894. fromSchema(schema) {
  7895. pvutils__namespace.clearProps(schema, CLEAR_PROPS$Y);
  7896. const asn1 = asn1js__namespace.compareSchema(schema, schema, AttributeCertificateV1.schema({
  7897. names: {
  7898. acinfo: {
  7899. names: {
  7900. blockName: ACINFO$1
  7901. }
  7902. },
  7903. signatureAlgorithm: {
  7904. names: {
  7905. blockName: SIGNATURE_ALGORITHM$7
  7906. }
  7907. },
  7908. signatureValue: SIGNATURE_VALUE$4
  7909. }
  7910. }));
  7911. AsnError.assertSchema(asn1, this.className);
  7912. this.acinfo = new AttributeCertificateInfoV1({ schema: asn1.result.acinfo });
  7913. this.signatureAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.signatureAlgorithm });
  7914. this.signatureValue = asn1.result.signatureValue;
  7915. }
  7916. toSchema() {
  7917. return (new asn1js__namespace.Sequence({
  7918. value: [
  7919. this.acinfo.toSchema(),
  7920. this.signatureAlgorithm.toSchema(),
  7921. this.signatureValue
  7922. ]
  7923. }));
  7924. }
  7925. toJSON() {
  7926. return {
  7927. acinfo: this.acinfo.toJSON(),
  7928. signatureAlgorithm: this.signatureAlgorithm.toJSON(),
  7929. signatureValue: this.signatureValue.toJSON(),
  7930. };
  7931. }
  7932. }
  7933. AttributeCertificateV1.CLASS_NAME = "AttributeCertificateV1";
  7934. const DIGESTED_OBJECT_TYPE = "digestedObjectType";
  7935. const OTHER_OBJECT_TYPE_ID = "otherObjectTypeID";
  7936. const DIGEST_ALGORITHM$2 = "digestAlgorithm";
  7937. const OBJECT_DIGEST = "objectDigest";
  7938. const CLEAR_PROPS$X = [
  7939. DIGESTED_OBJECT_TYPE,
  7940. OTHER_OBJECT_TYPE_ID,
  7941. DIGEST_ALGORITHM$2,
  7942. OBJECT_DIGEST,
  7943. ];
  7944. class ObjectDigestInfo extends PkiObject {
  7945. constructor(parameters = {}) {
  7946. super();
  7947. this.digestedObjectType = pvutils__namespace.getParametersValue(parameters, DIGESTED_OBJECT_TYPE, ObjectDigestInfo.defaultValues(DIGESTED_OBJECT_TYPE));
  7948. if (OTHER_OBJECT_TYPE_ID in parameters) {
  7949. this.otherObjectTypeID = pvutils__namespace.getParametersValue(parameters, OTHER_OBJECT_TYPE_ID, ObjectDigestInfo.defaultValues(OTHER_OBJECT_TYPE_ID));
  7950. }
  7951. this.digestAlgorithm = pvutils__namespace.getParametersValue(parameters, DIGEST_ALGORITHM$2, ObjectDigestInfo.defaultValues(DIGEST_ALGORITHM$2));
  7952. this.objectDigest = pvutils__namespace.getParametersValue(parameters, OBJECT_DIGEST, ObjectDigestInfo.defaultValues(OBJECT_DIGEST));
  7953. if (parameters.schema) {
  7954. this.fromSchema(parameters.schema);
  7955. }
  7956. }
  7957. static defaultValues(memberName) {
  7958. switch (memberName) {
  7959. case DIGESTED_OBJECT_TYPE:
  7960. return new asn1js__namespace.Enumerated();
  7961. case OTHER_OBJECT_TYPE_ID:
  7962. return new asn1js__namespace.ObjectIdentifier();
  7963. case DIGEST_ALGORITHM$2:
  7964. return new AlgorithmIdentifier();
  7965. case OBJECT_DIGEST:
  7966. return new asn1js__namespace.BitString();
  7967. default:
  7968. return super.defaultValues(memberName);
  7969. }
  7970. }
  7971. static schema(parameters = {}) {
  7972. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  7973. return (new asn1js__namespace.Sequence({
  7974. name: (names.blockName || EMPTY_STRING),
  7975. value: [
  7976. new asn1js__namespace.Enumerated({ name: (names.digestedObjectType || EMPTY_STRING) }),
  7977. new asn1js__namespace.ObjectIdentifier({
  7978. optional: true,
  7979. name: (names.otherObjectTypeID || EMPTY_STRING)
  7980. }),
  7981. AlgorithmIdentifier.schema(names.digestAlgorithm || {}),
  7982. new asn1js__namespace.BitString({ name: (names.objectDigest || EMPTY_STRING) }),
  7983. ]
  7984. }));
  7985. }
  7986. fromSchema(schema) {
  7987. pvutils__namespace.clearProps(schema, CLEAR_PROPS$X);
  7988. const asn1 = asn1js__namespace.compareSchema(schema, schema, ObjectDigestInfo.schema({
  7989. names: {
  7990. digestedObjectType: DIGESTED_OBJECT_TYPE,
  7991. otherObjectTypeID: OTHER_OBJECT_TYPE_ID,
  7992. digestAlgorithm: {
  7993. names: {
  7994. blockName: DIGEST_ALGORITHM$2
  7995. }
  7996. },
  7997. objectDigest: OBJECT_DIGEST
  7998. }
  7999. }));
  8000. AsnError.assertSchema(asn1, this.className);
  8001. this.digestedObjectType = asn1.result.digestedObjectType;
  8002. if (OTHER_OBJECT_TYPE_ID in asn1.result) {
  8003. this.otherObjectTypeID = asn1.result.otherObjectTypeID;
  8004. }
  8005. this.digestAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.digestAlgorithm });
  8006. this.objectDigest = asn1.result.objectDigest;
  8007. }
  8008. toSchema() {
  8009. const result = new asn1js__namespace.Sequence({
  8010. value: [this.digestedObjectType]
  8011. });
  8012. if (this.otherObjectTypeID) {
  8013. result.valueBlock.value.push(this.otherObjectTypeID);
  8014. }
  8015. result.valueBlock.value.push(this.digestAlgorithm.toSchema());
  8016. result.valueBlock.value.push(this.objectDigest);
  8017. return result;
  8018. }
  8019. toJSON() {
  8020. const result = {
  8021. digestedObjectType: this.digestedObjectType.toJSON(),
  8022. digestAlgorithm: this.digestAlgorithm.toJSON(),
  8023. objectDigest: this.objectDigest.toJSON(),
  8024. };
  8025. if (this.otherObjectTypeID) {
  8026. result.otherObjectTypeID = this.otherObjectTypeID.toJSON();
  8027. }
  8028. return result;
  8029. }
  8030. }
  8031. ObjectDigestInfo.CLASS_NAME = "ObjectDigestInfo";
  8032. const ISSUER_NAME = "issuerName";
  8033. const BASE_CERTIFICATE_ID$1 = "baseCertificateID";
  8034. const OBJECT_DIGEST_INFO$1 = "objectDigestInfo";
  8035. const CLEAR_PROPS$W = [
  8036. ISSUER_NAME,
  8037. BASE_CERTIFICATE_ID$1,
  8038. OBJECT_DIGEST_INFO$1
  8039. ];
  8040. class V2Form extends PkiObject {
  8041. constructor(parameters = {}) {
  8042. super();
  8043. if (ISSUER_NAME in parameters) {
  8044. this.issuerName = pvutils__namespace.getParametersValue(parameters, ISSUER_NAME, V2Form.defaultValues(ISSUER_NAME));
  8045. }
  8046. if (BASE_CERTIFICATE_ID$1 in parameters) {
  8047. this.baseCertificateID = pvutils__namespace.getParametersValue(parameters, BASE_CERTIFICATE_ID$1, V2Form.defaultValues(BASE_CERTIFICATE_ID$1));
  8048. }
  8049. if (OBJECT_DIGEST_INFO$1 in parameters) {
  8050. this.objectDigestInfo = pvutils__namespace.getParametersValue(parameters, OBJECT_DIGEST_INFO$1, V2Form.defaultValues(OBJECT_DIGEST_INFO$1));
  8051. }
  8052. if (parameters.schema) {
  8053. this.fromSchema(parameters.schema);
  8054. }
  8055. }
  8056. static defaultValues(memberName) {
  8057. switch (memberName) {
  8058. case ISSUER_NAME:
  8059. return new GeneralNames();
  8060. case BASE_CERTIFICATE_ID$1:
  8061. return new IssuerSerial();
  8062. case OBJECT_DIGEST_INFO$1:
  8063. return new ObjectDigestInfo();
  8064. default:
  8065. return super.defaultValues(memberName);
  8066. }
  8067. }
  8068. static schema(parameters = {}) {
  8069. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  8070. return (new asn1js__namespace.Sequence({
  8071. name: (names.blockName || EMPTY_STRING),
  8072. value: [
  8073. GeneralNames.schema({
  8074. names: {
  8075. blockName: names.issuerName
  8076. }
  8077. }, true),
  8078. new asn1js__namespace.Constructed({
  8079. optional: true,
  8080. name: (names.baseCertificateID || EMPTY_STRING),
  8081. idBlock: {
  8082. tagClass: 3,
  8083. tagNumber: 0
  8084. },
  8085. value: IssuerSerial.schema().valueBlock.value
  8086. }),
  8087. new asn1js__namespace.Constructed({
  8088. optional: true,
  8089. name: (names.objectDigestInfo || EMPTY_STRING),
  8090. idBlock: {
  8091. tagClass: 3,
  8092. tagNumber: 1
  8093. },
  8094. value: ObjectDigestInfo.schema().valueBlock.value
  8095. })
  8096. ]
  8097. }));
  8098. }
  8099. fromSchema(schema) {
  8100. pvutils__namespace.clearProps(schema, CLEAR_PROPS$W);
  8101. const asn1 = asn1js__namespace.compareSchema(schema, schema, V2Form.schema({
  8102. names: {
  8103. issuerName: ISSUER_NAME,
  8104. baseCertificateID: BASE_CERTIFICATE_ID$1,
  8105. objectDigestInfo: OBJECT_DIGEST_INFO$1
  8106. }
  8107. }));
  8108. AsnError.assertSchema(asn1, this.className);
  8109. if (ISSUER_NAME in asn1.result)
  8110. this.issuerName = new GeneralNames({ schema: asn1.result.issuerName });
  8111. if (BASE_CERTIFICATE_ID$1 in asn1.result) {
  8112. this.baseCertificateID = new IssuerSerial({
  8113. schema: new asn1js__namespace.Sequence({
  8114. value: asn1.result.baseCertificateID.valueBlock.value
  8115. })
  8116. });
  8117. }
  8118. if (OBJECT_DIGEST_INFO$1 in asn1.result) {
  8119. this.objectDigestInfo = new ObjectDigestInfo({
  8120. schema: new asn1js__namespace.Sequence({
  8121. value: asn1.result.objectDigestInfo.valueBlock.value
  8122. })
  8123. });
  8124. }
  8125. }
  8126. toSchema() {
  8127. const result = new asn1js__namespace.Sequence();
  8128. if (this.issuerName)
  8129. result.valueBlock.value.push(this.issuerName.toSchema());
  8130. if (this.baseCertificateID) {
  8131. result.valueBlock.value.push(new asn1js__namespace.Constructed({
  8132. idBlock: {
  8133. tagClass: 3,
  8134. tagNumber: 0
  8135. },
  8136. value: this.baseCertificateID.toSchema().valueBlock.value
  8137. }));
  8138. }
  8139. if (this.objectDigestInfo) {
  8140. result.valueBlock.value.push(new asn1js__namespace.Constructed({
  8141. idBlock: {
  8142. tagClass: 3,
  8143. tagNumber: 1
  8144. },
  8145. value: this.objectDigestInfo.toSchema().valueBlock.value
  8146. }));
  8147. }
  8148. return result;
  8149. }
  8150. toJSON() {
  8151. const result = {};
  8152. if (this.issuerName) {
  8153. result.issuerName = this.issuerName.toJSON();
  8154. }
  8155. if (this.baseCertificateID) {
  8156. result.baseCertificateID = this.baseCertificateID.toJSON();
  8157. }
  8158. if (this.objectDigestInfo) {
  8159. result.objectDigestInfo = this.objectDigestInfo.toJSON();
  8160. }
  8161. return result;
  8162. }
  8163. }
  8164. V2Form.CLASS_NAME = "V2Form";
  8165. const BASE_CERTIFICATE_ID = "baseCertificateID";
  8166. const ENTITY_NAME = "entityName";
  8167. const OBJECT_DIGEST_INFO = "objectDigestInfo";
  8168. const CLEAR_PROPS$V = [
  8169. BASE_CERTIFICATE_ID,
  8170. ENTITY_NAME,
  8171. OBJECT_DIGEST_INFO
  8172. ];
  8173. class Holder extends PkiObject {
  8174. constructor(parameters = {}) {
  8175. super();
  8176. if (BASE_CERTIFICATE_ID in parameters) {
  8177. this.baseCertificateID = pvutils__namespace.getParametersValue(parameters, BASE_CERTIFICATE_ID, Holder.defaultValues(BASE_CERTIFICATE_ID));
  8178. }
  8179. if (ENTITY_NAME in parameters) {
  8180. this.entityName = pvutils__namespace.getParametersValue(parameters, ENTITY_NAME, Holder.defaultValues(ENTITY_NAME));
  8181. }
  8182. if (OBJECT_DIGEST_INFO in parameters) {
  8183. this.objectDigestInfo = pvutils__namespace.getParametersValue(parameters, OBJECT_DIGEST_INFO, Holder.defaultValues(OBJECT_DIGEST_INFO));
  8184. }
  8185. if (parameters.schema) {
  8186. this.fromSchema(parameters.schema);
  8187. }
  8188. }
  8189. static defaultValues(memberName) {
  8190. switch (memberName) {
  8191. case BASE_CERTIFICATE_ID:
  8192. return new IssuerSerial();
  8193. case ENTITY_NAME:
  8194. return new GeneralNames();
  8195. case OBJECT_DIGEST_INFO:
  8196. return new ObjectDigestInfo();
  8197. default:
  8198. return super.defaultValues(memberName);
  8199. }
  8200. }
  8201. static schema(parameters = {}) {
  8202. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  8203. return (new asn1js__namespace.Sequence({
  8204. name: (names.blockName || EMPTY_STRING),
  8205. value: [
  8206. new asn1js__namespace.Constructed({
  8207. optional: true,
  8208. name: (names.baseCertificateID || EMPTY_STRING),
  8209. idBlock: {
  8210. tagClass: 3,
  8211. tagNumber: 0
  8212. },
  8213. value: IssuerSerial.schema().valueBlock.value
  8214. }),
  8215. new asn1js__namespace.Constructed({
  8216. optional: true,
  8217. name: (names.entityName || EMPTY_STRING),
  8218. idBlock: {
  8219. tagClass: 3,
  8220. tagNumber: 1
  8221. },
  8222. value: GeneralNames.schema().valueBlock.value
  8223. }),
  8224. new asn1js__namespace.Constructed({
  8225. optional: true,
  8226. name: (names.objectDigestInfo || EMPTY_STRING),
  8227. idBlock: {
  8228. tagClass: 3,
  8229. tagNumber: 2
  8230. },
  8231. value: ObjectDigestInfo.schema().valueBlock.value
  8232. })
  8233. ]
  8234. }));
  8235. }
  8236. fromSchema(schema) {
  8237. pvutils__namespace.clearProps(schema, CLEAR_PROPS$V);
  8238. const asn1 = asn1js__namespace.compareSchema(schema, schema, Holder.schema({
  8239. names: {
  8240. baseCertificateID: BASE_CERTIFICATE_ID,
  8241. entityName: ENTITY_NAME,
  8242. objectDigestInfo: OBJECT_DIGEST_INFO
  8243. }
  8244. }));
  8245. AsnError.assertSchema(asn1, this.className);
  8246. if (BASE_CERTIFICATE_ID in asn1.result) {
  8247. this.baseCertificateID = new IssuerSerial({
  8248. schema: new asn1js__namespace.Sequence({
  8249. value: asn1.result.baseCertificateID.valueBlock.value
  8250. })
  8251. });
  8252. }
  8253. if (ENTITY_NAME in asn1.result) {
  8254. this.entityName = new GeneralNames({
  8255. schema: new asn1js__namespace.Sequence({
  8256. value: asn1.result.entityName.valueBlock.value
  8257. })
  8258. });
  8259. }
  8260. if (OBJECT_DIGEST_INFO in asn1.result) {
  8261. this.objectDigestInfo = new ObjectDigestInfo({
  8262. schema: new asn1js__namespace.Sequence({
  8263. value: asn1.result.objectDigestInfo.valueBlock.value
  8264. })
  8265. });
  8266. }
  8267. }
  8268. toSchema() {
  8269. const result = new asn1js__namespace.Sequence();
  8270. if (this.baseCertificateID) {
  8271. result.valueBlock.value.push(new asn1js__namespace.Constructed({
  8272. idBlock: {
  8273. tagClass: 3,
  8274. tagNumber: 0
  8275. },
  8276. value: this.baseCertificateID.toSchema().valueBlock.value
  8277. }));
  8278. }
  8279. if (this.entityName) {
  8280. result.valueBlock.value.push(new asn1js__namespace.Constructed({
  8281. idBlock: {
  8282. tagClass: 3,
  8283. tagNumber: 1
  8284. },
  8285. value: this.entityName.toSchema().valueBlock.value
  8286. }));
  8287. }
  8288. if (this.objectDigestInfo) {
  8289. result.valueBlock.value.push(new asn1js__namespace.Constructed({
  8290. idBlock: {
  8291. tagClass: 3,
  8292. tagNumber: 2
  8293. },
  8294. value: this.objectDigestInfo.toSchema().valueBlock.value
  8295. }));
  8296. }
  8297. return result;
  8298. }
  8299. toJSON() {
  8300. const result = {};
  8301. if (this.baseCertificateID) {
  8302. result.baseCertificateID = this.baseCertificateID.toJSON();
  8303. }
  8304. if (this.entityName) {
  8305. result.entityName = this.entityName.toJSON();
  8306. }
  8307. if (this.objectDigestInfo) {
  8308. result.objectDigestInfo = this.objectDigestInfo.toJSON();
  8309. }
  8310. return result;
  8311. }
  8312. }
  8313. Holder.CLASS_NAME = "Holder";
  8314. const VERSION$g = "version";
  8315. const HOLDER = "holder";
  8316. const ISSUER$3 = "issuer";
  8317. const SIGNATURE$5 = "signature";
  8318. const SERIAL_NUMBER$4 = "serialNumber";
  8319. const ATTR_CERT_VALIDITY_PERIOD = "attrCertValidityPeriod";
  8320. const ATTRIBUTES$2 = "attributes";
  8321. const ISSUER_UNIQUE_ID$1 = "issuerUniqueID";
  8322. const EXTENSIONS$3 = "extensions";
  8323. const CLEAR_PROPS$U = [
  8324. VERSION$g,
  8325. HOLDER,
  8326. ISSUER$3,
  8327. SIGNATURE$5,
  8328. SERIAL_NUMBER$4,
  8329. ATTR_CERT_VALIDITY_PERIOD,
  8330. ATTRIBUTES$2,
  8331. ISSUER_UNIQUE_ID$1,
  8332. EXTENSIONS$3
  8333. ];
  8334. class AttributeCertificateInfoV2 extends PkiObject {
  8335. constructor(parameters = {}) {
  8336. super();
  8337. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$g, AttributeCertificateInfoV2.defaultValues(VERSION$g));
  8338. this.holder = pvutils__namespace.getParametersValue(parameters, HOLDER, AttributeCertificateInfoV2.defaultValues(HOLDER));
  8339. this.issuer = pvutils__namespace.getParametersValue(parameters, ISSUER$3, AttributeCertificateInfoV2.defaultValues(ISSUER$3));
  8340. this.signature = pvutils__namespace.getParametersValue(parameters, SIGNATURE$5, AttributeCertificateInfoV2.defaultValues(SIGNATURE$5));
  8341. this.serialNumber = pvutils__namespace.getParametersValue(parameters, SERIAL_NUMBER$4, AttributeCertificateInfoV2.defaultValues(SERIAL_NUMBER$4));
  8342. this.attrCertValidityPeriod = pvutils__namespace.getParametersValue(parameters, ATTR_CERT_VALIDITY_PERIOD, AttributeCertificateInfoV2.defaultValues(ATTR_CERT_VALIDITY_PERIOD));
  8343. this.attributes = pvutils__namespace.getParametersValue(parameters, ATTRIBUTES$2, AttributeCertificateInfoV2.defaultValues(ATTRIBUTES$2));
  8344. if (ISSUER_UNIQUE_ID$1 in parameters) {
  8345. this.issuerUniqueID = pvutils__namespace.getParametersValue(parameters, ISSUER_UNIQUE_ID$1, AttributeCertificateInfoV2.defaultValues(ISSUER_UNIQUE_ID$1));
  8346. }
  8347. if (EXTENSIONS$3 in parameters) {
  8348. this.extensions = pvutils__namespace.getParametersValue(parameters, EXTENSIONS$3, AttributeCertificateInfoV2.defaultValues(EXTENSIONS$3));
  8349. }
  8350. if (parameters.schema) {
  8351. this.fromSchema(parameters.schema);
  8352. }
  8353. }
  8354. static defaultValues(memberName) {
  8355. switch (memberName) {
  8356. case VERSION$g:
  8357. return 1;
  8358. case HOLDER:
  8359. return new Holder();
  8360. case ISSUER$3:
  8361. return {};
  8362. case SIGNATURE$5:
  8363. return new AlgorithmIdentifier();
  8364. case SERIAL_NUMBER$4:
  8365. return new asn1js__namespace.Integer();
  8366. case ATTR_CERT_VALIDITY_PERIOD:
  8367. return new AttCertValidityPeriod();
  8368. case ATTRIBUTES$2:
  8369. return [];
  8370. case ISSUER_UNIQUE_ID$1:
  8371. return new asn1js__namespace.BitString();
  8372. case EXTENSIONS$3:
  8373. return new Extensions();
  8374. default:
  8375. return super.defaultValues(memberName);
  8376. }
  8377. }
  8378. static schema(parameters = {}) {
  8379. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  8380. return (new asn1js__namespace.Sequence({
  8381. name: (names.blockName || EMPTY_STRING),
  8382. value: [
  8383. new asn1js__namespace.Integer({ name: (names.version || EMPTY_STRING) }),
  8384. Holder.schema(names.holder || {}),
  8385. new asn1js__namespace.Choice({
  8386. value: [
  8387. GeneralNames.schema({
  8388. names: {
  8389. blockName: (names.issuer || EMPTY_STRING)
  8390. }
  8391. }),
  8392. new asn1js__namespace.Constructed({
  8393. name: (names.issuer || EMPTY_STRING),
  8394. idBlock: {
  8395. tagClass: 3,
  8396. tagNumber: 0
  8397. },
  8398. value: V2Form.schema().valueBlock.value
  8399. })
  8400. ]
  8401. }),
  8402. AlgorithmIdentifier.schema(names.signature || {}),
  8403. new asn1js__namespace.Integer({ name: (names.serialNumber || EMPTY_STRING) }),
  8404. AttCertValidityPeriod.schema(names.attrCertValidityPeriod || {}),
  8405. new asn1js__namespace.Sequence({
  8406. name: (names.attributes || EMPTY_STRING),
  8407. value: [
  8408. new asn1js__namespace.Repeated({
  8409. value: Attribute.schema()
  8410. })
  8411. ]
  8412. }),
  8413. new asn1js__namespace.BitString({
  8414. optional: true,
  8415. name: (names.issuerUniqueID || EMPTY_STRING)
  8416. }),
  8417. Extensions.schema(names.extensions || {}, true)
  8418. ]
  8419. }));
  8420. }
  8421. fromSchema(schema) {
  8422. pvutils__namespace.clearProps(schema, CLEAR_PROPS$U);
  8423. const asn1 = asn1js__namespace.compareSchema(schema, schema, AttributeCertificateInfoV2.schema({
  8424. names: {
  8425. version: VERSION$g,
  8426. holder: {
  8427. names: {
  8428. blockName: HOLDER
  8429. }
  8430. },
  8431. issuer: ISSUER$3,
  8432. signature: {
  8433. names: {
  8434. blockName: SIGNATURE$5
  8435. }
  8436. },
  8437. serialNumber: SERIAL_NUMBER$4,
  8438. attrCertValidityPeriod: {
  8439. names: {
  8440. blockName: ATTR_CERT_VALIDITY_PERIOD
  8441. }
  8442. },
  8443. attributes: ATTRIBUTES$2,
  8444. issuerUniqueID: ISSUER_UNIQUE_ID$1,
  8445. extensions: {
  8446. names: {
  8447. blockName: EXTENSIONS$3
  8448. }
  8449. }
  8450. }
  8451. }));
  8452. AsnError.assertSchema(asn1, this.className);
  8453. this.version = asn1.result.version.valueBlock.valueDec;
  8454. this.holder = new Holder({ schema: asn1.result.holder });
  8455. switch (asn1.result.issuer.idBlock.tagClass) {
  8456. case 3:
  8457. this.issuer = new V2Form({
  8458. schema: new asn1js__namespace.Sequence({
  8459. value: asn1.result.issuer.valueBlock.value
  8460. })
  8461. });
  8462. break;
  8463. case 1:
  8464. default:
  8465. throw new Error("Incorrect value for 'issuer' in AttributeCertificateInfoV2");
  8466. }
  8467. this.signature = new AlgorithmIdentifier({ schema: asn1.result.signature });
  8468. this.serialNumber = asn1.result.serialNumber;
  8469. this.attrCertValidityPeriod = new AttCertValidityPeriod({ schema: asn1.result.attrCertValidityPeriod });
  8470. this.attributes = Array.from(asn1.result.attributes.valueBlock.value, element => new Attribute({ schema: element }));
  8471. if (ISSUER_UNIQUE_ID$1 in asn1.result) {
  8472. this.issuerUniqueID = asn1.result.issuerUniqueID;
  8473. }
  8474. if (EXTENSIONS$3 in asn1.result) {
  8475. this.extensions = new Extensions({ schema: asn1.result.extensions });
  8476. }
  8477. }
  8478. toSchema() {
  8479. const result = new asn1js__namespace.Sequence({
  8480. value: [
  8481. new asn1js__namespace.Integer({ value: this.version }),
  8482. this.holder.toSchema(),
  8483. new asn1js__namespace.Constructed({
  8484. idBlock: {
  8485. tagClass: 3,
  8486. tagNumber: 0
  8487. },
  8488. value: this.issuer.toSchema().valueBlock.value
  8489. }),
  8490. this.signature.toSchema(),
  8491. this.serialNumber,
  8492. this.attrCertValidityPeriod.toSchema(),
  8493. new asn1js__namespace.Sequence({
  8494. value: Array.from(this.attributes, o => o.toSchema())
  8495. })
  8496. ]
  8497. });
  8498. if (this.issuerUniqueID) {
  8499. result.valueBlock.value.push(this.issuerUniqueID);
  8500. }
  8501. if (this.extensions) {
  8502. result.valueBlock.value.push(this.extensions.toSchema());
  8503. }
  8504. return result;
  8505. }
  8506. toJSON() {
  8507. const result = {
  8508. version: this.version,
  8509. holder: this.holder.toJSON(),
  8510. issuer: this.issuer.toJSON(),
  8511. signature: this.signature.toJSON(),
  8512. serialNumber: this.serialNumber.toJSON(),
  8513. attrCertValidityPeriod: this.attrCertValidityPeriod.toJSON(),
  8514. attributes: Array.from(this.attributes, o => o.toJSON())
  8515. };
  8516. if (this.issuerUniqueID) {
  8517. result.issuerUniqueID = this.issuerUniqueID.toJSON();
  8518. }
  8519. if (this.extensions) {
  8520. result.extensions = this.extensions.toJSON();
  8521. }
  8522. return result;
  8523. }
  8524. }
  8525. AttributeCertificateInfoV2.CLASS_NAME = "AttributeCertificateInfoV2";
  8526. const ACINFO = "acinfo";
  8527. const SIGNATURE_ALGORITHM$6 = "signatureAlgorithm";
  8528. const SIGNATURE_VALUE$3 = "signatureValue";
  8529. const CLEAR_PROPS$T = [
  8530. ACINFO,
  8531. SIGNATURE_ALGORITHM$6,
  8532. SIGNATURE_VALUE$3,
  8533. ];
  8534. class AttributeCertificateV2 extends PkiObject {
  8535. constructor(parameters = {}) {
  8536. super();
  8537. this.acinfo = pvutils__namespace.getParametersValue(parameters, ACINFO, AttributeCertificateV2.defaultValues(ACINFO));
  8538. this.signatureAlgorithm = pvutils__namespace.getParametersValue(parameters, SIGNATURE_ALGORITHM$6, AttributeCertificateV2.defaultValues(SIGNATURE_ALGORITHM$6));
  8539. this.signatureValue = pvutils__namespace.getParametersValue(parameters, SIGNATURE_VALUE$3, AttributeCertificateV2.defaultValues(SIGNATURE_VALUE$3));
  8540. if (parameters.schema) {
  8541. this.fromSchema(parameters.schema);
  8542. }
  8543. }
  8544. static defaultValues(memberName) {
  8545. switch (memberName) {
  8546. case ACINFO:
  8547. return new AttributeCertificateInfoV2();
  8548. case SIGNATURE_ALGORITHM$6:
  8549. return new AlgorithmIdentifier();
  8550. case SIGNATURE_VALUE$3:
  8551. return new asn1js__namespace.BitString();
  8552. default:
  8553. return super.defaultValues(memberName);
  8554. }
  8555. }
  8556. static schema(parameters = {}) {
  8557. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  8558. return (new asn1js__namespace.Sequence({
  8559. name: (names.blockName || EMPTY_STRING),
  8560. value: [
  8561. AttributeCertificateInfoV2.schema(names.acinfo || {}),
  8562. AlgorithmIdentifier.schema(names.signatureAlgorithm || {}),
  8563. new asn1js__namespace.BitString({ name: (names.signatureValue || EMPTY_STRING) })
  8564. ]
  8565. }));
  8566. }
  8567. fromSchema(schema) {
  8568. pvutils__namespace.clearProps(schema, CLEAR_PROPS$T);
  8569. const asn1 = asn1js__namespace.compareSchema(schema, schema, AttributeCertificateV2.schema({
  8570. names: {
  8571. acinfo: {
  8572. names: {
  8573. blockName: ACINFO
  8574. }
  8575. },
  8576. signatureAlgorithm: {
  8577. names: {
  8578. blockName: SIGNATURE_ALGORITHM$6
  8579. }
  8580. },
  8581. signatureValue: SIGNATURE_VALUE$3
  8582. }
  8583. }));
  8584. AsnError.assertSchema(asn1, this.className);
  8585. this.acinfo = new AttributeCertificateInfoV2({ schema: asn1.result.acinfo });
  8586. this.signatureAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.signatureAlgorithm });
  8587. this.signatureValue = asn1.result.signatureValue;
  8588. }
  8589. toSchema() {
  8590. return (new asn1js__namespace.Sequence({
  8591. value: [
  8592. this.acinfo.toSchema(),
  8593. this.signatureAlgorithm.toSchema(),
  8594. this.signatureValue
  8595. ]
  8596. }));
  8597. }
  8598. toJSON() {
  8599. return {
  8600. acinfo: this.acinfo.toJSON(),
  8601. signatureAlgorithm: this.signatureAlgorithm.toJSON(),
  8602. signatureValue: this.signatureValue.toJSON(),
  8603. };
  8604. }
  8605. }
  8606. AttributeCertificateV2.CLASS_NAME = "AttributeCertificateV2";
  8607. const CONTENT_TYPE = "contentType";
  8608. const CONTENT = "content";
  8609. const CLEAR_PROPS$S = [CONTENT_TYPE, CONTENT];
  8610. class ContentInfo extends PkiObject {
  8611. constructor(parameters = {}) {
  8612. super();
  8613. this.contentType = pvutils__namespace.getParametersValue(parameters, CONTENT_TYPE, ContentInfo.defaultValues(CONTENT_TYPE));
  8614. this.content = pvutils__namespace.getParametersValue(parameters, CONTENT, ContentInfo.defaultValues(CONTENT));
  8615. if (parameters.schema) {
  8616. this.fromSchema(parameters.schema);
  8617. }
  8618. }
  8619. static defaultValues(memberName) {
  8620. switch (memberName) {
  8621. case CONTENT_TYPE:
  8622. return EMPTY_STRING;
  8623. case CONTENT:
  8624. return new asn1js__namespace.Any();
  8625. default:
  8626. return super.defaultValues(memberName);
  8627. }
  8628. }
  8629. static compareWithDefault(memberName, memberValue) {
  8630. switch (memberName) {
  8631. case CONTENT_TYPE:
  8632. return (typeof memberValue === "string" &&
  8633. memberValue === this.defaultValues(CONTENT_TYPE));
  8634. case CONTENT:
  8635. return (memberValue instanceof asn1js__namespace.Any);
  8636. default:
  8637. return super.defaultValues(memberName);
  8638. }
  8639. }
  8640. static schema(parameters = {}) {
  8641. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  8642. if (("optional" in names) === false) {
  8643. names.optional = false;
  8644. }
  8645. return (new asn1js__namespace.Sequence({
  8646. name: (names.blockName || "ContentInfo"),
  8647. optional: names.optional,
  8648. value: [
  8649. new asn1js__namespace.ObjectIdentifier({ name: (names.contentType || CONTENT_TYPE) }),
  8650. new asn1js__namespace.Constructed({
  8651. idBlock: {
  8652. tagClass: 3,
  8653. tagNumber: 0
  8654. },
  8655. value: [new asn1js__namespace.Any({ name: (names.content || CONTENT) })]
  8656. })
  8657. ]
  8658. }));
  8659. }
  8660. fromSchema(schema) {
  8661. pvutils__namespace.clearProps(schema, CLEAR_PROPS$S);
  8662. const asn1 = asn1js__namespace.compareSchema(schema, schema, ContentInfo.schema());
  8663. AsnError.assertSchema(asn1, this.className);
  8664. this.contentType = asn1.result.contentType.valueBlock.toString();
  8665. this.content = asn1.result.content;
  8666. }
  8667. toSchema() {
  8668. return (new asn1js__namespace.Sequence({
  8669. value: [
  8670. new asn1js__namespace.ObjectIdentifier({ value: this.contentType }),
  8671. new asn1js__namespace.Constructed({
  8672. idBlock: {
  8673. tagClass: 3,
  8674. tagNumber: 0
  8675. },
  8676. value: [this.content]
  8677. })
  8678. ]
  8679. }));
  8680. }
  8681. toJSON() {
  8682. const object = {
  8683. contentType: this.contentType
  8684. };
  8685. if (!(this.content instanceof asn1js__namespace.Any)) {
  8686. object.content = this.content.toJSON();
  8687. }
  8688. return object;
  8689. }
  8690. }
  8691. ContentInfo.CLASS_NAME = "ContentInfo";
  8692. ContentInfo.DATA = id_ContentType_Data;
  8693. ContentInfo.SIGNED_DATA = id_ContentType_SignedData;
  8694. ContentInfo.ENVELOPED_DATA = id_ContentType_EnvelopedData;
  8695. ContentInfo.ENCRYPTED_DATA = id_ContentType_EncryptedData;
  8696. const TYPE$1 = "type";
  8697. const VALUE$4 = "value";
  8698. const UTC_TIME_NAME = "utcTimeName";
  8699. const GENERAL_TIME_NAME = "generalTimeName";
  8700. const CLEAR_PROPS$R = [UTC_TIME_NAME, GENERAL_TIME_NAME];
  8701. exports.TimeType = void 0;
  8702. (function (TimeType) {
  8703. TimeType[TimeType["UTCTime"] = 0] = "UTCTime";
  8704. TimeType[TimeType["GeneralizedTime"] = 1] = "GeneralizedTime";
  8705. TimeType[TimeType["empty"] = 2] = "empty";
  8706. })(exports.TimeType || (exports.TimeType = {}));
  8707. class Time extends PkiObject {
  8708. constructor(parameters = {}) {
  8709. super();
  8710. this.type = pvutils__namespace.getParametersValue(parameters, TYPE$1, Time.defaultValues(TYPE$1));
  8711. this.value = pvutils__namespace.getParametersValue(parameters, VALUE$4, Time.defaultValues(VALUE$4));
  8712. if (parameters.schema) {
  8713. this.fromSchema(parameters.schema);
  8714. }
  8715. }
  8716. static defaultValues(memberName) {
  8717. switch (memberName) {
  8718. case TYPE$1:
  8719. return 0;
  8720. case VALUE$4:
  8721. return new Date(0, 0, 0);
  8722. default:
  8723. return super.defaultValues(memberName);
  8724. }
  8725. }
  8726. static schema(parameters = {}, optional = false) {
  8727. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  8728. return (new asn1js__namespace.Choice({
  8729. optional,
  8730. value: [
  8731. new asn1js__namespace.UTCTime({ name: (names.utcTimeName || EMPTY_STRING) }),
  8732. new asn1js__namespace.GeneralizedTime({ name: (names.generalTimeName || EMPTY_STRING) })
  8733. ]
  8734. }));
  8735. }
  8736. fromSchema(schema) {
  8737. pvutils__namespace.clearProps(schema, CLEAR_PROPS$R);
  8738. const asn1 = asn1js__namespace.compareSchema(schema, schema, Time.schema({
  8739. names: {
  8740. utcTimeName: UTC_TIME_NAME,
  8741. generalTimeName: GENERAL_TIME_NAME
  8742. }
  8743. }));
  8744. AsnError.assertSchema(asn1, this.className);
  8745. if (UTC_TIME_NAME in asn1.result) {
  8746. this.type = 0;
  8747. this.value = asn1.result.utcTimeName.toDate();
  8748. }
  8749. if (GENERAL_TIME_NAME in asn1.result) {
  8750. this.type = 1;
  8751. this.value = asn1.result.generalTimeName.toDate();
  8752. }
  8753. }
  8754. toSchema() {
  8755. if (this.type === 0) {
  8756. return new asn1js__namespace.UTCTime({ valueDate: this.value });
  8757. }
  8758. else if (this.type === 1) {
  8759. return new asn1js__namespace.GeneralizedTime({ valueDate: this.value });
  8760. }
  8761. return {};
  8762. }
  8763. toJSON() {
  8764. return {
  8765. type: this.type,
  8766. value: this.value
  8767. };
  8768. }
  8769. }
  8770. Time.CLASS_NAME = "Time";
  8771. const TBS$4 = "tbs";
  8772. const VERSION$f = "version";
  8773. const SERIAL_NUMBER$3 = "serialNumber";
  8774. const SIGNATURE$4 = "signature";
  8775. const ISSUER$2 = "issuer";
  8776. const NOT_BEFORE = "notBefore";
  8777. const NOT_AFTER = "notAfter";
  8778. const SUBJECT$1 = "subject";
  8779. const SUBJECT_PUBLIC_KEY_INFO = "subjectPublicKeyInfo";
  8780. const ISSUER_UNIQUE_ID = "issuerUniqueID";
  8781. const SUBJECT_UNIQUE_ID = "subjectUniqueID";
  8782. const EXTENSIONS$2 = "extensions";
  8783. const SIGNATURE_ALGORITHM$5 = "signatureAlgorithm";
  8784. const SIGNATURE_VALUE$2 = "signatureValue";
  8785. const TBS_CERTIFICATE = "tbsCertificate";
  8786. const TBS_CERTIFICATE_VERSION = `${TBS_CERTIFICATE}.${VERSION$f}`;
  8787. const TBS_CERTIFICATE_SERIAL_NUMBER = `${TBS_CERTIFICATE}.${SERIAL_NUMBER$3}`;
  8788. const TBS_CERTIFICATE_SIGNATURE = `${TBS_CERTIFICATE}.${SIGNATURE$4}`;
  8789. const TBS_CERTIFICATE_ISSUER = `${TBS_CERTIFICATE}.${ISSUER$2}`;
  8790. const TBS_CERTIFICATE_NOT_BEFORE = `${TBS_CERTIFICATE}.${NOT_BEFORE}`;
  8791. const TBS_CERTIFICATE_NOT_AFTER = `${TBS_CERTIFICATE}.${NOT_AFTER}`;
  8792. const TBS_CERTIFICATE_SUBJECT = `${TBS_CERTIFICATE}.${SUBJECT$1}`;
  8793. const TBS_CERTIFICATE_SUBJECT_PUBLIC_KEY = `${TBS_CERTIFICATE}.${SUBJECT_PUBLIC_KEY_INFO}`;
  8794. const TBS_CERTIFICATE_ISSUER_UNIQUE_ID = `${TBS_CERTIFICATE}.${ISSUER_UNIQUE_ID}`;
  8795. const TBS_CERTIFICATE_SUBJECT_UNIQUE_ID = `${TBS_CERTIFICATE}.${SUBJECT_UNIQUE_ID}`;
  8796. const TBS_CERTIFICATE_EXTENSIONS = `${TBS_CERTIFICATE}.${EXTENSIONS$2}`;
  8797. const CLEAR_PROPS$Q = [
  8798. TBS_CERTIFICATE,
  8799. TBS_CERTIFICATE_VERSION,
  8800. TBS_CERTIFICATE_SERIAL_NUMBER,
  8801. TBS_CERTIFICATE_SIGNATURE,
  8802. TBS_CERTIFICATE_ISSUER,
  8803. TBS_CERTIFICATE_NOT_BEFORE,
  8804. TBS_CERTIFICATE_NOT_AFTER,
  8805. TBS_CERTIFICATE_SUBJECT,
  8806. TBS_CERTIFICATE_SUBJECT_PUBLIC_KEY,
  8807. TBS_CERTIFICATE_ISSUER_UNIQUE_ID,
  8808. TBS_CERTIFICATE_SUBJECT_UNIQUE_ID,
  8809. TBS_CERTIFICATE_EXTENSIONS,
  8810. SIGNATURE_ALGORITHM$5,
  8811. SIGNATURE_VALUE$2
  8812. ];
  8813. function tbsCertificate(parameters = {}) {
  8814. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  8815. return (new asn1js__namespace.Sequence({
  8816. name: (names.blockName || TBS_CERTIFICATE),
  8817. value: [
  8818. new asn1js__namespace.Constructed({
  8819. optional: true,
  8820. idBlock: {
  8821. tagClass: 3,
  8822. tagNumber: 0
  8823. },
  8824. value: [
  8825. new asn1js__namespace.Integer({ name: (names.tbsCertificateVersion || TBS_CERTIFICATE_VERSION) })
  8826. ]
  8827. }),
  8828. new asn1js__namespace.Integer({ name: (names.tbsCertificateSerialNumber || TBS_CERTIFICATE_SERIAL_NUMBER) }),
  8829. AlgorithmIdentifier.schema(names.signature || {
  8830. names: {
  8831. blockName: TBS_CERTIFICATE_SIGNATURE
  8832. }
  8833. }),
  8834. RelativeDistinguishedNames.schema(names.issuer || {
  8835. names: {
  8836. blockName: TBS_CERTIFICATE_ISSUER
  8837. }
  8838. }),
  8839. new asn1js__namespace.Sequence({
  8840. name: (names.tbsCertificateValidity || "tbsCertificate.validity"),
  8841. value: [
  8842. Time.schema(names.notBefore || {
  8843. names: {
  8844. utcTimeName: TBS_CERTIFICATE_NOT_BEFORE,
  8845. generalTimeName: TBS_CERTIFICATE_NOT_BEFORE
  8846. }
  8847. }),
  8848. Time.schema(names.notAfter || {
  8849. names: {
  8850. utcTimeName: TBS_CERTIFICATE_NOT_AFTER,
  8851. generalTimeName: TBS_CERTIFICATE_NOT_AFTER
  8852. }
  8853. })
  8854. ]
  8855. }),
  8856. RelativeDistinguishedNames.schema(names.subject || {
  8857. names: {
  8858. blockName: TBS_CERTIFICATE_SUBJECT
  8859. }
  8860. }),
  8861. PublicKeyInfo.schema(names.subjectPublicKeyInfo || {
  8862. names: {
  8863. blockName: TBS_CERTIFICATE_SUBJECT_PUBLIC_KEY
  8864. }
  8865. }),
  8866. new asn1js__namespace.Primitive({
  8867. name: (names.tbsCertificateIssuerUniqueID || TBS_CERTIFICATE_ISSUER_UNIQUE_ID),
  8868. optional: true,
  8869. idBlock: {
  8870. tagClass: 3,
  8871. tagNumber: 1
  8872. }
  8873. }),
  8874. new asn1js__namespace.Primitive({
  8875. name: (names.tbsCertificateSubjectUniqueID || TBS_CERTIFICATE_SUBJECT_UNIQUE_ID),
  8876. optional: true,
  8877. idBlock: {
  8878. tagClass: 3,
  8879. tagNumber: 2
  8880. }
  8881. }),
  8882. new asn1js__namespace.Constructed({
  8883. optional: true,
  8884. idBlock: {
  8885. tagClass: 3,
  8886. tagNumber: 3
  8887. },
  8888. value: [Extensions.schema(names.extensions || {
  8889. names: {
  8890. blockName: TBS_CERTIFICATE_EXTENSIONS
  8891. }
  8892. })]
  8893. })
  8894. ]
  8895. }));
  8896. }
  8897. class Certificate extends PkiObject {
  8898. get tbs() {
  8899. return pvtsutils__namespace.BufferSourceConverter.toArrayBuffer(this.tbsView);
  8900. }
  8901. set tbs(value) {
  8902. this.tbsView = new Uint8Array(value);
  8903. }
  8904. constructor(parameters = {}) {
  8905. super();
  8906. this.tbsView = new Uint8Array(pvutils__namespace.getParametersValue(parameters, TBS$4, Certificate.defaultValues(TBS$4)));
  8907. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$f, Certificate.defaultValues(VERSION$f));
  8908. this.serialNumber = pvutils__namespace.getParametersValue(parameters, SERIAL_NUMBER$3, Certificate.defaultValues(SERIAL_NUMBER$3));
  8909. this.signature = pvutils__namespace.getParametersValue(parameters, SIGNATURE$4, Certificate.defaultValues(SIGNATURE$4));
  8910. this.issuer = pvutils__namespace.getParametersValue(parameters, ISSUER$2, Certificate.defaultValues(ISSUER$2));
  8911. this.notBefore = pvutils__namespace.getParametersValue(parameters, NOT_BEFORE, Certificate.defaultValues(NOT_BEFORE));
  8912. this.notAfter = pvutils__namespace.getParametersValue(parameters, NOT_AFTER, Certificate.defaultValues(NOT_AFTER));
  8913. this.subject = pvutils__namespace.getParametersValue(parameters, SUBJECT$1, Certificate.defaultValues(SUBJECT$1));
  8914. this.subjectPublicKeyInfo = pvutils__namespace.getParametersValue(parameters, SUBJECT_PUBLIC_KEY_INFO, Certificate.defaultValues(SUBJECT_PUBLIC_KEY_INFO));
  8915. if (ISSUER_UNIQUE_ID in parameters) {
  8916. this.issuerUniqueID = pvutils__namespace.getParametersValue(parameters, ISSUER_UNIQUE_ID, Certificate.defaultValues(ISSUER_UNIQUE_ID));
  8917. }
  8918. if (SUBJECT_UNIQUE_ID in parameters) {
  8919. this.subjectUniqueID = pvutils__namespace.getParametersValue(parameters, SUBJECT_UNIQUE_ID, Certificate.defaultValues(SUBJECT_UNIQUE_ID));
  8920. }
  8921. if (EXTENSIONS$2 in parameters) {
  8922. this.extensions = pvutils__namespace.getParametersValue(parameters, EXTENSIONS$2, Certificate.defaultValues(EXTENSIONS$2));
  8923. }
  8924. this.signatureAlgorithm = pvutils__namespace.getParametersValue(parameters, SIGNATURE_ALGORITHM$5, Certificate.defaultValues(SIGNATURE_ALGORITHM$5));
  8925. this.signatureValue = pvutils__namespace.getParametersValue(parameters, SIGNATURE_VALUE$2, Certificate.defaultValues(SIGNATURE_VALUE$2));
  8926. if (parameters.schema) {
  8927. this.fromSchema(parameters.schema);
  8928. }
  8929. }
  8930. static defaultValues(memberName) {
  8931. switch (memberName) {
  8932. case TBS$4:
  8933. return EMPTY_BUFFER;
  8934. case VERSION$f:
  8935. return 0;
  8936. case SERIAL_NUMBER$3:
  8937. return new asn1js__namespace.Integer();
  8938. case SIGNATURE$4:
  8939. return new AlgorithmIdentifier();
  8940. case ISSUER$2:
  8941. return new RelativeDistinguishedNames();
  8942. case NOT_BEFORE:
  8943. return new Time();
  8944. case NOT_AFTER:
  8945. return new Time();
  8946. case SUBJECT$1:
  8947. return new RelativeDistinguishedNames();
  8948. case SUBJECT_PUBLIC_KEY_INFO:
  8949. return new PublicKeyInfo();
  8950. case ISSUER_UNIQUE_ID:
  8951. return EMPTY_BUFFER;
  8952. case SUBJECT_UNIQUE_ID:
  8953. return EMPTY_BUFFER;
  8954. case EXTENSIONS$2:
  8955. return [];
  8956. case SIGNATURE_ALGORITHM$5:
  8957. return new AlgorithmIdentifier();
  8958. case SIGNATURE_VALUE$2:
  8959. return new asn1js__namespace.BitString();
  8960. default:
  8961. return super.defaultValues(memberName);
  8962. }
  8963. }
  8964. static schema(parameters = {}) {
  8965. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  8966. return (new asn1js__namespace.Sequence({
  8967. name: (names.blockName || EMPTY_STRING),
  8968. value: [
  8969. tbsCertificate(names.tbsCertificate),
  8970. AlgorithmIdentifier.schema(names.signatureAlgorithm || {
  8971. names: {
  8972. blockName: SIGNATURE_ALGORITHM$5
  8973. }
  8974. }),
  8975. new asn1js__namespace.BitString({ name: (names.signatureValue || SIGNATURE_VALUE$2) })
  8976. ]
  8977. }));
  8978. }
  8979. fromSchema(schema) {
  8980. pvutils__namespace.clearProps(schema, CLEAR_PROPS$Q);
  8981. const asn1 = asn1js__namespace.compareSchema(schema, schema, Certificate.schema({
  8982. names: {
  8983. tbsCertificate: {
  8984. names: {
  8985. extensions: {
  8986. names: {
  8987. extensions: TBS_CERTIFICATE_EXTENSIONS
  8988. }
  8989. }
  8990. }
  8991. }
  8992. }
  8993. }));
  8994. AsnError.assertSchema(asn1, this.className);
  8995. this.tbsView = asn1.result.tbsCertificate.valueBeforeDecodeView;
  8996. if (TBS_CERTIFICATE_VERSION in asn1.result)
  8997. this.version = asn1.result[TBS_CERTIFICATE_VERSION].valueBlock.valueDec;
  8998. this.serialNumber = asn1.result[TBS_CERTIFICATE_SERIAL_NUMBER];
  8999. this.signature = new AlgorithmIdentifier({ schema: asn1.result[TBS_CERTIFICATE_SIGNATURE] });
  9000. this.issuer = new RelativeDistinguishedNames({ schema: asn1.result[TBS_CERTIFICATE_ISSUER] });
  9001. this.notBefore = new Time({ schema: asn1.result[TBS_CERTIFICATE_NOT_BEFORE] });
  9002. this.notAfter = new Time({ schema: asn1.result[TBS_CERTIFICATE_NOT_AFTER] });
  9003. this.subject = new RelativeDistinguishedNames({ schema: asn1.result[TBS_CERTIFICATE_SUBJECT] });
  9004. this.subjectPublicKeyInfo = new PublicKeyInfo({ schema: asn1.result[TBS_CERTIFICATE_SUBJECT_PUBLIC_KEY] });
  9005. if (TBS_CERTIFICATE_ISSUER_UNIQUE_ID in asn1.result)
  9006. this.issuerUniqueID = asn1.result[TBS_CERTIFICATE_ISSUER_UNIQUE_ID].valueBlock.valueHex;
  9007. if (TBS_CERTIFICATE_SUBJECT_UNIQUE_ID in asn1.result)
  9008. this.subjectUniqueID = asn1.result[TBS_CERTIFICATE_SUBJECT_UNIQUE_ID].valueBlock.valueHex;
  9009. if (TBS_CERTIFICATE_EXTENSIONS in asn1.result)
  9010. this.extensions = Array.from(asn1.result[TBS_CERTIFICATE_EXTENSIONS], element => new Extension({ schema: element }));
  9011. this.signatureAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.signatureAlgorithm });
  9012. this.signatureValue = asn1.result.signatureValue;
  9013. }
  9014. encodeTBS() {
  9015. const outputArray = [];
  9016. if ((VERSION$f in this) && (this.version !== Certificate.defaultValues(VERSION$f))) {
  9017. outputArray.push(new asn1js__namespace.Constructed({
  9018. optional: true,
  9019. idBlock: {
  9020. tagClass: 3,
  9021. tagNumber: 0
  9022. },
  9023. value: [
  9024. new asn1js__namespace.Integer({ value: this.version })
  9025. ]
  9026. }));
  9027. }
  9028. outputArray.push(this.serialNumber);
  9029. outputArray.push(this.signature.toSchema());
  9030. outputArray.push(this.issuer.toSchema());
  9031. outputArray.push(new asn1js__namespace.Sequence({
  9032. value: [
  9033. this.notBefore.toSchema(),
  9034. this.notAfter.toSchema()
  9035. ]
  9036. }));
  9037. outputArray.push(this.subject.toSchema());
  9038. outputArray.push(this.subjectPublicKeyInfo.toSchema());
  9039. if (this.issuerUniqueID) {
  9040. outputArray.push(new asn1js__namespace.Primitive({
  9041. optional: true,
  9042. idBlock: {
  9043. tagClass: 3,
  9044. tagNumber: 1
  9045. },
  9046. valueHex: this.issuerUniqueID
  9047. }));
  9048. }
  9049. if (this.subjectUniqueID) {
  9050. outputArray.push(new asn1js__namespace.Primitive({
  9051. optional: true,
  9052. idBlock: {
  9053. tagClass: 3,
  9054. tagNumber: 2
  9055. },
  9056. valueHex: this.subjectUniqueID
  9057. }));
  9058. }
  9059. if (this.extensions) {
  9060. outputArray.push(new asn1js__namespace.Constructed({
  9061. optional: true,
  9062. idBlock: {
  9063. tagClass: 3,
  9064. tagNumber: 3
  9065. },
  9066. value: [new asn1js__namespace.Sequence({
  9067. value: Array.from(this.extensions, o => o.toSchema())
  9068. })]
  9069. }));
  9070. }
  9071. return (new asn1js__namespace.Sequence({
  9072. value: outputArray
  9073. }));
  9074. }
  9075. toSchema(encodeFlag = false) {
  9076. let tbsSchema;
  9077. if (encodeFlag === false) {
  9078. if (!this.tbsView.byteLength) {
  9079. return Certificate.schema().value[0];
  9080. }
  9081. const asn1 = asn1js__namespace.fromBER(this.tbsView);
  9082. AsnError.assert(asn1, "TBS Certificate");
  9083. tbsSchema = asn1.result;
  9084. }
  9085. else {
  9086. tbsSchema = this.encodeTBS();
  9087. }
  9088. return (new asn1js__namespace.Sequence({
  9089. value: [
  9090. tbsSchema,
  9091. this.signatureAlgorithm.toSchema(),
  9092. this.signatureValue
  9093. ]
  9094. }));
  9095. }
  9096. toJSON() {
  9097. const res = {
  9098. tbs: pvtsutils__namespace.Convert.ToHex(this.tbsView),
  9099. version: this.version,
  9100. serialNumber: this.serialNumber.toJSON(),
  9101. signature: this.signature.toJSON(),
  9102. issuer: this.issuer.toJSON(),
  9103. notBefore: this.notBefore.toJSON(),
  9104. notAfter: this.notAfter.toJSON(),
  9105. subject: this.subject.toJSON(),
  9106. subjectPublicKeyInfo: this.subjectPublicKeyInfo.toJSON(),
  9107. signatureAlgorithm: this.signatureAlgorithm.toJSON(),
  9108. signatureValue: this.signatureValue.toJSON(),
  9109. };
  9110. if ((VERSION$f in this) && (this.version !== Certificate.defaultValues(VERSION$f))) {
  9111. res.version = this.version;
  9112. }
  9113. if (this.issuerUniqueID) {
  9114. res.issuerUniqueID = pvtsutils__namespace.Convert.ToHex(this.issuerUniqueID);
  9115. }
  9116. if (this.subjectUniqueID) {
  9117. res.subjectUniqueID = pvtsutils__namespace.Convert.ToHex(this.subjectUniqueID);
  9118. }
  9119. if (this.extensions) {
  9120. res.extensions = Array.from(this.extensions, o => o.toJSON());
  9121. }
  9122. return res;
  9123. }
  9124. async getPublicKey(parameters, crypto = getCrypto(true)) {
  9125. return crypto.getPublicKey(this.subjectPublicKeyInfo, this.signatureAlgorithm, parameters);
  9126. }
  9127. async getKeyHash(hashAlgorithm = "SHA-1", crypto = getCrypto(true)) {
  9128. return crypto.digest({ name: hashAlgorithm }, this.subjectPublicKeyInfo.subjectPublicKey.valueBlock.valueHexView);
  9129. }
  9130. async sign(privateKey, hashAlgorithm = "SHA-1", crypto = getCrypto(true)) {
  9131. if (!privateKey) {
  9132. throw new Error("Need to provide a private key for signing");
  9133. }
  9134. const signatureParameters = await crypto.getSignatureParameters(privateKey, hashAlgorithm);
  9135. const parameters = signatureParameters.parameters;
  9136. this.signature = signatureParameters.signatureAlgorithm;
  9137. this.signatureAlgorithm = signatureParameters.signatureAlgorithm;
  9138. this.tbsView = new Uint8Array(this.encodeTBS().toBER());
  9139. const signature = await crypto.signWithPrivateKey(this.tbsView, privateKey, parameters);
  9140. this.signatureValue = new asn1js__namespace.BitString({ valueHex: signature });
  9141. }
  9142. async verify(issuerCertificate, crypto = getCrypto(true)) {
  9143. let subjectPublicKeyInfo;
  9144. if (issuerCertificate) {
  9145. subjectPublicKeyInfo = issuerCertificate.subjectPublicKeyInfo;
  9146. }
  9147. else if (this.issuer.isEqual(this.subject)) {
  9148. subjectPublicKeyInfo = this.subjectPublicKeyInfo;
  9149. }
  9150. if (!(subjectPublicKeyInfo instanceof PublicKeyInfo)) {
  9151. throw new Error("Please provide issuer certificate as a parameter");
  9152. }
  9153. return crypto.verifyWithPublicKey(this.tbsView, this.signatureValue, subjectPublicKeyInfo, this.signatureAlgorithm);
  9154. }
  9155. }
  9156. Certificate.CLASS_NAME = "Certificate";
  9157. function checkCA(cert, signerCert = null) {
  9158. if (signerCert && cert.issuer.isEqual(signerCert.issuer) && cert.serialNumber.isEqual(signerCert.serialNumber)) {
  9159. return null;
  9160. }
  9161. let isCA = false;
  9162. if (cert.extensions) {
  9163. for (const extension of cert.extensions) {
  9164. if (extension.extnID === id_BasicConstraints && extension.parsedValue instanceof BasicConstraints) {
  9165. if (extension.parsedValue.cA) {
  9166. isCA = true;
  9167. break;
  9168. }
  9169. }
  9170. }
  9171. }
  9172. if (isCA) {
  9173. return cert;
  9174. }
  9175. return null;
  9176. }
  9177. const CERT_ID$1 = "certId";
  9178. const CERT_VALUE = "certValue";
  9179. const PARSED_VALUE$4 = "parsedValue";
  9180. const CLEAR_PROPS$P = [
  9181. CERT_ID$1,
  9182. CERT_VALUE
  9183. ];
  9184. class CertBag extends PkiObject {
  9185. constructor(parameters = {}) {
  9186. super();
  9187. this.certId = pvutils__namespace.getParametersValue(parameters, CERT_ID$1, CertBag.defaultValues(CERT_ID$1));
  9188. this.certValue = pvutils__namespace.getParametersValue(parameters, CERT_VALUE, CertBag.defaultValues(CERT_VALUE));
  9189. if (PARSED_VALUE$4 in parameters) {
  9190. this.parsedValue = pvutils__namespace.getParametersValue(parameters, PARSED_VALUE$4, CertBag.defaultValues(PARSED_VALUE$4));
  9191. }
  9192. if (parameters.schema) {
  9193. this.fromSchema(parameters.schema);
  9194. }
  9195. }
  9196. static defaultValues(memberName) {
  9197. switch (memberName) {
  9198. case CERT_ID$1:
  9199. return EMPTY_STRING;
  9200. case CERT_VALUE:
  9201. return (new asn1js__namespace.Any());
  9202. case PARSED_VALUE$4:
  9203. return {};
  9204. default:
  9205. return super.defaultValues(memberName);
  9206. }
  9207. }
  9208. static compareWithDefault(memberName, memberValue) {
  9209. switch (memberName) {
  9210. case CERT_ID$1:
  9211. return (memberValue === EMPTY_STRING);
  9212. case CERT_VALUE:
  9213. return (memberValue instanceof asn1js__namespace.Any);
  9214. case PARSED_VALUE$4:
  9215. return ((memberValue instanceof Object) && (Object.keys(memberValue).length === 0));
  9216. default:
  9217. return super.defaultValues(memberName);
  9218. }
  9219. }
  9220. static schema(parameters = {}) {
  9221. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  9222. return (new asn1js__namespace.Sequence({
  9223. name: (names.blockName || EMPTY_STRING),
  9224. value: [
  9225. new asn1js__namespace.ObjectIdentifier({ name: (names.id || "id") }),
  9226. new asn1js__namespace.Constructed({
  9227. idBlock: {
  9228. tagClass: 3,
  9229. tagNumber: 0
  9230. },
  9231. value: [new asn1js__namespace.Any({ name: (names.value || "value") })]
  9232. })
  9233. ]
  9234. }));
  9235. }
  9236. fromSchema(schema) {
  9237. pvutils__namespace.clearProps(schema, CLEAR_PROPS$P);
  9238. const asn1 = asn1js__namespace.compareSchema(schema, schema, CertBag.schema({
  9239. names: {
  9240. id: CERT_ID$1,
  9241. value: CERT_VALUE
  9242. }
  9243. }));
  9244. AsnError.assertSchema(asn1, this.className);
  9245. this.certId = asn1.result.certId.valueBlock.toString();
  9246. this.certValue = asn1.result.certValue;
  9247. const certValueHex = this.certValue.valueBlock.valueHexView;
  9248. switch (this.certId) {
  9249. case id_CertBag_X509Certificate:
  9250. {
  9251. try {
  9252. this.parsedValue = Certificate.fromBER(certValueHex);
  9253. }
  9254. catch {
  9255. AttributeCertificateV2.fromBER(certValueHex);
  9256. }
  9257. }
  9258. break;
  9259. case id_CertBag_AttributeCertificate:
  9260. {
  9261. this.parsedValue = AttributeCertificateV2.fromBER(certValueHex);
  9262. }
  9263. break;
  9264. case id_CertBag_SDSICertificate:
  9265. default:
  9266. throw new Error(`Incorrect CERT_ID value in CertBag: ${this.certId}`);
  9267. }
  9268. }
  9269. toSchema() {
  9270. if (PARSED_VALUE$4 in this) {
  9271. if ("acinfo" in this.parsedValue) {
  9272. this.certId = id_CertBag_AttributeCertificate;
  9273. }
  9274. else {
  9275. this.certId = id_CertBag_X509Certificate;
  9276. }
  9277. this.certValue = new asn1js__namespace.OctetString({ valueHex: this.parsedValue.toSchema().toBER(false) });
  9278. }
  9279. return (new asn1js__namespace.Sequence({
  9280. value: [
  9281. new asn1js__namespace.ObjectIdentifier({ value: this.certId }),
  9282. new asn1js__namespace.Constructed({
  9283. idBlock: {
  9284. tagClass: 3,
  9285. tagNumber: 0
  9286. },
  9287. value: [(("toSchema" in this.certValue) ? this.certValue.toSchema() : this.certValue)]
  9288. })
  9289. ]
  9290. }));
  9291. }
  9292. toJSON() {
  9293. return {
  9294. certId: this.certId,
  9295. certValue: this.certValue.toJSON()
  9296. };
  9297. }
  9298. }
  9299. CertBag.CLASS_NAME = "CertBag";
  9300. const USER_CERTIFICATE = "userCertificate";
  9301. const REVOCATION_DATE = "revocationDate";
  9302. const CRL_ENTRY_EXTENSIONS = "crlEntryExtensions";
  9303. const CLEAR_PROPS$O = [
  9304. USER_CERTIFICATE,
  9305. REVOCATION_DATE,
  9306. CRL_ENTRY_EXTENSIONS
  9307. ];
  9308. class RevokedCertificate extends PkiObject {
  9309. constructor(parameters = {}) {
  9310. super();
  9311. this.userCertificate = pvutils__namespace.getParametersValue(parameters, USER_CERTIFICATE, RevokedCertificate.defaultValues(USER_CERTIFICATE));
  9312. this.revocationDate = pvutils__namespace.getParametersValue(parameters, REVOCATION_DATE, RevokedCertificate.defaultValues(REVOCATION_DATE));
  9313. if (CRL_ENTRY_EXTENSIONS in parameters) {
  9314. this.crlEntryExtensions = pvutils__namespace.getParametersValue(parameters, CRL_ENTRY_EXTENSIONS, RevokedCertificate.defaultValues(CRL_ENTRY_EXTENSIONS));
  9315. }
  9316. if (parameters.schema) {
  9317. this.fromSchema(parameters.schema);
  9318. }
  9319. }
  9320. static defaultValues(memberName) {
  9321. switch (memberName) {
  9322. case USER_CERTIFICATE:
  9323. return new asn1js__namespace.Integer();
  9324. case REVOCATION_DATE:
  9325. return new Time();
  9326. case CRL_ENTRY_EXTENSIONS:
  9327. return new Extensions();
  9328. default:
  9329. return super.defaultValues(memberName);
  9330. }
  9331. }
  9332. static schema(parameters = {}) {
  9333. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  9334. return new asn1js__namespace.Sequence({
  9335. name: (names.blockName || EMPTY_STRING),
  9336. value: [
  9337. new asn1js__namespace.Integer({ name: (names.userCertificate || USER_CERTIFICATE) }),
  9338. Time.schema({
  9339. names: {
  9340. utcTimeName: (names.revocationDate || REVOCATION_DATE),
  9341. generalTimeName: (names.revocationDate || REVOCATION_DATE)
  9342. }
  9343. }),
  9344. Extensions.schema({
  9345. names: {
  9346. blockName: (names.crlEntryExtensions || CRL_ENTRY_EXTENSIONS)
  9347. }
  9348. }, true)
  9349. ]
  9350. });
  9351. }
  9352. fromSchema(schema) {
  9353. pvutils__namespace.clearProps(schema, CLEAR_PROPS$O);
  9354. const asn1 = asn1js__namespace.compareSchema(schema, schema, RevokedCertificate.schema());
  9355. AsnError.assertSchema(asn1, this.className);
  9356. this.userCertificate = asn1.result.userCertificate;
  9357. this.revocationDate = new Time({ schema: asn1.result.revocationDate });
  9358. if (CRL_ENTRY_EXTENSIONS in asn1.result) {
  9359. this.crlEntryExtensions = new Extensions({ schema: asn1.result.crlEntryExtensions });
  9360. }
  9361. }
  9362. toSchema() {
  9363. const outputArray = [
  9364. this.userCertificate,
  9365. this.revocationDate.toSchema()
  9366. ];
  9367. if (this.crlEntryExtensions) {
  9368. outputArray.push(this.crlEntryExtensions.toSchema());
  9369. }
  9370. return (new asn1js__namespace.Sequence({
  9371. value: outputArray
  9372. }));
  9373. }
  9374. toJSON() {
  9375. const res = {
  9376. userCertificate: this.userCertificate.toJSON(),
  9377. revocationDate: this.revocationDate.toJSON(),
  9378. };
  9379. if (this.crlEntryExtensions) {
  9380. res.crlEntryExtensions = this.crlEntryExtensions.toJSON();
  9381. }
  9382. return res;
  9383. }
  9384. }
  9385. RevokedCertificate.CLASS_NAME = "RevokedCertificate";
  9386. const TBS$3 = "tbs";
  9387. const VERSION$e = "version";
  9388. const SIGNATURE$3 = "signature";
  9389. const ISSUER$1 = "issuer";
  9390. const THIS_UPDATE$1 = "thisUpdate";
  9391. const NEXT_UPDATE$1 = "nextUpdate";
  9392. const REVOKED_CERTIFICATES = "revokedCertificates";
  9393. const CRL_EXTENSIONS = "crlExtensions";
  9394. const SIGNATURE_ALGORITHM$4 = "signatureAlgorithm";
  9395. const SIGNATURE_VALUE$1 = "signatureValue";
  9396. const TBS_CERT_LIST = "tbsCertList";
  9397. const TBS_CERT_LIST_VERSION = `${TBS_CERT_LIST}.version`;
  9398. const TBS_CERT_LIST_SIGNATURE = `${TBS_CERT_LIST}.signature`;
  9399. const TBS_CERT_LIST_ISSUER = `${TBS_CERT_LIST}.issuer`;
  9400. const TBS_CERT_LIST_THIS_UPDATE = `${TBS_CERT_LIST}.thisUpdate`;
  9401. const TBS_CERT_LIST_NEXT_UPDATE = `${TBS_CERT_LIST}.nextUpdate`;
  9402. const TBS_CERT_LIST_REVOKED_CERTIFICATES = `${TBS_CERT_LIST}.revokedCertificates`;
  9403. const TBS_CERT_LIST_EXTENSIONS = `${TBS_CERT_LIST}.extensions`;
  9404. const CLEAR_PROPS$N = [
  9405. TBS_CERT_LIST,
  9406. TBS_CERT_LIST_VERSION,
  9407. TBS_CERT_LIST_SIGNATURE,
  9408. TBS_CERT_LIST_ISSUER,
  9409. TBS_CERT_LIST_THIS_UPDATE,
  9410. TBS_CERT_LIST_NEXT_UPDATE,
  9411. TBS_CERT_LIST_REVOKED_CERTIFICATES,
  9412. TBS_CERT_LIST_EXTENSIONS,
  9413. SIGNATURE_ALGORITHM$4,
  9414. SIGNATURE_VALUE$1
  9415. ];
  9416. function tbsCertList(parameters = {}) {
  9417. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  9418. return (new asn1js__namespace.Sequence({
  9419. name: (names.blockName || TBS_CERT_LIST),
  9420. value: [
  9421. new asn1js__namespace.Integer({
  9422. optional: true,
  9423. name: (names.tbsCertListVersion || TBS_CERT_LIST_VERSION),
  9424. value: 2
  9425. }),
  9426. AlgorithmIdentifier.schema(names.signature || {
  9427. names: {
  9428. blockName: TBS_CERT_LIST_SIGNATURE
  9429. }
  9430. }),
  9431. RelativeDistinguishedNames.schema(names.issuer || {
  9432. names: {
  9433. blockName: TBS_CERT_LIST_ISSUER
  9434. }
  9435. }),
  9436. Time.schema(names.tbsCertListThisUpdate || {
  9437. names: {
  9438. utcTimeName: TBS_CERT_LIST_THIS_UPDATE,
  9439. generalTimeName: TBS_CERT_LIST_THIS_UPDATE
  9440. }
  9441. }),
  9442. Time.schema(names.tbsCertListNextUpdate || {
  9443. names: {
  9444. utcTimeName: TBS_CERT_LIST_NEXT_UPDATE,
  9445. generalTimeName: TBS_CERT_LIST_NEXT_UPDATE
  9446. }
  9447. }, true),
  9448. new asn1js__namespace.Sequence({
  9449. optional: true,
  9450. value: [
  9451. new asn1js__namespace.Repeated({
  9452. name: (names.tbsCertListRevokedCertificates || TBS_CERT_LIST_REVOKED_CERTIFICATES),
  9453. value: new asn1js__namespace.Sequence({
  9454. value: [
  9455. new asn1js__namespace.Integer(),
  9456. Time.schema(),
  9457. Extensions.schema({}, true)
  9458. ]
  9459. })
  9460. })
  9461. ]
  9462. }),
  9463. new asn1js__namespace.Constructed({
  9464. optional: true,
  9465. idBlock: {
  9466. tagClass: 3,
  9467. tagNumber: 0
  9468. },
  9469. value: [Extensions.schema(names.crlExtensions || {
  9470. names: {
  9471. blockName: TBS_CERT_LIST_EXTENSIONS
  9472. }
  9473. })]
  9474. })
  9475. ]
  9476. }));
  9477. }
  9478. const WELL_KNOWN_EXTENSIONS = [
  9479. id_AuthorityKeyIdentifier,
  9480. id_IssuerAltName,
  9481. id_CRLNumber,
  9482. id_BaseCRLNumber,
  9483. id_IssuingDistributionPoint,
  9484. id_FreshestCRL,
  9485. id_AuthorityInfoAccess,
  9486. id_CRLReason,
  9487. id_InvalidityDate,
  9488. id_CertificateIssuer,
  9489. ];
  9490. class CertificateRevocationList extends PkiObject {
  9491. get tbs() {
  9492. return pvtsutils__namespace.BufferSourceConverter.toArrayBuffer(this.tbsView);
  9493. }
  9494. set tbs(value) {
  9495. this.tbsView = new Uint8Array(value);
  9496. }
  9497. constructor(parameters = {}) {
  9498. super();
  9499. this.tbsView = new Uint8Array(pvutils__namespace.getParametersValue(parameters, TBS$3, CertificateRevocationList.defaultValues(TBS$3)));
  9500. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$e, CertificateRevocationList.defaultValues(VERSION$e));
  9501. this.signature = pvutils__namespace.getParametersValue(parameters, SIGNATURE$3, CertificateRevocationList.defaultValues(SIGNATURE$3));
  9502. this.issuer = pvutils__namespace.getParametersValue(parameters, ISSUER$1, CertificateRevocationList.defaultValues(ISSUER$1));
  9503. this.thisUpdate = pvutils__namespace.getParametersValue(parameters, THIS_UPDATE$1, CertificateRevocationList.defaultValues(THIS_UPDATE$1));
  9504. if (NEXT_UPDATE$1 in parameters) {
  9505. this.nextUpdate = pvutils__namespace.getParametersValue(parameters, NEXT_UPDATE$1, CertificateRevocationList.defaultValues(NEXT_UPDATE$1));
  9506. }
  9507. if (REVOKED_CERTIFICATES in parameters) {
  9508. this.revokedCertificates = pvutils__namespace.getParametersValue(parameters, REVOKED_CERTIFICATES, CertificateRevocationList.defaultValues(REVOKED_CERTIFICATES));
  9509. }
  9510. if (CRL_EXTENSIONS in parameters) {
  9511. this.crlExtensions = pvutils__namespace.getParametersValue(parameters, CRL_EXTENSIONS, CertificateRevocationList.defaultValues(CRL_EXTENSIONS));
  9512. }
  9513. this.signatureAlgorithm = pvutils__namespace.getParametersValue(parameters, SIGNATURE_ALGORITHM$4, CertificateRevocationList.defaultValues(SIGNATURE_ALGORITHM$4));
  9514. this.signatureValue = pvutils__namespace.getParametersValue(parameters, SIGNATURE_VALUE$1, CertificateRevocationList.defaultValues(SIGNATURE_VALUE$1));
  9515. if (parameters.schema) {
  9516. this.fromSchema(parameters.schema);
  9517. }
  9518. }
  9519. static defaultValues(memberName) {
  9520. switch (memberName) {
  9521. case TBS$3:
  9522. return EMPTY_BUFFER;
  9523. case VERSION$e:
  9524. return 0;
  9525. case SIGNATURE$3:
  9526. return new AlgorithmIdentifier();
  9527. case ISSUER$1:
  9528. return new RelativeDistinguishedNames();
  9529. case THIS_UPDATE$1:
  9530. return new Time();
  9531. case NEXT_UPDATE$1:
  9532. return new Time();
  9533. case REVOKED_CERTIFICATES:
  9534. return [];
  9535. case CRL_EXTENSIONS:
  9536. return new Extensions();
  9537. case SIGNATURE_ALGORITHM$4:
  9538. return new AlgorithmIdentifier();
  9539. case SIGNATURE_VALUE$1:
  9540. return new asn1js__namespace.BitString();
  9541. default:
  9542. return super.defaultValues(memberName);
  9543. }
  9544. }
  9545. static schema(parameters = {}) {
  9546. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  9547. return (new asn1js__namespace.Sequence({
  9548. name: (names.blockName || "CertificateList"),
  9549. value: [
  9550. tbsCertList(parameters),
  9551. AlgorithmIdentifier.schema(names.signatureAlgorithm || {
  9552. names: {
  9553. blockName: SIGNATURE_ALGORITHM$4
  9554. }
  9555. }),
  9556. new asn1js__namespace.BitString({ name: (names.signatureValue || SIGNATURE_VALUE$1) })
  9557. ]
  9558. }));
  9559. }
  9560. fromSchema(schema) {
  9561. pvutils__namespace.clearProps(schema, CLEAR_PROPS$N);
  9562. const asn1 = asn1js__namespace.compareSchema(schema, schema, CertificateRevocationList.schema());
  9563. AsnError.assertSchema(asn1, this.className);
  9564. this.tbsView = asn1.result.tbsCertList.valueBeforeDecodeView;
  9565. if (TBS_CERT_LIST_VERSION in asn1.result) {
  9566. this.version = asn1.result[TBS_CERT_LIST_VERSION].valueBlock.valueDec;
  9567. }
  9568. this.signature = new AlgorithmIdentifier({ schema: asn1.result[TBS_CERT_LIST_SIGNATURE] });
  9569. this.issuer = new RelativeDistinguishedNames({ schema: asn1.result[TBS_CERT_LIST_ISSUER] });
  9570. this.thisUpdate = new Time({ schema: asn1.result[TBS_CERT_LIST_THIS_UPDATE] });
  9571. if (TBS_CERT_LIST_NEXT_UPDATE in asn1.result) {
  9572. this.nextUpdate = new Time({ schema: asn1.result[TBS_CERT_LIST_NEXT_UPDATE] });
  9573. }
  9574. if (TBS_CERT_LIST_REVOKED_CERTIFICATES in asn1.result) {
  9575. this.revokedCertificates = Array.from(asn1.result[TBS_CERT_LIST_REVOKED_CERTIFICATES], element => new RevokedCertificate({ schema: element }));
  9576. }
  9577. if (TBS_CERT_LIST_EXTENSIONS in asn1.result) {
  9578. this.crlExtensions = new Extensions({ schema: asn1.result[TBS_CERT_LIST_EXTENSIONS] });
  9579. }
  9580. this.signatureAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.signatureAlgorithm });
  9581. this.signatureValue = asn1.result.signatureValue;
  9582. }
  9583. encodeTBS() {
  9584. const outputArray = [];
  9585. if (this.version !== CertificateRevocationList.defaultValues(VERSION$e)) {
  9586. outputArray.push(new asn1js__namespace.Integer({ value: this.version }));
  9587. }
  9588. outputArray.push(this.signature.toSchema());
  9589. outputArray.push(this.issuer.toSchema());
  9590. outputArray.push(this.thisUpdate.toSchema());
  9591. if (this.nextUpdate) {
  9592. outputArray.push(this.nextUpdate.toSchema());
  9593. }
  9594. if (this.revokedCertificates) {
  9595. outputArray.push(new asn1js__namespace.Sequence({
  9596. value: Array.from(this.revokedCertificates, o => o.toSchema())
  9597. }));
  9598. }
  9599. if (this.crlExtensions) {
  9600. outputArray.push(new asn1js__namespace.Constructed({
  9601. optional: true,
  9602. idBlock: {
  9603. tagClass: 3,
  9604. tagNumber: 0
  9605. },
  9606. value: [
  9607. this.crlExtensions.toSchema()
  9608. ]
  9609. }));
  9610. }
  9611. return (new asn1js__namespace.Sequence({
  9612. value: outputArray
  9613. }));
  9614. }
  9615. toSchema(encodeFlag = false) {
  9616. let tbsSchema;
  9617. if (!encodeFlag) {
  9618. if (!this.tbsView.byteLength) {
  9619. return CertificateRevocationList.schema();
  9620. }
  9621. const asn1 = asn1js__namespace.fromBER(this.tbsView);
  9622. AsnError.assert(asn1, "TBS Certificate Revocation List");
  9623. tbsSchema = asn1.result;
  9624. }
  9625. else {
  9626. tbsSchema = this.encodeTBS();
  9627. }
  9628. return (new asn1js__namespace.Sequence({
  9629. value: [
  9630. tbsSchema,
  9631. this.signatureAlgorithm.toSchema(),
  9632. this.signatureValue
  9633. ]
  9634. }));
  9635. }
  9636. toJSON() {
  9637. const res = {
  9638. tbs: pvtsutils__namespace.Convert.ToHex(this.tbsView),
  9639. version: this.version,
  9640. signature: this.signature.toJSON(),
  9641. issuer: this.issuer.toJSON(),
  9642. thisUpdate: this.thisUpdate.toJSON(),
  9643. signatureAlgorithm: this.signatureAlgorithm.toJSON(),
  9644. signatureValue: this.signatureValue.toJSON()
  9645. };
  9646. if (this.version !== CertificateRevocationList.defaultValues(VERSION$e))
  9647. res.version = this.version;
  9648. if (this.nextUpdate) {
  9649. res.nextUpdate = this.nextUpdate.toJSON();
  9650. }
  9651. if (this.revokedCertificates) {
  9652. res.revokedCertificates = Array.from(this.revokedCertificates, o => o.toJSON());
  9653. }
  9654. if (this.crlExtensions) {
  9655. res.crlExtensions = this.crlExtensions.toJSON();
  9656. }
  9657. return res;
  9658. }
  9659. isCertificateRevoked(certificate) {
  9660. if (!this.issuer.isEqual(certificate.issuer)) {
  9661. return false;
  9662. }
  9663. if (!this.revokedCertificates) {
  9664. return false;
  9665. }
  9666. for (const revokedCertificate of this.revokedCertificates) {
  9667. if (revokedCertificate.userCertificate.isEqual(certificate.serialNumber)) {
  9668. return true;
  9669. }
  9670. }
  9671. return false;
  9672. }
  9673. async sign(privateKey, hashAlgorithm = "SHA-1", crypto = getCrypto(true)) {
  9674. if (!privateKey) {
  9675. throw new Error("Need to provide a private key for signing");
  9676. }
  9677. const signatureParameters = await crypto.getSignatureParameters(privateKey, hashAlgorithm);
  9678. const { parameters } = signatureParameters;
  9679. this.signature = signatureParameters.signatureAlgorithm;
  9680. this.signatureAlgorithm = signatureParameters.signatureAlgorithm;
  9681. this.tbsView = new Uint8Array(this.encodeTBS().toBER());
  9682. const signature = await crypto.signWithPrivateKey(this.tbsView, privateKey, parameters);
  9683. this.signatureValue = new asn1js__namespace.BitString({ valueHex: signature });
  9684. }
  9685. async verify(parameters = {}, crypto = getCrypto(true)) {
  9686. let subjectPublicKeyInfo;
  9687. if (parameters.issuerCertificate) {
  9688. subjectPublicKeyInfo = parameters.issuerCertificate.subjectPublicKeyInfo;
  9689. if (!this.issuer.isEqual(parameters.issuerCertificate.subject)) {
  9690. return false;
  9691. }
  9692. }
  9693. if (parameters.publicKeyInfo) {
  9694. subjectPublicKeyInfo = parameters.publicKeyInfo;
  9695. }
  9696. if (!subjectPublicKeyInfo) {
  9697. throw new Error("Issuer's certificate must be provided as an input parameter");
  9698. }
  9699. if (this.crlExtensions) {
  9700. for (const extension of this.crlExtensions.extensions) {
  9701. if (extension.critical) {
  9702. if (!WELL_KNOWN_EXTENSIONS.includes(extension.extnID))
  9703. return false;
  9704. }
  9705. }
  9706. }
  9707. return crypto.verifyWithPublicKey(this.tbsView, this.signatureValue, subjectPublicKeyInfo, this.signatureAlgorithm);
  9708. }
  9709. }
  9710. CertificateRevocationList.CLASS_NAME = "CertificateRevocationList";
  9711. const CRL_ID = "crlId";
  9712. const CRL_VALUE = "crlValue";
  9713. const PARSED_VALUE$3 = "parsedValue";
  9714. const CLEAR_PROPS$M = [
  9715. CRL_ID,
  9716. CRL_VALUE,
  9717. ];
  9718. class CRLBag extends PkiObject {
  9719. constructor(parameters = {}) {
  9720. super();
  9721. this.crlId = pvutils__namespace.getParametersValue(parameters, CRL_ID, CRLBag.defaultValues(CRL_ID));
  9722. this.crlValue = pvutils__namespace.getParametersValue(parameters, CRL_VALUE, CRLBag.defaultValues(CRL_VALUE));
  9723. if (PARSED_VALUE$3 in parameters) {
  9724. this.parsedValue = pvutils__namespace.getParametersValue(parameters, PARSED_VALUE$3, CRLBag.defaultValues(PARSED_VALUE$3));
  9725. }
  9726. if (parameters.schema) {
  9727. this.fromSchema(parameters.schema);
  9728. }
  9729. }
  9730. static defaultValues(memberName) {
  9731. switch (memberName) {
  9732. case CRL_ID:
  9733. return EMPTY_STRING;
  9734. case CRL_VALUE:
  9735. return (new asn1js__namespace.Any());
  9736. case PARSED_VALUE$3:
  9737. return {};
  9738. default:
  9739. return super.defaultValues(memberName);
  9740. }
  9741. }
  9742. static compareWithDefault(memberName, memberValue) {
  9743. switch (memberName) {
  9744. case CRL_ID:
  9745. return (memberValue === EMPTY_STRING);
  9746. case CRL_VALUE:
  9747. return (memberValue instanceof asn1js__namespace.Any);
  9748. case PARSED_VALUE$3:
  9749. return ((memberValue instanceof Object) && (Object.keys(memberValue).length === 0));
  9750. default:
  9751. return super.defaultValues(memberName);
  9752. }
  9753. }
  9754. static schema(parameters = {}) {
  9755. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  9756. return (new asn1js__namespace.Sequence({
  9757. name: (names.blockName || EMPTY_STRING),
  9758. value: [
  9759. new asn1js__namespace.ObjectIdentifier({ name: (names.id || "id") }),
  9760. new asn1js__namespace.Constructed({
  9761. idBlock: {
  9762. tagClass: 3,
  9763. tagNumber: 0
  9764. },
  9765. value: [new asn1js__namespace.Any({ name: (names.value || "value") })]
  9766. })
  9767. ]
  9768. }));
  9769. }
  9770. fromSchema(schema) {
  9771. pvutils__namespace.clearProps(schema, CLEAR_PROPS$M);
  9772. const asn1 = asn1js__namespace.compareSchema(schema, schema, CRLBag.schema({
  9773. names: {
  9774. id: CRL_ID,
  9775. value: CRL_VALUE
  9776. }
  9777. }));
  9778. AsnError.assertSchema(asn1, this.className);
  9779. this.crlId = asn1.result.crlId.valueBlock.toString();
  9780. this.crlValue = asn1.result.crlValue;
  9781. switch (this.crlId) {
  9782. case id_CRLBag_X509CRL:
  9783. {
  9784. this.parsedValue = CertificateRevocationList.fromBER(this.certValue.valueBlock.valueHex);
  9785. }
  9786. break;
  9787. default:
  9788. throw new Error(`Incorrect CRL_ID value in CRLBag: ${this.crlId}`);
  9789. }
  9790. }
  9791. toSchema() {
  9792. if (this.parsedValue) {
  9793. this.crlId = id_CRLBag_X509CRL;
  9794. this.crlValue = new asn1js__namespace.OctetString({ valueHex: this.parsedValue.toSchema().toBER(false) });
  9795. }
  9796. return (new asn1js__namespace.Sequence({
  9797. value: [
  9798. new asn1js__namespace.ObjectIdentifier({ value: this.crlId }),
  9799. new asn1js__namespace.Constructed({
  9800. idBlock: {
  9801. tagClass: 3,
  9802. tagNumber: 0
  9803. },
  9804. value: [this.crlValue.toSchema()]
  9805. })
  9806. ]
  9807. }));
  9808. }
  9809. toJSON() {
  9810. return {
  9811. crlId: this.crlId,
  9812. crlValue: this.crlValue.toJSON()
  9813. };
  9814. }
  9815. }
  9816. CRLBag.CLASS_NAME = "CRLBag";
  9817. const VERSION$d = "version";
  9818. const ENCRYPTED_CONTENT_INFO$1 = "encryptedContentInfo";
  9819. const UNPROTECTED_ATTRS$1 = "unprotectedAttrs";
  9820. const CLEAR_PROPS$L = [
  9821. VERSION$d,
  9822. ENCRYPTED_CONTENT_INFO$1,
  9823. UNPROTECTED_ATTRS$1,
  9824. ];
  9825. class EncryptedData extends PkiObject {
  9826. constructor(parameters = {}) {
  9827. super();
  9828. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$d, EncryptedData.defaultValues(VERSION$d));
  9829. this.encryptedContentInfo = pvutils__namespace.getParametersValue(parameters, ENCRYPTED_CONTENT_INFO$1, EncryptedData.defaultValues(ENCRYPTED_CONTENT_INFO$1));
  9830. if (UNPROTECTED_ATTRS$1 in parameters) {
  9831. this.unprotectedAttrs = pvutils__namespace.getParametersValue(parameters, UNPROTECTED_ATTRS$1, EncryptedData.defaultValues(UNPROTECTED_ATTRS$1));
  9832. }
  9833. if (parameters.schema) {
  9834. this.fromSchema(parameters.schema);
  9835. }
  9836. }
  9837. static defaultValues(memberName) {
  9838. switch (memberName) {
  9839. case VERSION$d:
  9840. return 0;
  9841. case ENCRYPTED_CONTENT_INFO$1:
  9842. return new EncryptedContentInfo();
  9843. case UNPROTECTED_ATTRS$1:
  9844. return [];
  9845. default:
  9846. return super.defaultValues(memberName);
  9847. }
  9848. }
  9849. static compareWithDefault(memberName, memberValue) {
  9850. switch (memberName) {
  9851. case VERSION$d:
  9852. return (memberValue === 0);
  9853. case ENCRYPTED_CONTENT_INFO$1:
  9854. return ((EncryptedContentInfo.compareWithDefault("contentType", memberValue.contentType)) &&
  9855. (EncryptedContentInfo.compareWithDefault("contentEncryptionAlgorithm", memberValue.contentEncryptionAlgorithm)) &&
  9856. (EncryptedContentInfo.compareWithDefault("encryptedContent", memberValue.encryptedContent)));
  9857. case UNPROTECTED_ATTRS$1:
  9858. return (memberValue.length === 0);
  9859. default:
  9860. return super.defaultValues(memberName);
  9861. }
  9862. }
  9863. static schema(parameters = {}) {
  9864. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  9865. return (new asn1js__namespace.Sequence({
  9866. name: (names.blockName || EMPTY_STRING),
  9867. value: [
  9868. new asn1js__namespace.Integer({ name: (names.version || EMPTY_STRING) }),
  9869. EncryptedContentInfo.schema(names.encryptedContentInfo || {}),
  9870. new asn1js__namespace.Constructed({
  9871. optional: true,
  9872. idBlock: {
  9873. tagClass: 3,
  9874. tagNumber: 1
  9875. },
  9876. value: [
  9877. new asn1js__namespace.Repeated({
  9878. name: (names.unprotectedAttrs || EMPTY_STRING),
  9879. value: Attribute.schema()
  9880. })
  9881. ]
  9882. })
  9883. ]
  9884. }));
  9885. }
  9886. fromSchema(schema) {
  9887. pvutils__namespace.clearProps(schema, CLEAR_PROPS$L);
  9888. const asn1 = asn1js__namespace.compareSchema(schema, schema, EncryptedData.schema({
  9889. names: {
  9890. version: VERSION$d,
  9891. encryptedContentInfo: {
  9892. names: {
  9893. blockName: ENCRYPTED_CONTENT_INFO$1
  9894. }
  9895. },
  9896. unprotectedAttrs: UNPROTECTED_ATTRS$1
  9897. }
  9898. }));
  9899. AsnError.assertSchema(asn1, this.className);
  9900. this.version = asn1.result.version.valueBlock.valueDec;
  9901. this.encryptedContentInfo = new EncryptedContentInfo({ schema: asn1.result.encryptedContentInfo });
  9902. if (UNPROTECTED_ATTRS$1 in asn1.result)
  9903. this.unprotectedAttrs = Array.from(asn1.result.unprotectedAttrs, element => new Attribute({ schema: element }));
  9904. }
  9905. toSchema() {
  9906. const outputArray = [];
  9907. outputArray.push(new asn1js__namespace.Integer({ value: this.version }));
  9908. outputArray.push(this.encryptedContentInfo.toSchema());
  9909. if (this.unprotectedAttrs) {
  9910. outputArray.push(new asn1js__namespace.Constructed({
  9911. optional: true,
  9912. idBlock: {
  9913. tagClass: 3,
  9914. tagNumber: 1
  9915. },
  9916. value: Array.from(this.unprotectedAttrs, o => o.toSchema())
  9917. }));
  9918. }
  9919. return (new asn1js__namespace.Sequence({
  9920. value: outputArray
  9921. }));
  9922. }
  9923. toJSON() {
  9924. const res = {
  9925. version: this.version,
  9926. encryptedContentInfo: this.encryptedContentInfo.toJSON()
  9927. };
  9928. if (this.unprotectedAttrs)
  9929. res.unprotectedAttrs = Array.from(this.unprotectedAttrs, o => o.toJSON());
  9930. return res;
  9931. }
  9932. async encrypt(parameters, crypto = getCrypto(true)) {
  9933. ArgumentError.assert(parameters, "parameters", "object");
  9934. const encryptParams = {
  9935. ...parameters,
  9936. contentType: "1.2.840.113549.1.7.1",
  9937. };
  9938. this.encryptedContentInfo = await crypto.encryptEncryptedContentInfo(encryptParams);
  9939. }
  9940. async decrypt(parameters, crypto = getCrypto(true)) {
  9941. ArgumentError.assert(parameters, "parameters", "object");
  9942. const decryptParams = {
  9943. ...parameters,
  9944. encryptedContentInfo: this.encryptedContentInfo,
  9945. };
  9946. return crypto.decryptEncryptedContentInfo(decryptParams);
  9947. }
  9948. }
  9949. EncryptedData.CLASS_NAME = "EncryptedData";
  9950. const ENCRYPTION_ALGORITHM = "encryptionAlgorithm";
  9951. const ENCRYPTED_DATA = "encryptedData";
  9952. const PARSED_VALUE$2 = "parsedValue";
  9953. const CLEAR_PROPS$K = [
  9954. ENCRYPTION_ALGORITHM,
  9955. ENCRYPTED_DATA,
  9956. ];
  9957. class PKCS8ShroudedKeyBag extends PkiObject {
  9958. constructor(parameters = {}) {
  9959. super();
  9960. this.encryptionAlgorithm = pvutils__namespace.getParametersValue(parameters, ENCRYPTION_ALGORITHM, PKCS8ShroudedKeyBag.defaultValues(ENCRYPTION_ALGORITHM));
  9961. this.encryptedData = pvutils__namespace.getParametersValue(parameters, ENCRYPTED_DATA, PKCS8ShroudedKeyBag.defaultValues(ENCRYPTED_DATA));
  9962. if (PARSED_VALUE$2 in parameters) {
  9963. this.parsedValue = pvutils__namespace.getParametersValue(parameters, PARSED_VALUE$2, PKCS8ShroudedKeyBag.defaultValues(PARSED_VALUE$2));
  9964. }
  9965. if (parameters.schema) {
  9966. this.fromSchema(parameters.schema);
  9967. }
  9968. }
  9969. static defaultValues(memberName) {
  9970. switch (memberName) {
  9971. case ENCRYPTION_ALGORITHM:
  9972. return (new AlgorithmIdentifier());
  9973. case ENCRYPTED_DATA:
  9974. return (new asn1js__namespace.OctetString());
  9975. case PARSED_VALUE$2:
  9976. return {};
  9977. default:
  9978. return super.defaultValues(memberName);
  9979. }
  9980. }
  9981. static compareWithDefault(memberName, memberValue) {
  9982. switch (memberName) {
  9983. case ENCRYPTION_ALGORITHM:
  9984. return ((AlgorithmIdentifier.compareWithDefault("algorithmId", memberValue.algorithmId)) &&
  9985. (("algorithmParams" in memberValue) === false));
  9986. case ENCRYPTED_DATA:
  9987. return (memberValue.isEqual(PKCS8ShroudedKeyBag.defaultValues(memberName)));
  9988. case PARSED_VALUE$2:
  9989. return ((memberValue instanceof Object) && (Object.keys(memberValue).length === 0));
  9990. default:
  9991. return super.defaultValues(memberName);
  9992. }
  9993. }
  9994. static schema(parameters = {}) {
  9995. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  9996. return (new asn1js__namespace.Sequence({
  9997. name: (names.blockName || EMPTY_STRING),
  9998. value: [
  9999. AlgorithmIdentifier.schema(names.encryptionAlgorithm || {
  10000. names: {
  10001. blockName: ENCRYPTION_ALGORITHM
  10002. }
  10003. }),
  10004. new asn1js__namespace.Choice({
  10005. value: [
  10006. new asn1js__namespace.OctetString({ name: (names.encryptedData || ENCRYPTED_DATA) }),
  10007. new asn1js__namespace.OctetString({
  10008. idBlock: {
  10009. isConstructed: true
  10010. },
  10011. name: (names.encryptedData || ENCRYPTED_DATA)
  10012. })
  10013. ]
  10014. })
  10015. ]
  10016. }));
  10017. }
  10018. fromSchema(schema) {
  10019. pvutils__namespace.clearProps(schema, CLEAR_PROPS$K);
  10020. const asn1 = asn1js__namespace.compareSchema(schema, schema, PKCS8ShroudedKeyBag.schema({
  10021. names: {
  10022. encryptionAlgorithm: {
  10023. names: {
  10024. blockName: ENCRYPTION_ALGORITHM
  10025. }
  10026. },
  10027. encryptedData: ENCRYPTED_DATA
  10028. }
  10029. }));
  10030. AsnError.assertSchema(asn1, this.className);
  10031. this.encryptionAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.encryptionAlgorithm });
  10032. this.encryptedData = asn1.result.encryptedData;
  10033. }
  10034. toSchema() {
  10035. return (new asn1js__namespace.Sequence({
  10036. value: [
  10037. this.encryptionAlgorithm.toSchema(),
  10038. this.encryptedData
  10039. ]
  10040. }));
  10041. }
  10042. toJSON() {
  10043. return {
  10044. encryptionAlgorithm: this.encryptionAlgorithm.toJSON(),
  10045. encryptedData: this.encryptedData.toJSON(),
  10046. };
  10047. }
  10048. async parseInternalValues(parameters, crypto = getCrypto(true)) {
  10049. const cmsEncrypted = new EncryptedData({
  10050. encryptedContentInfo: new EncryptedContentInfo({
  10051. contentEncryptionAlgorithm: this.encryptionAlgorithm,
  10052. encryptedContent: this.encryptedData
  10053. })
  10054. });
  10055. const decryptedData = await cmsEncrypted.decrypt(parameters, crypto);
  10056. this.parsedValue = PrivateKeyInfo.fromBER(decryptedData);
  10057. }
  10058. async makeInternalValues(parameters, crypto = getCrypto(true)) {
  10059. if (!this.parsedValue) {
  10060. throw new Error("Please initialize \"parsedValue\" first");
  10061. }
  10062. const cmsEncrypted = new EncryptedData();
  10063. const encryptParams = {
  10064. ...parameters,
  10065. contentToEncrypt: this.parsedValue.toSchema().toBER(false),
  10066. };
  10067. await cmsEncrypted.encrypt(encryptParams, crypto);
  10068. if (!cmsEncrypted.encryptedContentInfo.encryptedContent) {
  10069. throw new Error("The filed `encryptedContent` in EncryptedContentInfo is empty");
  10070. }
  10071. this.encryptionAlgorithm = cmsEncrypted.encryptedContentInfo.contentEncryptionAlgorithm;
  10072. this.encryptedData = cmsEncrypted.encryptedContentInfo.encryptedContent;
  10073. }
  10074. }
  10075. PKCS8ShroudedKeyBag.CLASS_NAME = "PKCS8ShroudedKeyBag";
  10076. const SECRET_TYPE_ID = "secretTypeId";
  10077. const SECRET_VALUE = "secretValue";
  10078. const CLEAR_PROPS$J = [
  10079. SECRET_TYPE_ID,
  10080. SECRET_VALUE,
  10081. ];
  10082. class SecretBag extends PkiObject {
  10083. constructor(parameters = {}) {
  10084. super();
  10085. this.secretTypeId = pvutils__namespace.getParametersValue(parameters, SECRET_TYPE_ID, SecretBag.defaultValues(SECRET_TYPE_ID));
  10086. this.secretValue = pvutils__namespace.getParametersValue(parameters, SECRET_VALUE, SecretBag.defaultValues(SECRET_VALUE));
  10087. if (parameters.schema) {
  10088. this.fromSchema(parameters.schema);
  10089. }
  10090. }
  10091. static defaultValues(memberName) {
  10092. switch (memberName) {
  10093. case SECRET_TYPE_ID:
  10094. return EMPTY_STRING;
  10095. case SECRET_VALUE:
  10096. return (new asn1js__namespace.Any());
  10097. default:
  10098. return super.defaultValues(memberName);
  10099. }
  10100. }
  10101. static compareWithDefault(memberName, memberValue) {
  10102. switch (memberName) {
  10103. case SECRET_TYPE_ID:
  10104. return (memberValue === EMPTY_STRING);
  10105. case SECRET_VALUE:
  10106. return (memberValue instanceof asn1js__namespace.Any);
  10107. default:
  10108. return super.defaultValues(memberName);
  10109. }
  10110. }
  10111. static schema(parameters = {}) {
  10112. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  10113. return (new asn1js__namespace.Sequence({
  10114. name: (names.blockName || EMPTY_STRING),
  10115. value: [
  10116. new asn1js__namespace.ObjectIdentifier({ name: (names.id || "id") }),
  10117. new asn1js__namespace.Constructed({
  10118. idBlock: {
  10119. tagClass: 3,
  10120. tagNumber: 0
  10121. },
  10122. value: [new asn1js__namespace.Any({ name: (names.value || "value") })]
  10123. })
  10124. ]
  10125. }));
  10126. }
  10127. fromSchema(schema) {
  10128. pvutils__namespace.clearProps(schema, CLEAR_PROPS$J);
  10129. const asn1 = asn1js__namespace.compareSchema(schema, schema, SecretBag.schema({
  10130. names: {
  10131. id: SECRET_TYPE_ID,
  10132. value: SECRET_VALUE
  10133. }
  10134. }));
  10135. AsnError.assertSchema(asn1, this.className);
  10136. this.secretTypeId = asn1.result.secretTypeId.valueBlock.toString();
  10137. this.secretValue = asn1.result.secretValue;
  10138. }
  10139. toSchema() {
  10140. return (new asn1js__namespace.Sequence({
  10141. value: [
  10142. new asn1js__namespace.ObjectIdentifier({ value: this.secretTypeId }),
  10143. new asn1js__namespace.Constructed({
  10144. idBlock: {
  10145. tagClass: 3,
  10146. tagNumber: 0
  10147. },
  10148. value: [this.secretValue.toSchema()]
  10149. })
  10150. ]
  10151. }));
  10152. }
  10153. toJSON() {
  10154. return {
  10155. secretTypeId: this.secretTypeId,
  10156. secretValue: this.secretValue.toJSON()
  10157. };
  10158. }
  10159. }
  10160. SecretBag.CLASS_NAME = "SecretBag";
  10161. class SafeBagValueFactory {
  10162. static getItems() {
  10163. if (!this.items) {
  10164. this.items = {};
  10165. SafeBagValueFactory.register("1.2.840.113549.1.12.10.1.1", PrivateKeyInfo);
  10166. SafeBagValueFactory.register("1.2.840.113549.1.12.10.1.2", PKCS8ShroudedKeyBag);
  10167. SafeBagValueFactory.register("1.2.840.113549.1.12.10.1.3", CertBag);
  10168. SafeBagValueFactory.register("1.2.840.113549.1.12.10.1.4", CRLBag);
  10169. SafeBagValueFactory.register("1.2.840.113549.1.12.10.1.5", SecretBag);
  10170. SafeBagValueFactory.register("1.2.840.113549.1.12.10.1.6", SafeContents);
  10171. }
  10172. return this.items;
  10173. }
  10174. static register(id, type) {
  10175. this.getItems()[id] = type;
  10176. }
  10177. static find(id) {
  10178. return this.getItems()[id] || null;
  10179. }
  10180. }
  10181. const BAG_ID = "bagId";
  10182. const BAG_VALUE = "bagValue";
  10183. const BAG_ATTRIBUTES = "bagAttributes";
  10184. const CLEAR_PROPS$I = [
  10185. BAG_ID,
  10186. BAG_VALUE,
  10187. BAG_ATTRIBUTES
  10188. ];
  10189. class SafeBag extends PkiObject {
  10190. constructor(parameters = {}) {
  10191. super();
  10192. this.bagId = pvutils__namespace.getParametersValue(parameters, BAG_ID, SafeBag.defaultValues(BAG_ID));
  10193. this.bagValue = pvutils__namespace.getParametersValue(parameters, BAG_VALUE, SafeBag.defaultValues(BAG_VALUE));
  10194. if (BAG_ATTRIBUTES in parameters) {
  10195. this.bagAttributes = pvutils__namespace.getParametersValue(parameters, BAG_ATTRIBUTES, SafeBag.defaultValues(BAG_ATTRIBUTES));
  10196. }
  10197. if (parameters.schema) {
  10198. this.fromSchema(parameters.schema);
  10199. }
  10200. }
  10201. static defaultValues(memberName) {
  10202. switch (memberName) {
  10203. case BAG_ID:
  10204. return EMPTY_STRING;
  10205. case BAG_VALUE:
  10206. return (new asn1js__namespace.Any());
  10207. case BAG_ATTRIBUTES:
  10208. return [];
  10209. default:
  10210. return super.defaultValues(memberName);
  10211. }
  10212. }
  10213. static compareWithDefault(memberName, memberValue) {
  10214. switch (memberName) {
  10215. case BAG_ID:
  10216. return (memberValue === EMPTY_STRING);
  10217. case BAG_VALUE:
  10218. return (memberValue instanceof asn1js__namespace.Any);
  10219. case BAG_ATTRIBUTES:
  10220. return (memberValue.length === 0);
  10221. default:
  10222. return super.defaultValues(memberName);
  10223. }
  10224. }
  10225. static schema(parameters = {}) {
  10226. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  10227. return (new asn1js__namespace.Sequence({
  10228. name: (names.blockName || EMPTY_STRING),
  10229. value: [
  10230. new asn1js__namespace.ObjectIdentifier({ name: (names.bagId || BAG_ID) }),
  10231. new asn1js__namespace.Constructed({
  10232. idBlock: {
  10233. tagClass: 3,
  10234. tagNumber: 0
  10235. },
  10236. value: [new asn1js__namespace.Any({ name: (names.bagValue || BAG_VALUE) })]
  10237. }),
  10238. new asn1js__namespace.Set({
  10239. optional: true,
  10240. value: [
  10241. new asn1js__namespace.Repeated({
  10242. name: (names.bagAttributes || BAG_ATTRIBUTES),
  10243. value: Attribute.schema()
  10244. })
  10245. ]
  10246. })
  10247. ]
  10248. }));
  10249. }
  10250. fromSchema(schema) {
  10251. pvutils__namespace.clearProps(schema, CLEAR_PROPS$I);
  10252. const asn1 = asn1js__namespace.compareSchema(schema, schema, SafeBag.schema({
  10253. names: {
  10254. bagId: BAG_ID,
  10255. bagValue: BAG_VALUE,
  10256. bagAttributes: BAG_ATTRIBUTES
  10257. }
  10258. }));
  10259. AsnError.assertSchema(asn1, this.className);
  10260. this.bagId = asn1.result.bagId.valueBlock.toString();
  10261. const bagType = SafeBagValueFactory.find(this.bagId);
  10262. if (!bagType) {
  10263. throw new Error(`Invalid BAG_ID for SafeBag: ${this.bagId}`);
  10264. }
  10265. this.bagValue = new bagType({ schema: asn1.result.bagValue });
  10266. if (BAG_ATTRIBUTES in asn1.result) {
  10267. this.bagAttributes = Array.from(asn1.result.bagAttributes, element => new Attribute({ schema: element }));
  10268. }
  10269. }
  10270. toSchema() {
  10271. const outputArray = [
  10272. new asn1js__namespace.ObjectIdentifier({ value: this.bagId }),
  10273. new asn1js__namespace.Constructed({
  10274. idBlock: {
  10275. tagClass: 3,
  10276. tagNumber: 0
  10277. },
  10278. value: [this.bagValue.toSchema()]
  10279. })
  10280. ];
  10281. if (this.bagAttributes) {
  10282. outputArray.push(new asn1js__namespace.Set({
  10283. value: Array.from(this.bagAttributes, o => o.toSchema())
  10284. }));
  10285. }
  10286. return (new asn1js__namespace.Sequence({
  10287. value: outputArray
  10288. }));
  10289. }
  10290. toJSON() {
  10291. const output = {
  10292. bagId: this.bagId,
  10293. bagValue: this.bagValue.toJSON()
  10294. };
  10295. if (this.bagAttributes) {
  10296. output.bagAttributes = Array.from(this.bagAttributes, o => o.toJSON());
  10297. }
  10298. return output;
  10299. }
  10300. }
  10301. SafeBag.CLASS_NAME = "SafeBag";
  10302. const SAFE_BUGS = "safeBags";
  10303. class SafeContents extends PkiObject {
  10304. constructor(parameters = {}) {
  10305. super();
  10306. this.safeBags = pvutils__namespace.getParametersValue(parameters, SAFE_BUGS, SafeContents.defaultValues(SAFE_BUGS));
  10307. if (parameters.schema) {
  10308. this.fromSchema(parameters.schema);
  10309. }
  10310. }
  10311. static defaultValues(memberName) {
  10312. switch (memberName) {
  10313. case SAFE_BUGS:
  10314. return [];
  10315. default:
  10316. return super.defaultValues(memberName);
  10317. }
  10318. }
  10319. static compareWithDefault(memberName, memberValue) {
  10320. switch (memberName) {
  10321. case SAFE_BUGS:
  10322. return (memberValue.length === 0);
  10323. default:
  10324. return super.defaultValues(memberName);
  10325. }
  10326. }
  10327. static schema(parameters = {}) {
  10328. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  10329. return (new asn1js__namespace.Sequence({
  10330. name: (names.blockName || EMPTY_STRING),
  10331. value: [
  10332. new asn1js__namespace.Repeated({
  10333. name: (names.safeBags || EMPTY_STRING),
  10334. value: SafeBag.schema()
  10335. })
  10336. ]
  10337. }));
  10338. }
  10339. fromSchema(schema) {
  10340. pvutils__namespace.clearProps(schema, [
  10341. SAFE_BUGS
  10342. ]);
  10343. const asn1 = asn1js__namespace.compareSchema(schema, schema, SafeContents.schema({
  10344. names: {
  10345. safeBags: SAFE_BUGS
  10346. }
  10347. }));
  10348. AsnError.assertSchema(asn1, this.className);
  10349. this.safeBags = Array.from(asn1.result.safeBags, element => new SafeBag({ schema: element }));
  10350. }
  10351. toSchema() {
  10352. return (new asn1js__namespace.Sequence({
  10353. value: Array.from(this.safeBags, o => o.toSchema())
  10354. }));
  10355. }
  10356. toJSON() {
  10357. return {
  10358. safeBags: Array.from(this.safeBags, o => o.toJSON())
  10359. };
  10360. }
  10361. }
  10362. SafeContents.CLASS_NAME = "SafeContents";
  10363. const OTHER_CERT_FORMAT = "otherCertFormat";
  10364. const OTHER_CERT = "otherCert";
  10365. const CLEAR_PROPS$H = [
  10366. OTHER_CERT_FORMAT,
  10367. OTHER_CERT
  10368. ];
  10369. class OtherCertificateFormat extends PkiObject {
  10370. constructor(parameters = {}) {
  10371. super();
  10372. this.otherCertFormat = pvutils__namespace.getParametersValue(parameters, OTHER_CERT_FORMAT, OtherCertificateFormat.defaultValues(OTHER_CERT_FORMAT));
  10373. this.otherCert = pvutils__namespace.getParametersValue(parameters, OTHER_CERT, OtherCertificateFormat.defaultValues(OTHER_CERT));
  10374. if (parameters.schema) {
  10375. this.fromSchema(parameters.schema);
  10376. }
  10377. }
  10378. static defaultValues(memberName) {
  10379. switch (memberName) {
  10380. case OTHER_CERT_FORMAT:
  10381. return EMPTY_STRING;
  10382. case OTHER_CERT:
  10383. return new asn1js__namespace.Any();
  10384. default:
  10385. return super.defaultValues(memberName);
  10386. }
  10387. }
  10388. static schema(parameters = {}) {
  10389. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  10390. return (new asn1js__namespace.Sequence({
  10391. name: (names.blockName || EMPTY_STRING),
  10392. value: [
  10393. new asn1js__namespace.ObjectIdentifier({ name: (names.otherCertFormat || OTHER_CERT_FORMAT) }),
  10394. new asn1js__namespace.Any({ name: (names.otherCert || OTHER_CERT) })
  10395. ]
  10396. }));
  10397. }
  10398. fromSchema(schema) {
  10399. pvutils__namespace.clearProps(schema, CLEAR_PROPS$H);
  10400. const asn1 = asn1js__namespace.compareSchema(schema, schema, OtherCertificateFormat.schema());
  10401. AsnError.assertSchema(asn1, this.className);
  10402. this.otherCertFormat = asn1.result.otherCertFormat.valueBlock.toString();
  10403. this.otherCert = asn1.result.otherCert;
  10404. }
  10405. toSchema() {
  10406. return (new asn1js__namespace.Sequence({
  10407. value: [
  10408. new asn1js__namespace.ObjectIdentifier({ value: this.otherCertFormat }),
  10409. this.otherCert
  10410. ]
  10411. }));
  10412. }
  10413. toJSON() {
  10414. const res = {
  10415. otherCertFormat: this.otherCertFormat
  10416. };
  10417. if (!(this.otherCert instanceof asn1js__namespace.Any)) {
  10418. res.otherCert = this.otherCert.toJSON();
  10419. }
  10420. return res;
  10421. }
  10422. }
  10423. const CERTIFICATES$1 = "certificates";
  10424. const CLEAR_PROPS$G = [
  10425. CERTIFICATES$1,
  10426. ];
  10427. class CertificateSet extends PkiObject {
  10428. constructor(parameters = {}) {
  10429. super();
  10430. this.certificates = pvutils__namespace.getParametersValue(parameters, CERTIFICATES$1, CertificateSet.defaultValues(CERTIFICATES$1));
  10431. if (parameters.schema) {
  10432. this.fromSchema(parameters.schema);
  10433. }
  10434. }
  10435. static defaultValues(memberName) {
  10436. switch (memberName) {
  10437. case CERTIFICATES$1:
  10438. return [];
  10439. default:
  10440. return super.defaultValues(memberName);
  10441. }
  10442. }
  10443. static schema(parameters = {}) {
  10444. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  10445. return (new asn1js__namespace.Set({
  10446. name: (names.blockName || EMPTY_STRING),
  10447. value: [
  10448. new asn1js__namespace.Repeated({
  10449. name: (names.certificates || CERTIFICATES$1),
  10450. value: new asn1js__namespace.Choice({
  10451. value: [
  10452. Certificate.schema(),
  10453. new asn1js__namespace.Constructed({
  10454. idBlock: {
  10455. tagClass: 3,
  10456. tagNumber: 0
  10457. },
  10458. value: [
  10459. new asn1js__namespace.Any()
  10460. ]
  10461. }),
  10462. new asn1js__namespace.Constructed({
  10463. idBlock: {
  10464. tagClass: 3,
  10465. tagNumber: 1
  10466. },
  10467. value: [
  10468. new asn1js__namespace.Sequence
  10469. ]
  10470. }),
  10471. new asn1js__namespace.Constructed({
  10472. idBlock: {
  10473. tagClass: 3,
  10474. tagNumber: 2
  10475. },
  10476. value: AttributeCertificateV2.schema().valueBlock.value
  10477. }),
  10478. new asn1js__namespace.Constructed({
  10479. idBlock: {
  10480. tagClass: 3,
  10481. tagNumber: 3
  10482. },
  10483. value: OtherCertificateFormat.schema().valueBlock.value
  10484. })
  10485. ]
  10486. })
  10487. })
  10488. ]
  10489. }));
  10490. }
  10491. fromSchema(schema) {
  10492. pvutils__namespace.clearProps(schema, CLEAR_PROPS$G);
  10493. const asn1 = asn1js__namespace.compareSchema(schema, schema, CertificateSet.schema());
  10494. AsnError.assertSchema(asn1, this.className);
  10495. this.certificates = Array.from(asn1.result.certificates || [], (element) => {
  10496. const initialTagNumber = element.idBlock.tagNumber;
  10497. if (element.idBlock.tagClass === 1)
  10498. return new Certificate({ schema: element });
  10499. const elementSequence = new asn1js__namespace.Sequence({
  10500. value: element.valueBlock.value
  10501. });
  10502. switch (initialTagNumber) {
  10503. case 1:
  10504. if (elementSequence.valueBlock.value[0].valueBlock.value[0].valueBlock.valueDec === 1) {
  10505. return new AttributeCertificateV2({ schema: elementSequence });
  10506. }
  10507. else {
  10508. return new AttributeCertificateV1({ schema: elementSequence });
  10509. }
  10510. case 2:
  10511. return new AttributeCertificateV2({ schema: elementSequence });
  10512. case 3:
  10513. return new OtherCertificateFormat({ schema: elementSequence });
  10514. }
  10515. return element;
  10516. });
  10517. }
  10518. toSchema() {
  10519. return (new asn1js__namespace.Set({
  10520. value: Array.from(this.certificates, element => {
  10521. switch (true) {
  10522. case (element instanceof Certificate):
  10523. return element.toSchema();
  10524. case (element instanceof AttributeCertificateV1):
  10525. return new asn1js__namespace.Constructed({
  10526. idBlock: {
  10527. tagClass: 3,
  10528. tagNumber: 1
  10529. },
  10530. value: element.toSchema().valueBlock.value
  10531. });
  10532. case (element instanceof AttributeCertificateV2):
  10533. return new asn1js__namespace.Constructed({
  10534. idBlock: {
  10535. tagClass: 3,
  10536. tagNumber: 2
  10537. },
  10538. value: element.toSchema().valueBlock.value
  10539. });
  10540. case (element instanceof OtherCertificateFormat):
  10541. return new asn1js__namespace.Constructed({
  10542. idBlock: {
  10543. tagClass: 3,
  10544. tagNumber: 3
  10545. },
  10546. value: element.toSchema().valueBlock.value
  10547. });
  10548. }
  10549. return element.toSchema();
  10550. })
  10551. }));
  10552. }
  10553. toJSON() {
  10554. return {
  10555. certificates: Array.from(this.certificates, o => o.toJSON())
  10556. };
  10557. }
  10558. }
  10559. CertificateSet.CLASS_NAME = "CertificateSet";
  10560. const OTHER_REV_INFO_FORMAT = "otherRevInfoFormat";
  10561. const OTHER_REV_INFO = "otherRevInfo";
  10562. const CLEAR_PROPS$F = [
  10563. OTHER_REV_INFO_FORMAT,
  10564. OTHER_REV_INFO
  10565. ];
  10566. class OtherRevocationInfoFormat extends PkiObject {
  10567. constructor(parameters = {}) {
  10568. super();
  10569. this.otherRevInfoFormat = pvutils__namespace.getParametersValue(parameters, OTHER_REV_INFO_FORMAT, OtherRevocationInfoFormat.defaultValues(OTHER_REV_INFO_FORMAT));
  10570. this.otherRevInfo = pvutils__namespace.getParametersValue(parameters, OTHER_REV_INFO, OtherRevocationInfoFormat.defaultValues(OTHER_REV_INFO));
  10571. if (parameters.schema) {
  10572. this.fromSchema(parameters.schema);
  10573. }
  10574. }
  10575. static defaultValues(memberName) {
  10576. switch (memberName) {
  10577. case OTHER_REV_INFO_FORMAT:
  10578. return EMPTY_STRING;
  10579. case OTHER_REV_INFO:
  10580. return new asn1js__namespace.Any();
  10581. default:
  10582. return super.defaultValues(memberName);
  10583. }
  10584. }
  10585. static schema(parameters = {}) {
  10586. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  10587. return (new asn1js__namespace.Sequence({
  10588. name: (names.blockName || EMPTY_STRING),
  10589. value: [
  10590. new asn1js__namespace.ObjectIdentifier({ name: (names.otherRevInfoFormat || OTHER_REV_INFO_FORMAT) }),
  10591. new asn1js__namespace.Any({ name: (names.otherRevInfo || OTHER_REV_INFO) })
  10592. ]
  10593. }));
  10594. }
  10595. fromSchema(schema) {
  10596. pvutils__namespace.clearProps(schema, CLEAR_PROPS$F);
  10597. const asn1 = asn1js__namespace.compareSchema(schema, schema, OtherRevocationInfoFormat.schema());
  10598. AsnError.assertSchema(asn1, this.className);
  10599. this.otherRevInfoFormat = asn1.result.otherRevInfoFormat.valueBlock.toString();
  10600. this.otherRevInfo = asn1.result.otherRevInfo;
  10601. }
  10602. toSchema() {
  10603. return (new asn1js__namespace.Sequence({
  10604. value: [
  10605. new asn1js__namespace.ObjectIdentifier({ value: this.otherRevInfoFormat }),
  10606. this.otherRevInfo
  10607. ]
  10608. }));
  10609. }
  10610. toJSON() {
  10611. const res = {
  10612. otherRevInfoFormat: this.otherRevInfoFormat
  10613. };
  10614. if (!(this.otherRevInfo instanceof asn1js__namespace.Any)) {
  10615. res.otherRevInfo = this.otherRevInfo.toJSON();
  10616. }
  10617. return res;
  10618. }
  10619. }
  10620. OtherRevocationInfoFormat.CLASS_NAME = "OtherRevocationInfoFormat";
  10621. const CRLS$3 = "crls";
  10622. const OTHER_REVOCATION_INFOS = "otherRevocationInfos";
  10623. const CLEAR_PROPS$E = [
  10624. CRLS$3
  10625. ];
  10626. class RevocationInfoChoices extends PkiObject {
  10627. constructor(parameters = {}) {
  10628. super();
  10629. this.crls = pvutils__namespace.getParametersValue(parameters, CRLS$3, RevocationInfoChoices.defaultValues(CRLS$3));
  10630. this.otherRevocationInfos = pvutils__namespace.getParametersValue(parameters, OTHER_REVOCATION_INFOS, RevocationInfoChoices.defaultValues(OTHER_REVOCATION_INFOS));
  10631. if (parameters.schema) {
  10632. this.fromSchema(parameters.schema);
  10633. }
  10634. }
  10635. static defaultValues(memberName) {
  10636. switch (memberName) {
  10637. case CRLS$3:
  10638. return [];
  10639. case OTHER_REVOCATION_INFOS:
  10640. return [];
  10641. default:
  10642. return super.defaultValues(memberName);
  10643. }
  10644. }
  10645. static schema(parameters = {}) {
  10646. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  10647. return (new asn1js__namespace.Set({
  10648. name: (names.blockName || EMPTY_STRING),
  10649. value: [
  10650. new asn1js__namespace.Repeated({
  10651. name: (names.crls || EMPTY_STRING),
  10652. value: new asn1js__namespace.Choice({
  10653. value: [
  10654. CertificateRevocationList.schema(),
  10655. new asn1js__namespace.Constructed({
  10656. idBlock: {
  10657. tagClass: 3,
  10658. tagNumber: 1
  10659. },
  10660. value: [
  10661. new asn1js__namespace.ObjectIdentifier(),
  10662. new asn1js__namespace.Any()
  10663. ]
  10664. })
  10665. ]
  10666. })
  10667. })
  10668. ]
  10669. }));
  10670. }
  10671. fromSchema(schema) {
  10672. pvutils__namespace.clearProps(schema, CLEAR_PROPS$E);
  10673. const asn1 = asn1js__namespace.compareSchema(schema, schema, RevocationInfoChoices.schema({
  10674. names: {
  10675. crls: CRLS$3
  10676. }
  10677. }));
  10678. AsnError.assertSchema(asn1, this.className);
  10679. if (asn1.result.crls) {
  10680. for (const element of asn1.result.crls) {
  10681. if (element.idBlock.tagClass === 1)
  10682. this.crls.push(new CertificateRevocationList({ schema: element }));
  10683. else
  10684. this.otherRevocationInfos.push(new OtherRevocationInfoFormat({ schema: element }));
  10685. }
  10686. }
  10687. }
  10688. toSchema() {
  10689. const outputArray = [];
  10690. outputArray.push(...Array.from(this.crls, o => o.toSchema()));
  10691. outputArray.push(...Array.from(this.otherRevocationInfos, element => {
  10692. const schema = element.toSchema();
  10693. schema.idBlock.tagClass = 3;
  10694. schema.idBlock.tagNumber = 1;
  10695. return schema;
  10696. }));
  10697. return (new asn1js__namespace.Set({
  10698. value: outputArray
  10699. }));
  10700. }
  10701. toJSON() {
  10702. return {
  10703. crls: Array.from(this.crls, o => o.toJSON()),
  10704. otherRevocationInfos: Array.from(this.otherRevocationInfos, o => o.toJSON())
  10705. };
  10706. }
  10707. }
  10708. RevocationInfoChoices.CLASS_NAME = "RevocationInfoChoices";
  10709. const CERTS$3 = "certs";
  10710. const CRLS$2 = "crls";
  10711. const CLEAR_PROPS$D = [
  10712. CERTS$3,
  10713. CRLS$2,
  10714. ];
  10715. class OriginatorInfo extends PkiObject {
  10716. constructor(parameters = {}) {
  10717. super();
  10718. this.crls = pvutils__namespace.getParametersValue(parameters, CRLS$2, OriginatorInfo.defaultValues(CRLS$2));
  10719. if (parameters.schema) {
  10720. this.fromSchema(parameters.schema);
  10721. }
  10722. }
  10723. static defaultValues(memberName) {
  10724. switch (memberName) {
  10725. case CERTS$3:
  10726. return new CertificateSet();
  10727. case CRLS$2:
  10728. return new RevocationInfoChoices();
  10729. default:
  10730. return super.defaultValues(memberName);
  10731. }
  10732. }
  10733. static compareWithDefault(memberName, memberValue) {
  10734. switch (memberName) {
  10735. case CERTS$3:
  10736. return (memberValue.certificates.length === 0);
  10737. case CRLS$2:
  10738. return ((memberValue.crls.length === 0) && (memberValue.otherRevocationInfos.length === 0));
  10739. default:
  10740. return super.defaultValues(memberName);
  10741. }
  10742. }
  10743. static schema(parameters = {}) {
  10744. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  10745. return (new asn1js__namespace.Sequence({
  10746. name: (names.blockName || EMPTY_STRING),
  10747. value: [
  10748. new asn1js__namespace.Constructed({
  10749. name: (names.certs || EMPTY_STRING),
  10750. optional: true,
  10751. idBlock: {
  10752. tagClass: 3,
  10753. tagNumber: 0
  10754. },
  10755. value: CertificateSet.schema().valueBlock.value
  10756. }),
  10757. new asn1js__namespace.Constructed({
  10758. name: (names.crls || EMPTY_STRING),
  10759. optional: true,
  10760. idBlock: {
  10761. tagClass: 3,
  10762. tagNumber: 1
  10763. },
  10764. value: RevocationInfoChoices.schema().valueBlock.value
  10765. })
  10766. ]
  10767. }));
  10768. }
  10769. fromSchema(schema) {
  10770. pvutils__namespace.clearProps(schema, CLEAR_PROPS$D);
  10771. const asn1 = asn1js__namespace.compareSchema(schema, schema, OriginatorInfo.schema({
  10772. names: {
  10773. certs: CERTS$3,
  10774. crls: CRLS$2
  10775. }
  10776. }));
  10777. AsnError.assertSchema(asn1, this.className);
  10778. if (CERTS$3 in asn1.result) {
  10779. this.certs = new CertificateSet({
  10780. schema: new asn1js__namespace.Set({
  10781. value: asn1.result.certs.valueBlock.value
  10782. })
  10783. });
  10784. }
  10785. if (CRLS$2 in asn1.result) {
  10786. this.crls = new RevocationInfoChoices({
  10787. schema: new asn1js__namespace.Set({
  10788. value: asn1.result.crls.valueBlock.value
  10789. })
  10790. });
  10791. }
  10792. }
  10793. toSchema() {
  10794. const sequenceValue = [];
  10795. if (this.certs) {
  10796. sequenceValue.push(new asn1js__namespace.Constructed({
  10797. idBlock: {
  10798. tagClass: 3,
  10799. tagNumber: 0
  10800. },
  10801. value: this.certs.toSchema().valueBlock.value
  10802. }));
  10803. }
  10804. if (this.crls) {
  10805. sequenceValue.push(new asn1js__namespace.Constructed({
  10806. idBlock: {
  10807. tagClass: 3,
  10808. tagNumber: 1
  10809. },
  10810. value: this.crls.toSchema().valueBlock.value
  10811. }));
  10812. }
  10813. return (new asn1js__namespace.Sequence({
  10814. value: sequenceValue
  10815. }));
  10816. }
  10817. toJSON() {
  10818. const res = {};
  10819. if (this.certs) {
  10820. res.certs = this.certs.toJSON();
  10821. }
  10822. if (this.crls) {
  10823. res.crls = this.crls.toJSON();
  10824. }
  10825. return res;
  10826. }
  10827. }
  10828. OriginatorInfo.CLASS_NAME = "OriginatorInfo";
  10829. const ISSUER = "issuer";
  10830. const SERIAL_NUMBER$2 = "serialNumber";
  10831. const CLEAR_PROPS$C = [
  10832. ISSUER,
  10833. SERIAL_NUMBER$2,
  10834. ];
  10835. class IssuerAndSerialNumber extends PkiObject {
  10836. constructor(parameters = {}) {
  10837. super();
  10838. this.issuer = pvutils__namespace.getParametersValue(parameters, ISSUER, IssuerAndSerialNumber.defaultValues(ISSUER));
  10839. this.serialNumber = pvutils__namespace.getParametersValue(parameters, SERIAL_NUMBER$2, IssuerAndSerialNumber.defaultValues(SERIAL_NUMBER$2));
  10840. if (parameters.schema) {
  10841. this.fromSchema(parameters.schema);
  10842. }
  10843. }
  10844. static defaultValues(memberName) {
  10845. switch (memberName) {
  10846. case ISSUER:
  10847. return new RelativeDistinguishedNames();
  10848. case SERIAL_NUMBER$2:
  10849. return new asn1js__namespace.Integer();
  10850. default:
  10851. return super.defaultValues(memberName);
  10852. }
  10853. }
  10854. static schema(parameters = {}) {
  10855. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  10856. return (new asn1js__namespace.Sequence({
  10857. name: (names.blockName || EMPTY_STRING),
  10858. value: [
  10859. RelativeDistinguishedNames.schema(names.issuer || {}),
  10860. new asn1js__namespace.Integer({ name: (names.serialNumber || EMPTY_STRING) })
  10861. ]
  10862. }));
  10863. }
  10864. fromSchema(schema) {
  10865. pvutils__namespace.clearProps(schema, CLEAR_PROPS$C);
  10866. const asn1 = asn1js__namespace.compareSchema(schema, schema, IssuerAndSerialNumber.schema({
  10867. names: {
  10868. issuer: {
  10869. names: {
  10870. blockName: ISSUER
  10871. }
  10872. },
  10873. serialNumber: SERIAL_NUMBER$2
  10874. }
  10875. }));
  10876. AsnError.assertSchema(asn1, this.className);
  10877. this.issuer = new RelativeDistinguishedNames({ schema: asn1.result.issuer });
  10878. this.serialNumber = asn1.result.serialNumber;
  10879. }
  10880. toSchema() {
  10881. return (new asn1js__namespace.Sequence({
  10882. value: [
  10883. this.issuer.toSchema(),
  10884. this.serialNumber
  10885. ]
  10886. }));
  10887. }
  10888. toJSON() {
  10889. return {
  10890. issuer: this.issuer.toJSON(),
  10891. serialNumber: this.serialNumber.toJSON(),
  10892. };
  10893. }
  10894. }
  10895. IssuerAndSerialNumber.CLASS_NAME = "IssuerAndSerialNumber";
  10896. const VARIANT$3 = "variant";
  10897. const VALUE$3 = "value";
  10898. const CLEAR_PROPS$B = [
  10899. "blockName"
  10900. ];
  10901. class RecipientIdentifier extends PkiObject {
  10902. constructor(parameters = {}) {
  10903. super();
  10904. this.variant = pvutils__namespace.getParametersValue(parameters, VARIANT$3, RecipientIdentifier.defaultValues(VARIANT$3));
  10905. if (VALUE$3 in parameters) {
  10906. this.value = pvutils__namespace.getParametersValue(parameters, VALUE$3, RecipientIdentifier.defaultValues(VALUE$3));
  10907. }
  10908. if (parameters.schema) {
  10909. this.fromSchema(parameters.schema);
  10910. }
  10911. }
  10912. static defaultValues(memberName) {
  10913. switch (memberName) {
  10914. case VARIANT$3:
  10915. return (-1);
  10916. case VALUE$3:
  10917. return {};
  10918. default:
  10919. return super.defaultValues(memberName);
  10920. }
  10921. }
  10922. static compareWithDefault(memberName, memberValue) {
  10923. switch (memberName) {
  10924. case VARIANT$3:
  10925. return (memberValue === (-1));
  10926. case VALUE$3:
  10927. return (Object.keys(memberValue).length === 0);
  10928. default:
  10929. return super.defaultValues(memberName);
  10930. }
  10931. }
  10932. static schema(parameters = {}) {
  10933. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  10934. return (new asn1js__namespace.Choice({
  10935. value: [
  10936. IssuerAndSerialNumber.schema({
  10937. names: {
  10938. blockName: (names.blockName || EMPTY_STRING)
  10939. }
  10940. }),
  10941. new asn1js__namespace.Primitive({
  10942. name: (names.blockName || EMPTY_STRING),
  10943. idBlock: {
  10944. tagClass: 3,
  10945. tagNumber: 0
  10946. }
  10947. })
  10948. ]
  10949. }));
  10950. }
  10951. fromSchema(schema) {
  10952. pvutils__namespace.clearProps(schema, CLEAR_PROPS$B);
  10953. const asn1 = asn1js__namespace.compareSchema(schema, schema, RecipientIdentifier.schema({
  10954. names: {
  10955. blockName: "blockName"
  10956. }
  10957. }));
  10958. AsnError.assertSchema(asn1, this.className);
  10959. if (asn1.result.blockName.idBlock.tagClass === 1) {
  10960. this.variant = 1;
  10961. this.value = new IssuerAndSerialNumber({ schema: asn1.result.blockName });
  10962. }
  10963. else {
  10964. this.variant = 2;
  10965. this.value = new asn1js__namespace.OctetString({ valueHex: asn1.result.blockName.valueBlock.valueHex });
  10966. }
  10967. }
  10968. toSchema() {
  10969. switch (this.variant) {
  10970. case 1:
  10971. if (!(this.value instanceof IssuerAndSerialNumber)) {
  10972. throw new Error("Incorrect type of RecipientIdentifier.value. It should be IssuerAndSerialNumber.");
  10973. }
  10974. return this.value.toSchema();
  10975. case 2:
  10976. if (!(this.value instanceof asn1js__namespace.OctetString)) {
  10977. throw new Error("Incorrect type of RecipientIdentifier.value. It should be ASN.1 OctetString.");
  10978. }
  10979. return new asn1js__namespace.Primitive({
  10980. idBlock: {
  10981. tagClass: 3,
  10982. tagNumber: 0
  10983. },
  10984. valueHex: this.value.valueBlock.valueHexView
  10985. });
  10986. default:
  10987. return new asn1js__namespace.Any();
  10988. }
  10989. }
  10990. toJSON() {
  10991. const res = {
  10992. variant: this.variant
  10993. };
  10994. if ((this.variant === 1 || this.variant === 2) && this.value) {
  10995. res.value = this.value.toJSON();
  10996. }
  10997. return res;
  10998. }
  10999. }
  11000. RecipientIdentifier.CLASS_NAME = "RecipientIdentifier";
  11001. const VERSION$c = "version";
  11002. const RID$1 = "rid";
  11003. const KEY_ENCRYPTION_ALGORITHM$3 = "keyEncryptionAlgorithm";
  11004. const ENCRYPTED_KEY$3 = "encryptedKey";
  11005. const RECIPIENT_CERTIFICATE$1 = "recipientCertificate";
  11006. const CLEAR_PROPS$A = [
  11007. VERSION$c,
  11008. RID$1,
  11009. KEY_ENCRYPTION_ALGORITHM$3,
  11010. ENCRYPTED_KEY$3,
  11011. ];
  11012. class KeyTransRecipientInfo extends PkiObject {
  11013. constructor(parameters = {}) {
  11014. super();
  11015. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$c, KeyTransRecipientInfo.defaultValues(VERSION$c));
  11016. this.rid = pvutils__namespace.getParametersValue(parameters, RID$1, KeyTransRecipientInfo.defaultValues(RID$1));
  11017. this.keyEncryptionAlgorithm = pvutils__namespace.getParametersValue(parameters, KEY_ENCRYPTION_ALGORITHM$3, KeyTransRecipientInfo.defaultValues(KEY_ENCRYPTION_ALGORITHM$3));
  11018. this.encryptedKey = pvutils__namespace.getParametersValue(parameters, ENCRYPTED_KEY$3, KeyTransRecipientInfo.defaultValues(ENCRYPTED_KEY$3));
  11019. this.recipientCertificate = pvutils__namespace.getParametersValue(parameters, RECIPIENT_CERTIFICATE$1, KeyTransRecipientInfo.defaultValues(RECIPIENT_CERTIFICATE$1));
  11020. if (parameters.schema) {
  11021. this.fromSchema(parameters.schema);
  11022. }
  11023. }
  11024. static defaultValues(memberName) {
  11025. switch (memberName) {
  11026. case VERSION$c:
  11027. return (-1);
  11028. case RID$1:
  11029. return {};
  11030. case KEY_ENCRYPTION_ALGORITHM$3:
  11031. return new AlgorithmIdentifier();
  11032. case ENCRYPTED_KEY$3:
  11033. return new asn1js__namespace.OctetString();
  11034. case RECIPIENT_CERTIFICATE$1:
  11035. return new Certificate();
  11036. default:
  11037. return super.defaultValues(memberName);
  11038. }
  11039. }
  11040. static compareWithDefault(memberName, memberValue) {
  11041. switch (memberName) {
  11042. case VERSION$c:
  11043. return (memberValue === KeyTransRecipientInfo.defaultValues(VERSION$c));
  11044. case RID$1:
  11045. return (Object.keys(memberValue).length === 0);
  11046. case KEY_ENCRYPTION_ALGORITHM$3:
  11047. case ENCRYPTED_KEY$3:
  11048. return memberValue.isEqual(KeyTransRecipientInfo.defaultValues(memberName));
  11049. case RECIPIENT_CERTIFICATE$1:
  11050. return false;
  11051. default:
  11052. return super.defaultValues(memberName);
  11053. }
  11054. }
  11055. static schema(parameters = {}) {
  11056. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  11057. return (new asn1js__namespace.Sequence({
  11058. name: (names.blockName || EMPTY_STRING),
  11059. value: [
  11060. new asn1js__namespace.Integer({ name: (names.version || EMPTY_STRING) }),
  11061. RecipientIdentifier.schema(names.rid || {}),
  11062. AlgorithmIdentifier.schema(names.keyEncryptionAlgorithm || {}),
  11063. new asn1js__namespace.OctetString({ name: (names.encryptedKey || EMPTY_STRING) })
  11064. ]
  11065. }));
  11066. }
  11067. fromSchema(schema) {
  11068. pvutils__namespace.clearProps(schema, CLEAR_PROPS$A);
  11069. const asn1 = asn1js__namespace.compareSchema(schema, schema, KeyTransRecipientInfo.schema({
  11070. names: {
  11071. version: VERSION$c,
  11072. rid: {
  11073. names: {
  11074. blockName: RID$1
  11075. }
  11076. },
  11077. keyEncryptionAlgorithm: {
  11078. names: {
  11079. blockName: KEY_ENCRYPTION_ALGORITHM$3
  11080. }
  11081. },
  11082. encryptedKey: ENCRYPTED_KEY$3
  11083. }
  11084. }));
  11085. AsnError.assertSchema(asn1, this.className);
  11086. this.version = asn1.result.version.valueBlock.valueDec;
  11087. if (asn1.result.rid.idBlock.tagClass === 3) {
  11088. this.rid = new asn1js__namespace.OctetString({ valueHex: asn1.result.rid.valueBlock.valueHex });
  11089. }
  11090. else {
  11091. this.rid = new IssuerAndSerialNumber({ schema: asn1.result.rid });
  11092. }
  11093. this.keyEncryptionAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.keyEncryptionAlgorithm });
  11094. this.encryptedKey = asn1.result.encryptedKey;
  11095. }
  11096. toSchema() {
  11097. const outputArray = [];
  11098. if (this.rid instanceof IssuerAndSerialNumber) {
  11099. this.version = 0;
  11100. outputArray.push(new asn1js__namespace.Integer({ value: this.version }));
  11101. outputArray.push(this.rid.toSchema());
  11102. }
  11103. else {
  11104. this.version = 2;
  11105. outputArray.push(new asn1js__namespace.Integer({ value: this.version }));
  11106. outputArray.push(new asn1js__namespace.Primitive({
  11107. idBlock: {
  11108. tagClass: 3,
  11109. tagNumber: 0
  11110. },
  11111. valueHex: this.rid.valueBlock.valueHexView
  11112. }));
  11113. }
  11114. outputArray.push(this.keyEncryptionAlgorithm.toSchema());
  11115. outputArray.push(this.encryptedKey);
  11116. return (new asn1js__namespace.Sequence({
  11117. value: outputArray
  11118. }));
  11119. }
  11120. toJSON() {
  11121. return {
  11122. version: this.version,
  11123. rid: this.rid.toJSON(),
  11124. keyEncryptionAlgorithm: this.keyEncryptionAlgorithm.toJSON(),
  11125. encryptedKey: this.encryptedKey.toJSON(),
  11126. };
  11127. }
  11128. }
  11129. KeyTransRecipientInfo.CLASS_NAME = "KeyTransRecipientInfo";
  11130. const ALGORITHM = "algorithm";
  11131. const PUBLIC_KEY = "publicKey";
  11132. const CLEAR_PROPS$z = [
  11133. ALGORITHM,
  11134. PUBLIC_KEY
  11135. ];
  11136. class OriginatorPublicKey extends PkiObject {
  11137. constructor(parameters = {}) {
  11138. super();
  11139. this.algorithm = pvutils__namespace.getParametersValue(parameters, ALGORITHM, OriginatorPublicKey.defaultValues(ALGORITHM));
  11140. this.publicKey = pvutils__namespace.getParametersValue(parameters, PUBLIC_KEY, OriginatorPublicKey.defaultValues(PUBLIC_KEY));
  11141. if (parameters.schema) {
  11142. this.fromSchema(parameters.schema);
  11143. }
  11144. }
  11145. static defaultValues(memberName) {
  11146. switch (memberName) {
  11147. case ALGORITHM:
  11148. return new AlgorithmIdentifier();
  11149. case PUBLIC_KEY:
  11150. return new asn1js__namespace.BitString();
  11151. default:
  11152. return super.defaultValues(memberName);
  11153. }
  11154. }
  11155. static compareWithDefault(memberName, memberValue) {
  11156. switch (memberName) {
  11157. case ALGORITHM:
  11158. case PUBLIC_KEY:
  11159. return (memberValue.isEqual(OriginatorPublicKey.defaultValues(memberName)));
  11160. default:
  11161. return super.defaultValues(memberName);
  11162. }
  11163. }
  11164. static schema(parameters = {}) {
  11165. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  11166. return (new asn1js__namespace.Sequence({
  11167. name: (names.blockName || EMPTY_STRING),
  11168. value: [
  11169. AlgorithmIdentifier.schema(names.algorithm || {}),
  11170. new asn1js__namespace.BitString({ name: (names.publicKey || EMPTY_STRING) })
  11171. ]
  11172. }));
  11173. }
  11174. fromSchema(schema) {
  11175. pvutils__namespace.clearProps(schema, CLEAR_PROPS$z);
  11176. const asn1 = asn1js__namespace.compareSchema(schema, schema, OriginatorPublicKey.schema({
  11177. names: {
  11178. algorithm: {
  11179. names: {
  11180. blockName: ALGORITHM
  11181. }
  11182. },
  11183. publicKey: PUBLIC_KEY
  11184. }
  11185. }));
  11186. AsnError.assertSchema(asn1, this.className);
  11187. this.algorithm = new AlgorithmIdentifier({ schema: asn1.result.algorithm });
  11188. this.publicKey = asn1.result.publicKey;
  11189. }
  11190. toSchema() {
  11191. return (new asn1js__namespace.Sequence({
  11192. value: [
  11193. this.algorithm.toSchema(),
  11194. this.publicKey
  11195. ]
  11196. }));
  11197. }
  11198. toJSON() {
  11199. return {
  11200. algorithm: this.algorithm.toJSON(),
  11201. publicKey: this.publicKey.toJSON(),
  11202. };
  11203. }
  11204. }
  11205. OriginatorPublicKey.CLASS_NAME = "OriginatorPublicKey";
  11206. const VARIANT$2 = "variant";
  11207. const VALUE$2 = "value";
  11208. const CLEAR_PROPS$y = [
  11209. "blockName",
  11210. ];
  11211. class OriginatorIdentifierOrKey extends PkiObject {
  11212. constructor(parameters = {}) {
  11213. super();
  11214. this.variant = pvutils__namespace.getParametersValue(parameters, VARIANT$2, OriginatorIdentifierOrKey.defaultValues(VARIANT$2));
  11215. if (VALUE$2 in parameters) {
  11216. this.value = pvutils__namespace.getParametersValue(parameters, VALUE$2, OriginatorIdentifierOrKey.defaultValues(VALUE$2));
  11217. }
  11218. if (parameters.schema) {
  11219. this.fromSchema(parameters.schema);
  11220. }
  11221. }
  11222. static defaultValues(memberName) {
  11223. switch (memberName) {
  11224. case VARIANT$2:
  11225. return (-1);
  11226. case VALUE$2:
  11227. return {};
  11228. default:
  11229. return super.defaultValues(memberName);
  11230. }
  11231. }
  11232. static compareWithDefault(memberName, memberValue) {
  11233. switch (memberName) {
  11234. case VARIANT$2:
  11235. return (memberValue === (-1));
  11236. case VALUE$2:
  11237. return (Object.keys(memberValue).length === 0);
  11238. default:
  11239. return super.defaultValues(memberName);
  11240. }
  11241. }
  11242. static schema(parameters = {}) {
  11243. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  11244. return (new asn1js__namespace.Choice({
  11245. value: [
  11246. IssuerAndSerialNumber.schema({
  11247. names: {
  11248. blockName: (names.blockName || EMPTY_STRING)
  11249. }
  11250. }),
  11251. new asn1js__namespace.Primitive({
  11252. idBlock: {
  11253. tagClass: 3,
  11254. tagNumber: 0
  11255. },
  11256. name: (names.blockName || EMPTY_STRING)
  11257. }),
  11258. new asn1js__namespace.Constructed({
  11259. idBlock: {
  11260. tagClass: 3,
  11261. tagNumber: 1
  11262. },
  11263. name: (names.blockName || EMPTY_STRING),
  11264. value: OriginatorPublicKey.schema().valueBlock.value
  11265. })
  11266. ]
  11267. }));
  11268. }
  11269. fromSchema(schema) {
  11270. pvutils__namespace.clearProps(schema, CLEAR_PROPS$y);
  11271. const asn1 = asn1js__namespace.compareSchema(schema, schema, OriginatorIdentifierOrKey.schema({
  11272. names: {
  11273. blockName: "blockName"
  11274. }
  11275. }));
  11276. AsnError.assertSchema(asn1, this.className);
  11277. if (asn1.result.blockName.idBlock.tagClass === 1) {
  11278. this.variant = 1;
  11279. this.value = new IssuerAndSerialNumber({ schema: asn1.result.blockName });
  11280. }
  11281. else {
  11282. if (asn1.result.blockName.idBlock.tagNumber === 0) {
  11283. asn1.result.blockName.idBlock.tagClass = 1;
  11284. asn1.result.blockName.idBlock.tagNumber = 4;
  11285. this.variant = 2;
  11286. this.value = asn1.result.blockName;
  11287. }
  11288. else {
  11289. this.variant = 3;
  11290. this.value = new OriginatorPublicKey({
  11291. schema: new asn1js__namespace.Sequence({
  11292. value: asn1.result.blockName.valueBlock.value
  11293. })
  11294. });
  11295. }
  11296. }
  11297. }
  11298. toSchema() {
  11299. switch (this.variant) {
  11300. case 1:
  11301. return this.value.toSchema();
  11302. case 2:
  11303. this.value.idBlock.tagClass = 3;
  11304. this.value.idBlock.tagNumber = 0;
  11305. return this.value;
  11306. case 3:
  11307. {
  11308. const _schema = this.value.toSchema();
  11309. _schema.idBlock.tagClass = 3;
  11310. _schema.idBlock.tagNumber = 1;
  11311. return _schema;
  11312. }
  11313. default:
  11314. return new asn1js__namespace.Any();
  11315. }
  11316. }
  11317. toJSON() {
  11318. const res = {
  11319. variant: this.variant
  11320. };
  11321. if ((this.variant === 1) || (this.variant === 2) || (this.variant === 3)) {
  11322. res.value = this.value.toJSON();
  11323. }
  11324. return res;
  11325. }
  11326. }
  11327. OriginatorIdentifierOrKey.CLASS_NAME = "OriginatorIdentifierOrKey";
  11328. const KEY_ATTR_ID = "keyAttrId";
  11329. const KEY_ATTR = "keyAttr";
  11330. const CLEAR_PROPS$x = [
  11331. KEY_ATTR_ID,
  11332. KEY_ATTR,
  11333. ];
  11334. class OtherKeyAttribute extends PkiObject {
  11335. constructor(parameters = {}) {
  11336. super();
  11337. this.keyAttrId = pvutils__namespace.getParametersValue(parameters, KEY_ATTR_ID, OtherKeyAttribute.defaultValues(KEY_ATTR_ID));
  11338. if (KEY_ATTR in parameters) {
  11339. this.keyAttr = pvutils__namespace.getParametersValue(parameters, KEY_ATTR, OtherKeyAttribute.defaultValues(KEY_ATTR));
  11340. }
  11341. if (parameters.schema) {
  11342. this.fromSchema(parameters.schema);
  11343. }
  11344. }
  11345. static defaultValues(memberName) {
  11346. switch (memberName) {
  11347. case KEY_ATTR_ID:
  11348. return EMPTY_STRING;
  11349. case KEY_ATTR:
  11350. return {};
  11351. default:
  11352. return super.defaultValues(memberName);
  11353. }
  11354. }
  11355. static compareWithDefault(memberName, memberValue) {
  11356. switch (memberName) {
  11357. case KEY_ATTR_ID:
  11358. return (typeof memberValue === "string" && memberValue === EMPTY_STRING);
  11359. case KEY_ATTR:
  11360. return (Object.keys(memberValue).length === 0);
  11361. default:
  11362. return super.defaultValues(memberName);
  11363. }
  11364. }
  11365. static schema(parameters = {}) {
  11366. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  11367. return (new asn1js__namespace.Sequence({
  11368. optional: (names.optional || true),
  11369. name: (names.blockName || EMPTY_STRING),
  11370. value: [
  11371. new asn1js__namespace.ObjectIdentifier({ name: (names.keyAttrId || EMPTY_STRING) }),
  11372. new asn1js__namespace.Any({
  11373. optional: true,
  11374. name: (names.keyAttr || EMPTY_STRING)
  11375. })
  11376. ]
  11377. }));
  11378. }
  11379. fromSchema(schema) {
  11380. pvutils__namespace.clearProps(schema, CLEAR_PROPS$x);
  11381. const asn1 = asn1js__namespace.compareSchema(schema, schema, OtherKeyAttribute.schema({
  11382. names: {
  11383. keyAttrId: KEY_ATTR_ID,
  11384. keyAttr: KEY_ATTR
  11385. }
  11386. }));
  11387. AsnError.assertSchema(asn1, this.className);
  11388. this.keyAttrId = asn1.result.keyAttrId.valueBlock.toString();
  11389. if (KEY_ATTR in asn1.result) {
  11390. this.keyAttr = asn1.result.keyAttr;
  11391. }
  11392. }
  11393. toSchema() {
  11394. const outputArray = [];
  11395. outputArray.push(new asn1js__namespace.ObjectIdentifier({ value: this.keyAttrId }));
  11396. if (KEY_ATTR in this) {
  11397. outputArray.push(this.keyAttr);
  11398. }
  11399. return (new asn1js__namespace.Sequence({
  11400. value: outputArray,
  11401. }));
  11402. }
  11403. toJSON() {
  11404. const res = {
  11405. keyAttrId: this.keyAttrId
  11406. };
  11407. if (KEY_ATTR in this) {
  11408. res.keyAttr = this.keyAttr.toJSON();
  11409. }
  11410. return res;
  11411. }
  11412. }
  11413. OtherKeyAttribute.CLASS_NAME = "OtherKeyAttribute";
  11414. const SUBJECT_KEY_IDENTIFIER = "subjectKeyIdentifier";
  11415. const DATE$1 = "date";
  11416. const OTHER$1 = "other";
  11417. const CLEAR_PROPS$w = [
  11418. SUBJECT_KEY_IDENTIFIER,
  11419. DATE$1,
  11420. OTHER$1,
  11421. ];
  11422. class RecipientKeyIdentifier extends PkiObject {
  11423. constructor(parameters = {}) {
  11424. super();
  11425. this.subjectKeyIdentifier = pvutils__namespace.getParametersValue(parameters, SUBJECT_KEY_IDENTIFIER, RecipientKeyIdentifier.defaultValues(SUBJECT_KEY_IDENTIFIER));
  11426. if (DATE$1 in parameters) {
  11427. this.date = pvutils__namespace.getParametersValue(parameters, DATE$1, RecipientKeyIdentifier.defaultValues(DATE$1));
  11428. }
  11429. if (OTHER$1 in parameters) {
  11430. this.other = pvutils__namespace.getParametersValue(parameters, OTHER$1, RecipientKeyIdentifier.defaultValues(OTHER$1));
  11431. }
  11432. if (parameters.schema) {
  11433. this.fromSchema(parameters.schema);
  11434. }
  11435. }
  11436. static defaultValues(memberName) {
  11437. switch (memberName) {
  11438. case SUBJECT_KEY_IDENTIFIER:
  11439. return new asn1js__namespace.OctetString();
  11440. case DATE$1:
  11441. return new asn1js__namespace.GeneralizedTime();
  11442. case OTHER$1:
  11443. return new OtherKeyAttribute();
  11444. default:
  11445. return super.defaultValues(memberName);
  11446. }
  11447. }
  11448. static compareWithDefault(memberName, memberValue) {
  11449. switch (memberName) {
  11450. case SUBJECT_KEY_IDENTIFIER:
  11451. return (memberValue.isEqual(RecipientKeyIdentifier.defaultValues(SUBJECT_KEY_IDENTIFIER)));
  11452. case DATE$1:
  11453. return ((memberValue.year === 0) &&
  11454. (memberValue.month === 0) &&
  11455. (memberValue.day === 0) &&
  11456. (memberValue.hour === 0) &&
  11457. (memberValue.minute === 0) &&
  11458. (memberValue.second === 0) &&
  11459. (memberValue.millisecond === 0));
  11460. case OTHER$1:
  11461. return ((memberValue.keyAttrId === EMPTY_STRING) && (("keyAttr" in memberValue) === false));
  11462. default:
  11463. return super.defaultValues(memberName);
  11464. }
  11465. }
  11466. static schema(parameters = {}) {
  11467. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  11468. return (new asn1js__namespace.Sequence({
  11469. name: (names.blockName || EMPTY_STRING),
  11470. value: [
  11471. new asn1js__namespace.OctetString({ name: (names.subjectKeyIdentifier || EMPTY_STRING) }),
  11472. new asn1js__namespace.GeneralizedTime({
  11473. optional: true,
  11474. name: (names.date || EMPTY_STRING)
  11475. }),
  11476. OtherKeyAttribute.schema(names.other || {})
  11477. ]
  11478. }));
  11479. }
  11480. fromSchema(schema) {
  11481. pvutils__namespace.clearProps(schema, CLEAR_PROPS$w);
  11482. const asn1 = asn1js__namespace.compareSchema(schema, schema, RecipientKeyIdentifier.schema({
  11483. names: {
  11484. subjectKeyIdentifier: SUBJECT_KEY_IDENTIFIER,
  11485. date: DATE$1,
  11486. other: {
  11487. names: {
  11488. blockName: OTHER$1
  11489. }
  11490. }
  11491. }
  11492. }));
  11493. AsnError.assertSchema(asn1, this.className);
  11494. this.subjectKeyIdentifier = asn1.result.subjectKeyIdentifier;
  11495. if (DATE$1 in asn1.result)
  11496. this.date = asn1.result.date;
  11497. if (OTHER$1 in asn1.result)
  11498. this.other = new OtherKeyAttribute({ schema: asn1.result.other });
  11499. }
  11500. toSchema() {
  11501. const outputArray = [];
  11502. outputArray.push(this.subjectKeyIdentifier);
  11503. if (this.date) {
  11504. outputArray.push(this.date);
  11505. }
  11506. if (this.other) {
  11507. outputArray.push(this.other.toSchema());
  11508. }
  11509. return (new asn1js__namespace.Sequence({
  11510. value: outputArray
  11511. }));
  11512. }
  11513. toJSON() {
  11514. const res = {
  11515. subjectKeyIdentifier: this.subjectKeyIdentifier.toJSON()
  11516. };
  11517. if (this.date) {
  11518. res.date = this.date.toJSON();
  11519. }
  11520. if (this.other) {
  11521. res.other = this.other.toJSON();
  11522. }
  11523. return res;
  11524. }
  11525. }
  11526. RecipientKeyIdentifier.CLASS_NAME = "RecipientKeyIdentifier";
  11527. const VARIANT$1 = "variant";
  11528. const VALUE$1 = "value";
  11529. const CLEAR_PROPS$v = [
  11530. "blockName",
  11531. ];
  11532. class KeyAgreeRecipientIdentifier extends PkiObject {
  11533. constructor(parameters = {}) {
  11534. super();
  11535. this.variant = pvutils__namespace.getParametersValue(parameters, VARIANT$1, KeyAgreeRecipientIdentifier.defaultValues(VARIANT$1));
  11536. this.value = pvutils__namespace.getParametersValue(parameters, VALUE$1, KeyAgreeRecipientIdentifier.defaultValues(VALUE$1));
  11537. if (parameters.schema) {
  11538. this.fromSchema(parameters.schema);
  11539. }
  11540. }
  11541. static defaultValues(memberName) {
  11542. switch (memberName) {
  11543. case VARIANT$1:
  11544. return (-1);
  11545. case VALUE$1:
  11546. return {};
  11547. default:
  11548. return super.defaultValues(memberName);
  11549. }
  11550. }
  11551. static compareWithDefault(memberName, memberValue) {
  11552. switch (memberName) {
  11553. case VARIANT$1:
  11554. return (memberValue === (-1));
  11555. case VALUE$1:
  11556. return (Object.keys(memberValue).length === 0);
  11557. default:
  11558. return super.defaultValues(memberName);
  11559. }
  11560. }
  11561. static schema(parameters = {}) {
  11562. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  11563. return (new asn1js__namespace.Choice({
  11564. value: [
  11565. IssuerAndSerialNumber.schema(names.issuerAndSerialNumber || {
  11566. names: {
  11567. blockName: (names.blockName || EMPTY_STRING)
  11568. }
  11569. }),
  11570. new asn1js__namespace.Constructed({
  11571. name: (names.blockName || EMPTY_STRING),
  11572. idBlock: {
  11573. tagClass: 3,
  11574. tagNumber: 0
  11575. },
  11576. value: RecipientKeyIdentifier.schema(names.rKeyId || {
  11577. names: {
  11578. blockName: (names.blockName || EMPTY_STRING)
  11579. }
  11580. }).valueBlock.value
  11581. })
  11582. ]
  11583. }));
  11584. }
  11585. fromSchema(schema) {
  11586. pvutils__namespace.clearProps(schema, CLEAR_PROPS$v);
  11587. const asn1 = asn1js__namespace.compareSchema(schema, schema, KeyAgreeRecipientIdentifier.schema({
  11588. names: {
  11589. blockName: "blockName"
  11590. }
  11591. }));
  11592. AsnError.assertSchema(asn1, this.className);
  11593. if (asn1.result.blockName.idBlock.tagClass === 1) {
  11594. this.variant = 1;
  11595. this.value = new IssuerAndSerialNumber({ schema: asn1.result.blockName });
  11596. }
  11597. else {
  11598. this.variant = 2;
  11599. this.value = new RecipientKeyIdentifier({
  11600. schema: new asn1js__namespace.Sequence({
  11601. value: asn1.result.blockName.valueBlock.value
  11602. })
  11603. });
  11604. }
  11605. }
  11606. toSchema() {
  11607. switch (this.variant) {
  11608. case 1:
  11609. return this.value.toSchema();
  11610. case 2:
  11611. return new asn1js__namespace.Constructed({
  11612. idBlock: {
  11613. tagClass: 3,
  11614. tagNumber: 0
  11615. },
  11616. value: this.value.toSchema().valueBlock.value
  11617. });
  11618. default:
  11619. return new asn1js__namespace.Any();
  11620. }
  11621. }
  11622. toJSON() {
  11623. const res = {
  11624. variant: this.variant,
  11625. };
  11626. if ((this.variant === 1) || (this.variant === 2)) {
  11627. res.value = this.value.toJSON();
  11628. }
  11629. return res;
  11630. }
  11631. }
  11632. KeyAgreeRecipientIdentifier.CLASS_NAME = "KeyAgreeRecipientIdentifier";
  11633. const RID = "rid";
  11634. const ENCRYPTED_KEY$2 = "encryptedKey";
  11635. const CLEAR_PROPS$u = [
  11636. RID,
  11637. ENCRYPTED_KEY$2,
  11638. ];
  11639. class RecipientEncryptedKey extends PkiObject {
  11640. constructor(parameters = {}) {
  11641. super();
  11642. this.rid = pvutils__namespace.getParametersValue(parameters, RID, RecipientEncryptedKey.defaultValues(RID));
  11643. this.encryptedKey = pvutils__namespace.getParametersValue(parameters, ENCRYPTED_KEY$2, RecipientEncryptedKey.defaultValues(ENCRYPTED_KEY$2));
  11644. if (parameters.schema) {
  11645. this.fromSchema(parameters.schema);
  11646. }
  11647. }
  11648. static defaultValues(memberName) {
  11649. switch (memberName) {
  11650. case RID:
  11651. return new KeyAgreeRecipientIdentifier();
  11652. case ENCRYPTED_KEY$2:
  11653. return new asn1js__namespace.OctetString();
  11654. default:
  11655. return super.defaultValues(memberName);
  11656. }
  11657. }
  11658. static compareWithDefault(memberName, memberValue) {
  11659. switch (memberName) {
  11660. case RID:
  11661. return ((memberValue.variant === (-1)) && (("value" in memberValue) === false));
  11662. case ENCRYPTED_KEY$2:
  11663. return (memberValue.isEqual(RecipientEncryptedKey.defaultValues(ENCRYPTED_KEY$2)));
  11664. default:
  11665. return super.defaultValues(memberName);
  11666. }
  11667. }
  11668. static schema(parameters = {}) {
  11669. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  11670. return (new asn1js__namespace.Sequence({
  11671. name: (names.blockName || EMPTY_STRING),
  11672. value: [
  11673. KeyAgreeRecipientIdentifier.schema(names.rid || {}),
  11674. new asn1js__namespace.OctetString({ name: (names.encryptedKey || EMPTY_STRING) })
  11675. ]
  11676. }));
  11677. }
  11678. fromSchema(schema) {
  11679. pvutils__namespace.clearProps(schema, CLEAR_PROPS$u);
  11680. const asn1 = asn1js__namespace.compareSchema(schema, schema, RecipientEncryptedKey.schema({
  11681. names: {
  11682. rid: {
  11683. names: {
  11684. blockName: RID
  11685. }
  11686. },
  11687. encryptedKey: ENCRYPTED_KEY$2
  11688. }
  11689. }));
  11690. AsnError.assertSchema(asn1, this.className);
  11691. this.rid = new KeyAgreeRecipientIdentifier({ schema: asn1.result.rid });
  11692. this.encryptedKey = asn1.result.encryptedKey;
  11693. }
  11694. toSchema() {
  11695. return (new asn1js__namespace.Sequence({
  11696. value: [
  11697. this.rid.toSchema(),
  11698. this.encryptedKey
  11699. ]
  11700. }));
  11701. }
  11702. toJSON() {
  11703. return {
  11704. rid: this.rid.toJSON(),
  11705. encryptedKey: this.encryptedKey.toJSON(),
  11706. };
  11707. }
  11708. }
  11709. RecipientEncryptedKey.CLASS_NAME = "RecipientEncryptedKey";
  11710. const ENCRYPTED_KEYS = "encryptedKeys";
  11711. const RECIPIENT_ENCRYPTED_KEYS = "RecipientEncryptedKeys";
  11712. const CLEAR_PROPS$t = [
  11713. RECIPIENT_ENCRYPTED_KEYS,
  11714. ];
  11715. class RecipientEncryptedKeys extends PkiObject {
  11716. constructor(parameters = {}) {
  11717. super();
  11718. this.encryptedKeys = pvutils__namespace.getParametersValue(parameters, ENCRYPTED_KEYS, RecipientEncryptedKeys.defaultValues(ENCRYPTED_KEYS));
  11719. if (parameters.schema) {
  11720. this.fromSchema(parameters.schema);
  11721. }
  11722. }
  11723. static defaultValues(memberName) {
  11724. switch (memberName) {
  11725. case ENCRYPTED_KEYS:
  11726. return [];
  11727. default:
  11728. return super.defaultValues(memberName);
  11729. }
  11730. }
  11731. static compareWithDefault(memberName, memberValue) {
  11732. switch (memberName) {
  11733. case ENCRYPTED_KEYS:
  11734. return (memberValue.length === 0);
  11735. default:
  11736. return super.defaultValues(memberName);
  11737. }
  11738. }
  11739. static schema(parameters = {}) {
  11740. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  11741. return (new asn1js__namespace.Sequence({
  11742. name: (names.blockName || EMPTY_STRING),
  11743. value: [
  11744. new asn1js__namespace.Repeated({
  11745. name: (names.RecipientEncryptedKeys || EMPTY_STRING),
  11746. value: RecipientEncryptedKey.schema()
  11747. })
  11748. ]
  11749. }));
  11750. }
  11751. fromSchema(schema) {
  11752. pvutils__namespace.clearProps(schema, CLEAR_PROPS$t);
  11753. const asn1 = asn1js__namespace.compareSchema(schema, schema, RecipientEncryptedKeys.schema({
  11754. names: {
  11755. RecipientEncryptedKeys: RECIPIENT_ENCRYPTED_KEYS
  11756. }
  11757. }));
  11758. AsnError.assertSchema(asn1, this.className);
  11759. this.encryptedKeys = Array.from(asn1.result.RecipientEncryptedKeys, element => new RecipientEncryptedKey({ schema: element }));
  11760. }
  11761. toSchema() {
  11762. return (new asn1js__namespace.Sequence({
  11763. value: Array.from(this.encryptedKeys, o => o.toSchema())
  11764. }));
  11765. }
  11766. toJSON() {
  11767. return {
  11768. encryptedKeys: Array.from(this.encryptedKeys, o => o.toJSON())
  11769. };
  11770. }
  11771. }
  11772. RecipientEncryptedKeys.CLASS_NAME = "RecipientEncryptedKeys";
  11773. const VERSION$b = "version";
  11774. const ORIGINATOR = "originator";
  11775. const UKM = "ukm";
  11776. const KEY_ENCRYPTION_ALGORITHM$2 = "keyEncryptionAlgorithm";
  11777. const RECIPIENT_ENCRYPTED_KEY = "recipientEncryptedKeys";
  11778. const RECIPIENT_CERTIFICATE = "recipientCertificate";
  11779. const RECIPIENT_PUBLIC_KEY = "recipientPublicKey";
  11780. const CLEAR_PROPS$s = [
  11781. VERSION$b,
  11782. ORIGINATOR,
  11783. UKM,
  11784. KEY_ENCRYPTION_ALGORITHM$2,
  11785. RECIPIENT_ENCRYPTED_KEY,
  11786. ];
  11787. class KeyAgreeRecipientInfo extends PkiObject {
  11788. constructor(parameters = {}) {
  11789. super();
  11790. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$b, KeyAgreeRecipientInfo.defaultValues(VERSION$b));
  11791. this.originator = pvutils__namespace.getParametersValue(parameters, ORIGINATOR, KeyAgreeRecipientInfo.defaultValues(ORIGINATOR));
  11792. if (UKM in parameters) {
  11793. this.ukm = pvutils__namespace.getParametersValue(parameters, UKM, KeyAgreeRecipientInfo.defaultValues(UKM));
  11794. }
  11795. this.keyEncryptionAlgorithm = pvutils__namespace.getParametersValue(parameters, KEY_ENCRYPTION_ALGORITHM$2, KeyAgreeRecipientInfo.defaultValues(KEY_ENCRYPTION_ALGORITHM$2));
  11796. this.recipientEncryptedKeys = pvutils__namespace.getParametersValue(parameters, RECIPIENT_ENCRYPTED_KEY, KeyAgreeRecipientInfo.defaultValues(RECIPIENT_ENCRYPTED_KEY));
  11797. this.recipientCertificate = pvutils__namespace.getParametersValue(parameters, RECIPIENT_CERTIFICATE, KeyAgreeRecipientInfo.defaultValues(RECIPIENT_CERTIFICATE));
  11798. this.recipientPublicKey = pvutils__namespace.getParametersValue(parameters, RECIPIENT_PUBLIC_KEY, KeyAgreeRecipientInfo.defaultValues(RECIPIENT_PUBLIC_KEY));
  11799. if (parameters.schema) {
  11800. this.fromSchema(parameters.schema);
  11801. }
  11802. }
  11803. static defaultValues(memberName) {
  11804. switch (memberName) {
  11805. case VERSION$b:
  11806. return 0;
  11807. case ORIGINATOR:
  11808. return new OriginatorIdentifierOrKey();
  11809. case UKM:
  11810. return new asn1js__namespace.OctetString();
  11811. case KEY_ENCRYPTION_ALGORITHM$2:
  11812. return new AlgorithmIdentifier();
  11813. case RECIPIENT_ENCRYPTED_KEY:
  11814. return new RecipientEncryptedKeys();
  11815. case RECIPIENT_CERTIFICATE:
  11816. return new Certificate();
  11817. case RECIPIENT_PUBLIC_KEY:
  11818. return null;
  11819. default:
  11820. return super.defaultValues(memberName);
  11821. }
  11822. }
  11823. static compareWithDefault(memberName, memberValue) {
  11824. switch (memberName) {
  11825. case VERSION$b:
  11826. return (memberValue === 0);
  11827. case ORIGINATOR:
  11828. return ((memberValue.variant === (-1)) && (("value" in memberValue) === false));
  11829. case UKM:
  11830. return (memberValue.isEqual(KeyAgreeRecipientInfo.defaultValues(UKM)));
  11831. case KEY_ENCRYPTION_ALGORITHM$2:
  11832. return ((memberValue.algorithmId === EMPTY_STRING) && (("algorithmParams" in memberValue) === false));
  11833. case RECIPIENT_ENCRYPTED_KEY:
  11834. return (memberValue.encryptedKeys.length === 0);
  11835. case RECIPIENT_CERTIFICATE:
  11836. return false;
  11837. case RECIPIENT_PUBLIC_KEY:
  11838. return false;
  11839. default:
  11840. return super.defaultValues(memberName);
  11841. }
  11842. }
  11843. static schema(parameters = {}) {
  11844. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  11845. return (new asn1js__namespace.Sequence({
  11846. name: names.blockName || EMPTY_STRING,
  11847. value: [
  11848. new asn1js__namespace.Integer({ name: names.version || EMPTY_STRING }),
  11849. new asn1js__namespace.Constructed({
  11850. idBlock: {
  11851. tagClass: 3,
  11852. tagNumber: 0
  11853. },
  11854. value: [
  11855. OriginatorIdentifierOrKey.schema(names.originator || {})
  11856. ]
  11857. }),
  11858. new asn1js__namespace.Constructed({
  11859. optional: true,
  11860. idBlock: {
  11861. tagClass: 3,
  11862. tagNumber: 1
  11863. },
  11864. value: [new asn1js__namespace.OctetString({ name: names.ukm || EMPTY_STRING })]
  11865. }),
  11866. AlgorithmIdentifier.schema(names.keyEncryptionAlgorithm || {}),
  11867. RecipientEncryptedKeys.schema(names.recipientEncryptedKeys || {})
  11868. ]
  11869. }));
  11870. }
  11871. fromSchema(schema) {
  11872. pvutils__namespace.clearProps(schema, CLEAR_PROPS$s);
  11873. const asn1 = asn1js__namespace.compareSchema(schema, schema, KeyAgreeRecipientInfo.schema({
  11874. names: {
  11875. version: VERSION$b,
  11876. originator: {
  11877. names: {
  11878. blockName: ORIGINATOR
  11879. }
  11880. },
  11881. ukm: UKM,
  11882. keyEncryptionAlgorithm: {
  11883. names: {
  11884. blockName: KEY_ENCRYPTION_ALGORITHM$2
  11885. }
  11886. },
  11887. recipientEncryptedKeys: {
  11888. names: {
  11889. blockName: RECIPIENT_ENCRYPTED_KEY
  11890. }
  11891. }
  11892. }
  11893. }));
  11894. AsnError.assertSchema(asn1, this.className);
  11895. this.version = asn1.result.version.valueBlock.valueDec;
  11896. this.originator = new OriginatorIdentifierOrKey({ schema: asn1.result.originator });
  11897. if (UKM in asn1.result)
  11898. this.ukm = asn1.result.ukm;
  11899. this.keyEncryptionAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.keyEncryptionAlgorithm });
  11900. this.recipientEncryptedKeys = new RecipientEncryptedKeys({ schema: asn1.result.recipientEncryptedKeys });
  11901. }
  11902. toSchema() {
  11903. const outputArray = [];
  11904. outputArray.push(new asn1js__namespace.Integer({ value: this.version }));
  11905. outputArray.push(new asn1js__namespace.Constructed({
  11906. idBlock: {
  11907. tagClass: 3,
  11908. tagNumber: 0
  11909. },
  11910. value: [this.originator.toSchema()]
  11911. }));
  11912. if (this.ukm) {
  11913. outputArray.push(new asn1js__namespace.Constructed({
  11914. optional: true,
  11915. idBlock: {
  11916. tagClass: 3,
  11917. tagNumber: 1
  11918. },
  11919. value: [this.ukm]
  11920. }));
  11921. }
  11922. outputArray.push(this.keyEncryptionAlgorithm.toSchema());
  11923. outputArray.push(this.recipientEncryptedKeys.toSchema());
  11924. return (new asn1js__namespace.Sequence({
  11925. value: outputArray
  11926. }));
  11927. }
  11928. toJSON() {
  11929. const res = {
  11930. version: this.version,
  11931. originator: this.originator.toJSON(),
  11932. keyEncryptionAlgorithm: this.keyEncryptionAlgorithm.toJSON(),
  11933. recipientEncryptedKeys: this.recipientEncryptedKeys.toJSON(),
  11934. };
  11935. if (this.ukm) {
  11936. res.ukm = this.ukm.toJSON();
  11937. }
  11938. return res;
  11939. }
  11940. }
  11941. KeyAgreeRecipientInfo.CLASS_NAME = "KeyAgreeRecipientInfo";
  11942. const KEY_IDENTIFIER = "keyIdentifier";
  11943. const DATE = "date";
  11944. const OTHER = "other";
  11945. const CLEAR_PROPS$r = [
  11946. KEY_IDENTIFIER,
  11947. DATE,
  11948. OTHER,
  11949. ];
  11950. class KEKIdentifier extends PkiObject {
  11951. constructor(parameters = {}) {
  11952. super();
  11953. this.keyIdentifier = pvutils__namespace.getParametersValue(parameters, KEY_IDENTIFIER, KEKIdentifier.defaultValues(KEY_IDENTIFIER));
  11954. if (DATE in parameters) {
  11955. this.date = pvutils__namespace.getParametersValue(parameters, DATE, KEKIdentifier.defaultValues(DATE));
  11956. }
  11957. if (OTHER in parameters) {
  11958. this.other = pvutils__namespace.getParametersValue(parameters, OTHER, KEKIdentifier.defaultValues(OTHER));
  11959. }
  11960. if (parameters.schema) {
  11961. this.fromSchema(parameters.schema);
  11962. }
  11963. }
  11964. static defaultValues(memberName) {
  11965. switch (memberName) {
  11966. case KEY_IDENTIFIER:
  11967. return new asn1js__namespace.OctetString();
  11968. case DATE:
  11969. return new asn1js__namespace.GeneralizedTime();
  11970. case OTHER:
  11971. return new OtherKeyAttribute();
  11972. default:
  11973. return super.defaultValues(memberName);
  11974. }
  11975. }
  11976. static compareWithDefault(memberName, memberValue) {
  11977. switch (memberName) {
  11978. case KEY_IDENTIFIER:
  11979. return (memberValue.isEqual(KEKIdentifier.defaultValues(KEY_IDENTIFIER)));
  11980. case DATE:
  11981. return ((memberValue.year === 0) &&
  11982. (memberValue.month === 0) &&
  11983. (memberValue.day === 0) &&
  11984. (memberValue.hour === 0) &&
  11985. (memberValue.minute === 0) &&
  11986. (memberValue.second === 0) &&
  11987. (memberValue.millisecond === 0));
  11988. case OTHER:
  11989. return ((memberValue.compareWithDefault("keyAttrId", memberValue.keyAttrId)) &&
  11990. (("keyAttr" in memberValue) === false));
  11991. default:
  11992. return super.defaultValues(memberName);
  11993. }
  11994. }
  11995. static schema(parameters = {}) {
  11996. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  11997. return (new asn1js__namespace.Sequence({
  11998. name: (names.blockName || EMPTY_STRING),
  11999. value: [
  12000. new asn1js__namespace.OctetString({ name: (names.keyIdentifier || EMPTY_STRING) }),
  12001. new asn1js__namespace.GeneralizedTime({
  12002. optional: true,
  12003. name: (names.date || EMPTY_STRING)
  12004. }),
  12005. OtherKeyAttribute.schema(names.other || {})
  12006. ]
  12007. }));
  12008. }
  12009. fromSchema(schema) {
  12010. pvutils__namespace.clearProps(schema, CLEAR_PROPS$r);
  12011. const asn1 = asn1js__namespace.compareSchema(schema, schema, KEKIdentifier.schema({
  12012. names: {
  12013. keyIdentifier: KEY_IDENTIFIER,
  12014. date: DATE,
  12015. other: {
  12016. names: {
  12017. blockName: OTHER
  12018. }
  12019. }
  12020. }
  12021. }));
  12022. AsnError.assertSchema(asn1, this.className);
  12023. this.keyIdentifier = asn1.result.keyIdentifier;
  12024. if (DATE in asn1.result)
  12025. this.date = asn1.result.date;
  12026. if (OTHER in asn1.result)
  12027. this.other = new OtherKeyAttribute({ schema: asn1.result.other });
  12028. }
  12029. toSchema() {
  12030. const outputArray = [];
  12031. outputArray.push(this.keyIdentifier);
  12032. if (this.date) {
  12033. outputArray.push(this.date);
  12034. }
  12035. if (this.other) {
  12036. outputArray.push(this.other.toSchema());
  12037. }
  12038. return (new asn1js__namespace.Sequence({
  12039. value: outputArray
  12040. }));
  12041. }
  12042. toJSON() {
  12043. const res = {
  12044. keyIdentifier: this.keyIdentifier.toJSON()
  12045. };
  12046. if (this.date) {
  12047. res.date = this.date;
  12048. }
  12049. if (this.other) {
  12050. res.other = this.other.toJSON();
  12051. }
  12052. return res;
  12053. }
  12054. }
  12055. KEKIdentifier.CLASS_NAME = "KEKIdentifier";
  12056. const VERSION$a = "version";
  12057. const KEK_ID = "kekid";
  12058. const KEY_ENCRYPTION_ALGORITHM$1 = "keyEncryptionAlgorithm";
  12059. const ENCRYPTED_KEY$1 = "encryptedKey";
  12060. const PER_DEFINED_KEK = "preDefinedKEK";
  12061. const CLEAR_PROPS$q = [
  12062. VERSION$a,
  12063. KEK_ID,
  12064. KEY_ENCRYPTION_ALGORITHM$1,
  12065. ENCRYPTED_KEY$1,
  12066. ];
  12067. class KEKRecipientInfo extends PkiObject {
  12068. constructor(parameters = {}) {
  12069. super();
  12070. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$a, KEKRecipientInfo.defaultValues(VERSION$a));
  12071. this.kekid = pvutils__namespace.getParametersValue(parameters, KEK_ID, KEKRecipientInfo.defaultValues(KEK_ID));
  12072. this.keyEncryptionAlgorithm = pvutils__namespace.getParametersValue(parameters, KEY_ENCRYPTION_ALGORITHM$1, KEKRecipientInfo.defaultValues(KEY_ENCRYPTION_ALGORITHM$1));
  12073. this.encryptedKey = pvutils__namespace.getParametersValue(parameters, ENCRYPTED_KEY$1, KEKRecipientInfo.defaultValues(ENCRYPTED_KEY$1));
  12074. this.preDefinedKEK = pvutils__namespace.getParametersValue(parameters, PER_DEFINED_KEK, KEKRecipientInfo.defaultValues(PER_DEFINED_KEK));
  12075. if (parameters.schema) {
  12076. this.fromSchema(parameters.schema);
  12077. }
  12078. }
  12079. static defaultValues(memberName) {
  12080. switch (memberName) {
  12081. case VERSION$a:
  12082. return 0;
  12083. case KEK_ID:
  12084. return new KEKIdentifier();
  12085. case KEY_ENCRYPTION_ALGORITHM$1:
  12086. return new AlgorithmIdentifier();
  12087. case ENCRYPTED_KEY$1:
  12088. return new asn1js__namespace.OctetString();
  12089. case PER_DEFINED_KEK:
  12090. return EMPTY_BUFFER;
  12091. default:
  12092. return super.defaultValues(memberName);
  12093. }
  12094. }
  12095. static compareWithDefault(memberName, memberValue) {
  12096. switch (memberName) {
  12097. case "KEKRecipientInfo":
  12098. return (memberValue === KEKRecipientInfo.defaultValues(VERSION$a));
  12099. case KEK_ID:
  12100. return ((memberValue.compareWithDefault("keyIdentifier", memberValue.keyIdentifier)) &&
  12101. (("date" in memberValue) === false) &&
  12102. (("other" in memberValue) === false));
  12103. case KEY_ENCRYPTION_ALGORITHM$1:
  12104. return ((memberValue.algorithmId === EMPTY_STRING) && (("algorithmParams" in memberValue) === false));
  12105. case ENCRYPTED_KEY$1:
  12106. return (memberValue.isEqual(KEKRecipientInfo.defaultValues(ENCRYPTED_KEY$1)));
  12107. case PER_DEFINED_KEK:
  12108. return (memberValue.byteLength === 0);
  12109. default:
  12110. return super.defaultValues(memberName);
  12111. }
  12112. }
  12113. static schema(parameters = {}) {
  12114. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  12115. return (new asn1js__namespace.Sequence({
  12116. name: (names.blockName || EMPTY_STRING),
  12117. value: [
  12118. new asn1js__namespace.Integer({ name: (names.version || EMPTY_STRING) }),
  12119. KEKIdentifier.schema(names.kekid || {}),
  12120. AlgorithmIdentifier.schema(names.keyEncryptionAlgorithm || {}),
  12121. new asn1js__namespace.OctetString({ name: (names.encryptedKey || EMPTY_STRING) })
  12122. ]
  12123. }));
  12124. }
  12125. fromSchema(schema) {
  12126. pvutils__namespace.clearProps(schema, CLEAR_PROPS$q);
  12127. const asn1 = asn1js__namespace.compareSchema(schema, schema, KEKRecipientInfo.schema({
  12128. names: {
  12129. version: VERSION$a,
  12130. kekid: {
  12131. names: {
  12132. blockName: KEK_ID
  12133. }
  12134. },
  12135. keyEncryptionAlgorithm: {
  12136. names: {
  12137. blockName: KEY_ENCRYPTION_ALGORITHM$1
  12138. }
  12139. },
  12140. encryptedKey: ENCRYPTED_KEY$1
  12141. }
  12142. }));
  12143. AsnError.assertSchema(asn1, this.className);
  12144. this.version = asn1.result.version.valueBlock.valueDec;
  12145. this.kekid = new KEKIdentifier({ schema: asn1.result.kekid });
  12146. this.keyEncryptionAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.keyEncryptionAlgorithm });
  12147. this.encryptedKey = asn1.result.encryptedKey;
  12148. }
  12149. toSchema() {
  12150. return (new asn1js__namespace.Sequence({
  12151. value: [
  12152. new asn1js__namespace.Integer({ value: this.version }),
  12153. this.kekid.toSchema(),
  12154. this.keyEncryptionAlgorithm.toSchema(),
  12155. this.encryptedKey
  12156. ]
  12157. }));
  12158. }
  12159. toJSON() {
  12160. return {
  12161. version: this.version,
  12162. kekid: this.kekid.toJSON(),
  12163. keyEncryptionAlgorithm: this.keyEncryptionAlgorithm.toJSON(),
  12164. encryptedKey: this.encryptedKey.toJSON(),
  12165. };
  12166. }
  12167. }
  12168. KEKRecipientInfo.CLASS_NAME = "KEKRecipientInfo";
  12169. const VERSION$9 = "version";
  12170. const KEY_DERIVATION_ALGORITHM = "keyDerivationAlgorithm";
  12171. const KEY_ENCRYPTION_ALGORITHM = "keyEncryptionAlgorithm";
  12172. const ENCRYPTED_KEY = "encryptedKey";
  12173. const PASSWORD = "password";
  12174. const CLEAR_PROPS$p = [
  12175. VERSION$9,
  12176. KEY_DERIVATION_ALGORITHM,
  12177. KEY_ENCRYPTION_ALGORITHM,
  12178. ENCRYPTED_KEY
  12179. ];
  12180. class PasswordRecipientinfo extends PkiObject {
  12181. constructor(parameters = {}) {
  12182. super();
  12183. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$9, PasswordRecipientinfo.defaultValues(VERSION$9));
  12184. if (KEY_DERIVATION_ALGORITHM in parameters) {
  12185. this.keyDerivationAlgorithm = pvutils__namespace.getParametersValue(parameters, KEY_DERIVATION_ALGORITHM, PasswordRecipientinfo.defaultValues(KEY_DERIVATION_ALGORITHM));
  12186. }
  12187. this.keyEncryptionAlgorithm = pvutils__namespace.getParametersValue(parameters, KEY_ENCRYPTION_ALGORITHM, PasswordRecipientinfo.defaultValues(KEY_ENCRYPTION_ALGORITHM));
  12188. this.encryptedKey = pvutils__namespace.getParametersValue(parameters, ENCRYPTED_KEY, PasswordRecipientinfo.defaultValues(ENCRYPTED_KEY));
  12189. this.password = pvutils__namespace.getParametersValue(parameters, PASSWORD, PasswordRecipientinfo.defaultValues(PASSWORD));
  12190. if (parameters.schema) {
  12191. this.fromSchema(parameters.schema);
  12192. }
  12193. }
  12194. static defaultValues(memberName) {
  12195. switch (memberName) {
  12196. case VERSION$9:
  12197. return (-1);
  12198. case KEY_DERIVATION_ALGORITHM:
  12199. return new AlgorithmIdentifier();
  12200. case KEY_ENCRYPTION_ALGORITHM:
  12201. return new AlgorithmIdentifier();
  12202. case ENCRYPTED_KEY:
  12203. return new asn1js__namespace.OctetString();
  12204. case PASSWORD:
  12205. return EMPTY_BUFFER;
  12206. default:
  12207. return super.defaultValues(memberName);
  12208. }
  12209. }
  12210. static compareWithDefault(memberName, memberValue) {
  12211. switch (memberName) {
  12212. case VERSION$9:
  12213. return (memberValue === (-1));
  12214. case KEY_DERIVATION_ALGORITHM:
  12215. case KEY_ENCRYPTION_ALGORITHM:
  12216. return ((memberValue.algorithmId === EMPTY_STRING) && (("algorithmParams" in memberValue) === false));
  12217. case ENCRYPTED_KEY:
  12218. return (memberValue.isEqual(PasswordRecipientinfo.defaultValues(ENCRYPTED_KEY)));
  12219. case PASSWORD:
  12220. return (memberValue.byteLength === 0);
  12221. default:
  12222. return super.defaultValues(memberName);
  12223. }
  12224. }
  12225. static schema(parameters = {}) {
  12226. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  12227. return (new asn1js__namespace.Sequence({
  12228. name: (names.blockName || EMPTY_STRING),
  12229. value: [
  12230. new asn1js__namespace.Integer({ name: (names.version || EMPTY_STRING) }),
  12231. new asn1js__namespace.Constructed({
  12232. name: (names.keyDerivationAlgorithm || EMPTY_STRING),
  12233. optional: true,
  12234. idBlock: {
  12235. tagClass: 3,
  12236. tagNumber: 0
  12237. },
  12238. value: AlgorithmIdentifier.schema().valueBlock.value
  12239. }),
  12240. AlgorithmIdentifier.schema(names.keyEncryptionAlgorithm || {}),
  12241. new asn1js__namespace.OctetString({ name: (names.encryptedKey || EMPTY_STRING) })
  12242. ]
  12243. }));
  12244. }
  12245. fromSchema(schema) {
  12246. pvutils__namespace.clearProps(schema, CLEAR_PROPS$p);
  12247. const asn1 = asn1js__namespace.compareSchema(schema, schema, PasswordRecipientinfo.schema({
  12248. names: {
  12249. version: VERSION$9,
  12250. keyDerivationAlgorithm: KEY_DERIVATION_ALGORITHM,
  12251. keyEncryptionAlgorithm: {
  12252. names: {
  12253. blockName: KEY_ENCRYPTION_ALGORITHM
  12254. }
  12255. },
  12256. encryptedKey: ENCRYPTED_KEY
  12257. }
  12258. }));
  12259. AsnError.assertSchema(asn1, this.className);
  12260. this.version = asn1.result.version.valueBlock.valueDec;
  12261. if (KEY_DERIVATION_ALGORITHM in asn1.result) {
  12262. this.keyDerivationAlgorithm = new AlgorithmIdentifier({
  12263. schema: new asn1js__namespace.Sequence({
  12264. value: asn1.result.keyDerivationAlgorithm.valueBlock.value
  12265. })
  12266. });
  12267. }
  12268. this.keyEncryptionAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.keyEncryptionAlgorithm });
  12269. this.encryptedKey = asn1.result.encryptedKey;
  12270. }
  12271. toSchema() {
  12272. const outputArray = [];
  12273. outputArray.push(new asn1js__namespace.Integer({ value: this.version }));
  12274. if (this.keyDerivationAlgorithm) {
  12275. outputArray.push(new asn1js__namespace.Constructed({
  12276. idBlock: {
  12277. tagClass: 3,
  12278. tagNumber: 0
  12279. },
  12280. value: this.keyDerivationAlgorithm.toSchema().valueBlock.value
  12281. }));
  12282. }
  12283. outputArray.push(this.keyEncryptionAlgorithm.toSchema());
  12284. outputArray.push(this.encryptedKey);
  12285. return (new asn1js__namespace.Sequence({
  12286. value: outputArray
  12287. }));
  12288. }
  12289. toJSON() {
  12290. const res = {
  12291. version: this.version,
  12292. keyEncryptionAlgorithm: this.keyEncryptionAlgorithm.toJSON(),
  12293. encryptedKey: this.encryptedKey.toJSON(),
  12294. };
  12295. if (this.keyDerivationAlgorithm) {
  12296. res.keyDerivationAlgorithm = this.keyDerivationAlgorithm.toJSON();
  12297. }
  12298. return res;
  12299. }
  12300. }
  12301. PasswordRecipientinfo.CLASS_NAME = "PasswordRecipientInfo";
  12302. const ORI_TYPE = "oriType";
  12303. const ORI_VALUE = "oriValue";
  12304. const CLEAR_PROPS$o = [
  12305. ORI_TYPE,
  12306. ORI_VALUE
  12307. ];
  12308. class OtherRecipientInfo extends PkiObject {
  12309. constructor(parameters = {}) {
  12310. super();
  12311. this.oriType = pvutils__namespace.getParametersValue(parameters, ORI_TYPE, OtherRecipientInfo.defaultValues(ORI_TYPE));
  12312. this.oriValue = pvutils__namespace.getParametersValue(parameters, ORI_VALUE, OtherRecipientInfo.defaultValues(ORI_VALUE));
  12313. if (parameters.schema) {
  12314. this.fromSchema(parameters.schema);
  12315. }
  12316. }
  12317. static defaultValues(memberName) {
  12318. switch (memberName) {
  12319. case ORI_TYPE:
  12320. return EMPTY_STRING;
  12321. case ORI_VALUE:
  12322. return {};
  12323. default:
  12324. return super.defaultValues(memberName);
  12325. }
  12326. }
  12327. static compareWithDefault(memberName, memberValue) {
  12328. switch (memberName) {
  12329. case ORI_TYPE:
  12330. return (memberValue === EMPTY_STRING);
  12331. case ORI_VALUE:
  12332. return (Object.keys(memberValue).length === 0);
  12333. default:
  12334. return super.defaultValues(memberName);
  12335. }
  12336. }
  12337. static schema(parameters = {}) {
  12338. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  12339. return (new asn1js__namespace.Sequence({
  12340. name: (names.blockName || EMPTY_STRING),
  12341. value: [
  12342. new asn1js__namespace.ObjectIdentifier({ name: (names.oriType || EMPTY_STRING) }),
  12343. new asn1js__namespace.Any({ name: (names.oriValue || EMPTY_STRING) })
  12344. ]
  12345. }));
  12346. }
  12347. fromSchema(schema) {
  12348. pvutils__namespace.clearProps(schema, CLEAR_PROPS$o);
  12349. const asn1 = asn1js__namespace.compareSchema(schema, schema, OtherRecipientInfo.schema({
  12350. names: {
  12351. oriType: ORI_TYPE,
  12352. oriValue: ORI_VALUE
  12353. }
  12354. }));
  12355. AsnError.assertSchema(asn1, this.className);
  12356. this.oriType = asn1.result.oriType.valueBlock.toString();
  12357. this.oriValue = asn1.result.oriValue;
  12358. }
  12359. toSchema() {
  12360. return (new asn1js__namespace.Sequence({
  12361. value: [
  12362. new asn1js__namespace.ObjectIdentifier({ value: this.oriType }),
  12363. this.oriValue
  12364. ]
  12365. }));
  12366. }
  12367. toJSON() {
  12368. const res = {
  12369. oriType: this.oriType
  12370. };
  12371. if (!OtherRecipientInfo.compareWithDefault(ORI_VALUE, this.oriValue)) {
  12372. res.oriValue = this.oriValue.toJSON();
  12373. }
  12374. return res;
  12375. }
  12376. }
  12377. OtherRecipientInfo.CLASS_NAME = "OtherRecipientInfo";
  12378. const VARIANT = "variant";
  12379. const VALUE = "value";
  12380. const CLEAR_PROPS$n = [
  12381. "blockName"
  12382. ];
  12383. class RecipientInfo extends PkiObject {
  12384. constructor(parameters = {}) {
  12385. super();
  12386. this.variant = pvutils__namespace.getParametersValue(parameters, VARIANT, RecipientInfo.defaultValues(VARIANT));
  12387. if (VALUE in parameters) {
  12388. this.value = pvutils__namespace.getParametersValue(parameters, VALUE, RecipientInfo.defaultValues(VALUE));
  12389. }
  12390. if (parameters.schema) {
  12391. this.fromSchema(parameters.schema);
  12392. }
  12393. }
  12394. static defaultValues(memberName) {
  12395. switch (memberName) {
  12396. case VARIANT:
  12397. return (-1);
  12398. case VALUE:
  12399. return {};
  12400. default:
  12401. return super.defaultValues(memberName);
  12402. }
  12403. }
  12404. static compareWithDefault(memberName, memberValue) {
  12405. switch (memberName) {
  12406. case VARIANT:
  12407. return (memberValue === RecipientInfo.defaultValues(memberName));
  12408. case VALUE:
  12409. return (Object.keys(memberValue).length === 0);
  12410. default:
  12411. return super.defaultValues(memberName);
  12412. }
  12413. }
  12414. static schema(parameters = {}) {
  12415. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  12416. return (new asn1js__namespace.Choice({
  12417. value: [
  12418. KeyTransRecipientInfo.schema({
  12419. names: {
  12420. blockName: (names.blockName || EMPTY_STRING)
  12421. }
  12422. }),
  12423. new asn1js__namespace.Constructed({
  12424. name: (names.blockName || EMPTY_STRING),
  12425. idBlock: {
  12426. tagClass: 3,
  12427. tagNumber: 1
  12428. },
  12429. value: KeyAgreeRecipientInfo.schema().valueBlock.value
  12430. }),
  12431. new asn1js__namespace.Constructed({
  12432. name: (names.blockName || EMPTY_STRING),
  12433. idBlock: {
  12434. tagClass: 3,
  12435. tagNumber: 2
  12436. },
  12437. value: KEKRecipientInfo.schema().valueBlock.value
  12438. }),
  12439. new asn1js__namespace.Constructed({
  12440. name: (names.blockName || EMPTY_STRING),
  12441. idBlock: {
  12442. tagClass: 3,
  12443. tagNumber: 3
  12444. },
  12445. value: PasswordRecipientinfo.schema().valueBlock.value
  12446. }),
  12447. new asn1js__namespace.Constructed({
  12448. name: (names.blockName || EMPTY_STRING),
  12449. idBlock: {
  12450. tagClass: 3,
  12451. tagNumber: 4
  12452. },
  12453. value: OtherRecipientInfo.schema().valueBlock.value
  12454. })
  12455. ]
  12456. }));
  12457. }
  12458. fromSchema(schema) {
  12459. pvutils__namespace.clearProps(schema, CLEAR_PROPS$n);
  12460. const asn1 = asn1js__namespace.compareSchema(schema, schema, RecipientInfo.schema({
  12461. names: {
  12462. blockName: "blockName"
  12463. }
  12464. }));
  12465. AsnError.assertSchema(asn1, this.className);
  12466. if (asn1.result.blockName.idBlock.tagClass === 1) {
  12467. this.variant = 1;
  12468. this.value = new KeyTransRecipientInfo({ schema: asn1.result.blockName });
  12469. }
  12470. else {
  12471. const blockSequence = new asn1js__namespace.Sequence({
  12472. value: asn1.result.blockName.valueBlock.value
  12473. });
  12474. switch (asn1.result.blockName.idBlock.tagNumber) {
  12475. case 1:
  12476. this.variant = 2;
  12477. this.value = new KeyAgreeRecipientInfo({ schema: blockSequence });
  12478. break;
  12479. case 2:
  12480. this.variant = 3;
  12481. this.value = new KEKRecipientInfo({ schema: blockSequence });
  12482. break;
  12483. case 3:
  12484. this.variant = 4;
  12485. this.value = new PasswordRecipientinfo({ schema: blockSequence });
  12486. break;
  12487. case 4:
  12488. this.variant = 5;
  12489. this.value = new OtherRecipientInfo({ schema: blockSequence });
  12490. break;
  12491. default:
  12492. throw new Error("Incorrect structure of RecipientInfo block");
  12493. }
  12494. }
  12495. }
  12496. toSchema() {
  12497. ParameterError.assertEmpty(this.value, "value", "RecipientInfo");
  12498. const _schema = this.value.toSchema();
  12499. switch (this.variant) {
  12500. case 1:
  12501. return _schema;
  12502. case 2:
  12503. case 3:
  12504. case 4:
  12505. _schema.idBlock.tagClass = 3;
  12506. _schema.idBlock.tagNumber = (this.variant - 1);
  12507. return _schema;
  12508. default:
  12509. return new asn1js__namespace.Any();
  12510. }
  12511. }
  12512. toJSON() {
  12513. const res = {
  12514. variant: this.variant
  12515. };
  12516. if (this.value && (this.variant >= 1) && (this.variant <= 4)) {
  12517. res.value = this.value.toJSON();
  12518. }
  12519. return res;
  12520. }
  12521. }
  12522. RecipientInfo.CLASS_NAME = "RecipientInfo";
  12523. const HASH_ALGORITHM$2 = "hashAlgorithm";
  12524. const MASK_GEN_ALGORITHM = "maskGenAlgorithm";
  12525. const P_SOURCE_ALGORITHM = "pSourceAlgorithm";
  12526. const CLEAR_PROPS$m = [
  12527. HASH_ALGORITHM$2,
  12528. MASK_GEN_ALGORITHM,
  12529. P_SOURCE_ALGORITHM
  12530. ];
  12531. class RSAESOAEPParams extends PkiObject {
  12532. constructor(parameters = {}) {
  12533. super();
  12534. this.hashAlgorithm = pvutils__namespace.getParametersValue(parameters, HASH_ALGORITHM$2, RSAESOAEPParams.defaultValues(HASH_ALGORITHM$2));
  12535. this.maskGenAlgorithm = pvutils__namespace.getParametersValue(parameters, MASK_GEN_ALGORITHM, RSAESOAEPParams.defaultValues(MASK_GEN_ALGORITHM));
  12536. this.pSourceAlgorithm = pvutils__namespace.getParametersValue(parameters, P_SOURCE_ALGORITHM, RSAESOAEPParams.defaultValues(P_SOURCE_ALGORITHM));
  12537. if (parameters.schema) {
  12538. this.fromSchema(parameters.schema);
  12539. }
  12540. }
  12541. static defaultValues(memberName) {
  12542. switch (memberName) {
  12543. case HASH_ALGORITHM$2:
  12544. return new AlgorithmIdentifier({
  12545. algorithmId: "1.3.14.3.2.26",
  12546. algorithmParams: new asn1js__namespace.Null()
  12547. });
  12548. case MASK_GEN_ALGORITHM:
  12549. return new AlgorithmIdentifier({
  12550. algorithmId: "1.2.840.113549.1.1.8",
  12551. algorithmParams: (new AlgorithmIdentifier({
  12552. algorithmId: "1.3.14.3.2.26",
  12553. algorithmParams: new asn1js__namespace.Null()
  12554. })).toSchema()
  12555. });
  12556. case P_SOURCE_ALGORITHM:
  12557. return new AlgorithmIdentifier({
  12558. algorithmId: "1.2.840.113549.1.1.9",
  12559. algorithmParams: new asn1js__namespace.OctetString({ valueHex: (new Uint8Array([0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09])).buffer })
  12560. });
  12561. default:
  12562. return super.defaultValues(memberName);
  12563. }
  12564. }
  12565. static schema(parameters = {}) {
  12566. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  12567. return (new asn1js__namespace.Sequence({
  12568. name: (names.blockName || EMPTY_STRING),
  12569. value: [
  12570. new asn1js__namespace.Constructed({
  12571. idBlock: {
  12572. tagClass: 3,
  12573. tagNumber: 0
  12574. },
  12575. optional: true,
  12576. value: [AlgorithmIdentifier.schema(names.hashAlgorithm || {})]
  12577. }),
  12578. new asn1js__namespace.Constructed({
  12579. idBlock: {
  12580. tagClass: 3,
  12581. tagNumber: 1
  12582. },
  12583. optional: true,
  12584. value: [AlgorithmIdentifier.schema(names.maskGenAlgorithm || {})]
  12585. }),
  12586. new asn1js__namespace.Constructed({
  12587. idBlock: {
  12588. tagClass: 3,
  12589. tagNumber: 2
  12590. },
  12591. optional: true,
  12592. value: [AlgorithmIdentifier.schema(names.pSourceAlgorithm || {})]
  12593. })
  12594. ]
  12595. }));
  12596. }
  12597. fromSchema(schema) {
  12598. pvutils__namespace.clearProps(schema, CLEAR_PROPS$m);
  12599. const asn1 = asn1js__namespace.compareSchema(schema, schema, RSAESOAEPParams.schema({
  12600. names: {
  12601. hashAlgorithm: {
  12602. names: {
  12603. blockName: HASH_ALGORITHM$2
  12604. }
  12605. },
  12606. maskGenAlgorithm: {
  12607. names: {
  12608. blockName: MASK_GEN_ALGORITHM
  12609. }
  12610. },
  12611. pSourceAlgorithm: {
  12612. names: {
  12613. blockName: P_SOURCE_ALGORITHM
  12614. }
  12615. }
  12616. }
  12617. }));
  12618. AsnError.assertSchema(asn1, this.className);
  12619. if (HASH_ALGORITHM$2 in asn1.result)
  12620. this.hashAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.hashAlgorithm });
  12621. if (MASK_GEN_ALGORITHM in asn1.result)
  12622. this.maskGenAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.maskGenAlgorithm });
  12623. if (P_SOURCE_ALGORITHM in asn1.result)
  12624. this.pSourceAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.pSourceAlgorithm });
  12625. }
  12626. toSchema() {
  12627. const outputArray = [];
  12628. if (!this.hashAlgorithm.isEqual(RSAESOAEPParams.defaultValues(HASH_ALGORITHM$2))) {
  12629. outputArray.push(new asn1js__namespace.Constructed({
  12630. idBlock: {
  12631. tagClass: 3,
  12632. tagNumber: 0
  12633. },
  12634. value: [this.hashAlgorithm.toSchema()]
  12635. }));
  12636. }
  12637. if (!this.maskGenAlgorithm.isEqual(RSAESOAEPParams.defaultValues(MASK_GEN_ALGORITHM))) {
  12638. outputArray.push(new asn1js__namespace.Constructed({
  12639. idBlock: {
  12640. tagClass: 3,
  12641. tagNumber: 1
  12642. },
  12643. value: [this.maskGenAlgorithm.toSchema()]
  12644. }));
  12645. }
  12646. if (!this.pSourceAlgorithm.isEqual(RSAESOAEPParams.defaultValues(P_SOURCE_ALGORITHM))) {
  12647. outputArray.push(new asn1js__namespace.Constructed({
  12648. idBlock: {
  12649. tagClass: 3,
  12650. tagNumber: 2
  12651. },
  12652. value: [this.pSourceAlgorithm.toSchema()]
  12653. }));
  12654. }
  12655. return (new asn1js__namespace.Sequence({
  12656. value: outputArray
  12657. }));
  12658. }
  12659. toJSON() {
  12660. const res = {};
  12661. if (!this.hashAlgorithm.isEqual(RSAESOAEPParams.defaultValues(HASH_ALGORITHM$2))) {
  12662. res.hashAlgorithm = this.hashAlgorithm.toJSON();
  12663. }
  12664. if (!this.maskGenAlgorithm.isEqual(RSAESOAEPParams.defaultValues(MASK_GEN_ALGORITHM))) {
  12665. res.maskGenAlgorithm = this.maskGenAlgorithm.toJSON();
  12666. }
  12667. if (!this.pSourceAlgorithm.isEqual(RSAESOAEPParams.defaultValues(P_SOURCE_ALGORITHM))) {
  12668. res.pSourceAlgorithm = this.pSourceAlgorithm.toJSON();
  12669. }
  12670. return res;
  12671. }
  12672. }
  12673. RSAESOAEPParams.CLASS_NAME = "RSAESOAEPParams";
  12674. const KEY_INFO = "keyInfo";
  12675. const ENTITY_U_INFO = "entityUInfo";
  12676. const SUPP_PUB_INFO = "suppPubInfo";
  12677. const CLEAR_PROPS$l = [
  12678. KEY_INFO,
  12679. ENTITY_U_INFO,
  12680. SUPP_PUB_INFO
  12681. ];
  12682. class ECCCMSSharedInfo extends PkiObject {
  12683. constructor(parameters = {}) {
  12684. super();
  12685. this.keyInfo = pvutils__namespace.getParametersValue(parameters, KEY_INFO, ECCCMSSharedInfo.defaultValues(KEY_INFO));
  12686. if (ENTITY_U_INFO in parameters) {
  12687. this.entityUInfo = pvutils__namespace.getParametersValue(parameters, ENTITY_U_INFO, ECCCMSSharedInfo.defaultValues(ENTITY_U_INFO));
  12688. }
  12689. this.suppPubInfo = pvutils__namespace.getParametersValue(parameters, SUPP_PUB_INFO, ECCCMSSharedInfo.defaultValues(SUPP_PUB_INFO));
  12690. if (parameters.schema) {
  12691. this.fromSchema(parameters.schema);
  12692. }
  12693. }
  12694. static defaultValues(memberName) {
  12695. switch (memberName) {
  12696. case KEY_INFO:
  12697. return new AlgorithmIdentifier();
  12698. case ENTITY_U_INFO:
  12699. return new asn1js__namespace.OctetString();
  12700. case SUPP_PUB_INFO:
  12701. return new asn1js__namespace.OctetString();
  12702. default:
  12703. return super.defaultValues(memberName);
  12704. }
  12705. }
  12706. static compareWithDefault(memberName, memberValue) {
  12707. switch (memberName) {
  12708. case KEY_INFO:
  12709. case ENTITY_U_INFO:
  12710. case SUPP_PUB_INFO:
  12711. return (memberValue.isEqual(ECCCMSSharedInfo.defaultValues(memberName)));
  12712. default:
  12713. return super.defaultValues(memberName);
  12714. }
  12715. }
  12716. static schema(parameters = {}) {
  12717. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  12718. return (new asn1js__namespace.Sequence({
  12719. name: (names.blockName || EMPTY_STRING),
  12720. value: [
  12721. AlgorithmIdentifier.schema(names.keyInfo || {}),
  12722. new asn1js__namespace.Constructed({
  12723. name: (names.entityUInfo || EMPTY_STRING),
  12724. idBlock: {
  12725. tagClass: 3,
  12726. tagNumber: 0
  12727. },
  12728. optional: true,
  12729. value: [new asn1js__namespace.OctetString()]
  12730. }),
  12731. new asn1js__namespace.Constructed({
  12732. name: (names.suppPubInfo || EMPTY_STRING),
  12733. idBlock: {
  12734. tagClass: 3,
  12735. tagNumber: 2
  12736. },
  12737. value: [new asn1js__namespace.OctetString()]
  12738. })
  12739. ]
  12740. }));
  12741. }
  12742. fromSchema(schema) {
  12743. pvutils__namespace.clearProps(schema, CLEAR_PROPS$l);
  12744. const asn1 = asn1js__namespace.compareSchema(schema, schema, ECCCMSSharedInfo.schema({
  12745. names: {
  12746. keyInfo: {
  12747. names: {
  12748. blockName: KEY_INFO
  12749. }
  12750. },
  12751. entityUInfo: ENTITY_U_INFO,
  12752. suppPubInfo: SUPP_PUB_INFO
  12753. }
  12754. }));
  12755. AsnError.assertSchema(asn1, this.className);
  12756. this.keyInfo = new AlgorithmIdentifier({ schema: asn1.result.keyInfo });
  12757. if (ENTITY_U_INFO in asn1.result)
  12758. this.entityUInfo = asn1.result.entityUInfo.valueBlock.value[0];
  12759. this.suppPubInfo = asn1.result.suppPubInfo.valueBlock.value[0];
  12760. }
  12761. toSchema() {
  12762. const outputArray = [];
  12763. outputArray.push(this.keyInfo.toSchema());
  12764. if (this.entityUInfo) {
  12765. outputArray.push(new asn1js__namespace.Constructed({
  12766. idBlock: {
  12767. tagClass: 3,
  12768. tagNumber: 0
  12769. },
  12770. value: [this.entityUInfo]
  12771. }));
  12772. }
  12773. outputArray.push(new asn1js__namespace.Constructed({
  12774. idBlock: {
  12775. tagClass: 3,
  12776. tagNumber: 2
  12777. },
  12778. value: [this.suppPubInfo]
  12779. }));
  12780. return new asn1js__namespace.Sequence({
  12781. value: outputArray
  12782. });
  12783. }
  12784. toJSON() {
  12785. const res = {
  12786. keyInfo: this.keyInfo.toJSON(),
  12787. suppPubInfo: this.suppPubInfo.toJSON(),
  12788. };
  12789. if (this.entityUInfo) {
  12790. res.entityUInfo = this.entityUInfo.toJSON();
  12791. }
  12792. return res;
  12793. }
  12794. }
  12795. ECCCMSSharedInfo.CLASS_NAME = "ECCCMSSharedInfo";
  12796. const VERSION$8 = "version";
  12797. const ORIGINATOR_INFO = "originatorInfo";
  12798. const RECIPIENT_INFOS = "recipientInfos";
  12799. const ENCRYPTED_CONTENT_INFO = "encryptedContentInfo";
  12800. const UNPROTECTED_ATTRS = "unprotectedAttrs";
  12801. const CLEAR_PROPS$k = [
  12802. VERSION$8,
  12803. ORIGINATOR_INFO,
  12804. RECIPIENT_INFOS,
  12805. ENCRYPTED_CONTENT_INFO,
  12806. UNPROTECTED_ATTRS
  12807. ];
  12808. const defaultEncryptionParams = {
  12809. kdfAlgorithm: "SHA-512",
  12810. kekEncryptionLength: 256
  12811. };
  12812. const curveLengthByName = {
  12813. "P-256": 256,
  12814. "P-384": 384,
  12815. "P-521": 528
  12816. };
  12817. class EnvelopedData extends PkiObject {
  12818. constructor(parameters = {}) {
  12819. super();
  12820. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$8, EnvelopedData.defaultValues(VERSION$8));
  12821. if (ORIGINATOR_INFO in parameters) {
  12822. this.originatorInfo = pvutils__namespace.getParametersValue(parameters, ORIGINATOR_INFO, EnvelopedData.defaultValues(ORIGINATOR_INFO));
  12823. }
  12824. this.recipientInfos = pvutils__namespace.getParametersValue(parameters, RECIPIENT_INFOS, EnvelopedData.defaultValues(RECIPIENT_INFOS));
  12825. this.encryptedContentInfo = pvutils__namespace.getParametersValue(parameters, ENCRYPTED_CONTENT_INFO, EnvelopedData.defaultValues(ENCRYPTED_CONTENT_INFO));
  12826. if (UNPROTECTED_ATTRS in parameters) {
  12827. this.unprotectedAttrs = pvutils__namespace.getParametersValue(parameters, UNPROTECTED_ATTRS, EnvelopedData.defaultValues(UNPROTECTED_ATTRS));
  12828. }
  12829. this.policy = {
  12830. disableSplit: !!parameters.disableSplit,
  12831. };
  12832. if (parameters.schema) {
  12833. this.fromSchema(parameters.schema);
  12834. }
  12835. }
  12836. static defaultValues(memberName) {
  12837. switch (memberName) {
  12838. case VERSION$8:
  12839. return 0;
  12840. case ORIGINATOR_INFO:
  12841. return new OriginatorInfo();
  12842. case RECIPIENT_INFOS:
  12843. return [];
  12844. case ENCRYPTED_CONTENT_INFO:
  12845. return new EncryptedContentInfo();
  12846. case UNPROTECTED_ATTRS:
  12847. return [];
  12848. default:
  12849. return super.defaultValues(memberName);
  12850. }
  12851. }
  12852. static compareWithDefault(memberName, memberValue) {
  12853. switch (memberName) {
  12854. case VERSION$8:
  12855. return (memberValue === EnvelopedData.defaultValues(memberName));
  12856. case ORIGINATOR_INFO:
  12857. return ((memberValue.certs.certificates.length === 0) && (memberValue.crls.crls.length === 0));
  12858. case RECIPIENT_INFOS:
  12859. case UNPROTECTED_ATTRS:
  12860. return (memberValue.length === 0);
  12861. case ENCRYPTED_CONTENT_INFO:
  12862. return ((EncryptedContentInfo.compareWithDefault("contentType", memberValue.contentType)) &&
  12863. (EncryptedContentInfo.compareWithDefault("contentEncryptionAlgorithm", memberValue.contentEncryptionAlgorithm) &&
  12864. (EncryptedContentInfo.compareWithDefault("encryptedContent", memberValue.encryptedContent))));
  12865. default:
  12866. return super.defaultValues(memberName);
  12867. }
  12868. }
  12869. static schema(parameters = {}) {
  12870. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  12871. return (new asn1js__namespace.Sequence({
  12872. name: (names.blockName || EMPTY_STRING),
  12873. value: [
  12874. new asn1js__namespace.Integer({ name: (names.version || EMPTY_STRING) }),
  12875. new asn1js__namespace.Constructed({
  12876. name: (names.originatorInfo || EMPTY_STRING),
  12877. optional: true,
  12878. idBlock: {
  12879. tagClass: 3,
  12880. tagNumber: 0
  12881. },
  12882. value: OriginatorInfo.schema().valueBlock.value
  12883. }),
  12884. new asn1js__namespace.Set({
  12885. value: [
  12886. new asn1js__namespace.Repeated({
  12887. name: (names.recipientInfos || EMPTY_STRING),
  12888. value: RecipientInfo.schema()
  12889. })
  12890. ]
  12891. }),
  12892. EncryptedContentInfo.schema(names.encryptedContentInfo || {}),
  12893. new asn1js__namespace.Constructed({
  12894. optional: true,
  12895. idBlock: {
  12896. tagClass: 3,
  12897. tagNumber: 1
  12898. },
  12899. value: [
  12900. new asn1js__namespace.Repeated({
  12901. name: (names.unprotectedAttrs || EMPTY_STRING),
  12902. value: Attribute.schema()
  12903. })
  12904. ]
  12905. })
  12906. ]
  12907. }));
  12908. }
  12909. fromSchema(schema) {
  12910. pvutils__namespace.clearProps(schema, CLEAR_PROPS$k);
  12911. const asn1 = asn1js__namespace.compareSchema(schema, schema, EnvelopedData.schema({
  12912. names: {
  12913. version: VERSION$8,
  12914. originatorInfo: ORIGINATOR_INFO,
  12915. recipientInfos: RECIPIENT_INFOS,
  12916. encryptedContentInfo: {
  12917. names: {
  12918. blockName: ENCRYPTED_CONTENT_INFO
  12919. }
  12920. },
  12921. unprotectedAttrs: UNPROTECTED_ATTRS
  12922. }
  12923. }));
  12924. AsnError.assertSchema(asn1, this.className);
  12925. this.version = asn1.result.version.valueBlock.valueDec;
  12926. if (ORIGINATOR_INFO in asn1.result) {
  12927. this.originatorInfo = new OriginatorInfo({
  12928. schema: new asn1js__namespace.Sequence({
  12929. value: asn1.result.originatorInfo.valueBlock.value
  12930. })
  12931. });
  12932. }
  12933. this.recipientInfos = Array.from(asn1.result.recipientInfos, o => new RecipientInfo({ schema: o }));
  12934. this.encryptedContentInfo = new EncryptedContentInfo({ schema: asn1.result.encryptedContentInfo });
  12935. if (UNPROTECTED_ATTRS in asn1.result)
  12936. this.unprotectedAttrs = Array.from(asn1.result.unprotectedAttrs, o => new Attribute({ schema: o }));
  12937. }
  12938. toSchema() {
  12939. const outputArray = [];
  12940. outputArray.push(new asn1js__namespace.Integer({ value: this.version }));
  12941. if (this.originatorInfo) {
  12942. outputArray.push(new asn1js__namespace.Constructed({
  12943. optional: true,
  12944. idBlock: {
  12945. tagClass: 3,
  12946. tagNumber: 0
  12947. },
  12948. value: this.originatorInfo.toSchema().valueBlock.value
  12949. }));
  12950. }
  12951. outputArray.push(new asn1js__namespace.Set({
  12952. value: Array.from(this.recipientInfos, o => o.toSchema())
  12953. }));
  12954. outputArray.push(this.encryptedContentInfo.toSchema());
  12955. if (this.unprotectedAttrs) {
  12956. outputArray.push(new asn1js__namespace.Constructed({
  12957. optional: true,
  12958. idBlock: {
  12959. tagClass: 3,
  12960. tagNumber: 1
  12961. },
  12962. value: Array.from(this.unprotectedAttrs, o => o.toSchema())
  12963. }));
  12964. }
  12965. return (new asn1js__namespace.Sequence({
  12966. value: outputArray
  12967. }));
  12968. }
  12969. toJSON() {
  12970. const res = {
  12971. version: this.version,
  12972. recipientInfos: Array.from(this.recipientInfos, o => o.toJSON()),
  12973. encryptedContentInfo: this.encryptedContentInfo.toJSON(),
  12974. };
  12975. if (this.originatorInfo)
  12976. res.originatorInfo = this.originatorInfo.toJSON();
  12977. if (this.unprotectedAttrs)
  12978. res.unprotectedAttrs = Array.from(this.unprotectedAttrs, o => o.toJSON());
  12979. return res;
  12980. }
  12981. addRecipientByCertificate(certificate, parameters, variant, crypto = getCrypto(true)) {
  12982. const encryptionParameters = Object.assign({ useOAEP: true, oaepHashAlgorithm: "SHA-512" }, defaultEncryptionParams, parameters || {});
  12983. if (certificate.subjectPublicKeyInfo.algorithm.algorithmId.indexOf("1.2.840.113549") !== (-1))
  12984. variant = 1;
  12985. else {
  12986. if (certificate.subjectPublicKeyInfo.algorithm.algorithmId.indexOf("1.2.840.10045") !== (-1))
  12987. variant = 2;
  12988. else
  12989. throw new Error(`Unknown type of certificate's public key: ${certificate.subjectPublicKeyInfo.algorithm.algorithmId}`);
  12990. }
  12991. switch (variant) {
  12992. case 1:
  12993. {
  12994. let algorithmId;
  12995. let algorithmParams;
  12996. if (encryptionParameters.useOAEP === true) {
  12997. algorithmId = crypto.getOIDByAlgorithm({
  12998. name: "RSA-OAEP"
  12999. }, true, "keyEncryptionAlgorithm");
  13000. const hashOID = crypto.getOIDByAlgorithm({
  13001. name: encryptionParameters.oaepHashAlgorithm
  13002. }, true, "RSAES-OAEP-params");
  13003. const hashAlgorithm = new AlgorithmIdentifier({
  13004. algorithmId: hashOID,
  13005. algorithmParams: new asn1js__namespace.Null()
  13006. });
  13007. const rsaOAEPParams = new RSAESOAEPParams({
  13008. hashAlgorithm,
  13009. maskGenAlgorithm: new AlgorithmIdentifier({
  13010. algorithmId: "1.2.840.113549.1.1.8",
  13011. algorithmParams: hashAlgorithm.toSchema()
  13012. })
  13013. });
  13014. algorithmParams = rsaOAEPParams.toSchema();
  13015. }
  13016. else {
  13017. algorithmId = crypto.getOIDByAlgorithm({
  13018. name: "RSAES-PKCS1-v1_5"
  13019. });
  13020. if (algorithmId === EMPTY_STRING)
  13021. throw new Error("Can not find OID for RSAES-PKCS1-v1_5");
  13022. algorithmParams = new asn1js__namespace.Null();
  13023. }
  13024. const keyInfo = new KeyTransRecipientInfo({
  13025. version: 0,
  13026. rid: new IssuerAndSerialNumber({
  13027. issuer: certificate.issuer,
  13028. serialNumber: certificate.serialNumber
  13029. }),
  13030. keyEncryptionAlgorithm: new AlgorithmIdentifier({
  13031. algorithmId,
  13032. algorithmParams
  13033. }),
  13034. recipientCertificate: certificate,
  13035. });
  13036. this.recipientInfos.push(new RecipientInfo({
  13037. variant: 1,
  13038. value: keyInfo
  13039. }));
  13040. }
  13041. break;
  13042. case 2:
  13043. {
  13044. const recipientIdentifier = new KeyAgreeRecipientIdentifier({
  13045. variant: 1,
  13046. value: new IssuerAndSerialNumber({
  13047. issuer: certificate.issuer,
  13048. serialNumber: certificate.serialNumber
  13049. })
  13050. });
  13051. this._addKeyAgreeRecipientInfo(recipientIdentifier, encryptionParameters, { recipientCertificate: certificate }, crypto);
  13052. }
  13053. break;
  13054. default:
  13055. throw new Error(`Unknown "variant" value: ${variant}`);
  13056. }
  13057. return true;
  13058. }
  13059. addRecipientByPreDefinedData(preDefinedData, parameters = {}, variant, crypto = getCrypto(true)) {
  13060. ArgumentError.assert(preDefinedData, "preDefinedData", "ArrayBuffer");
  13061. if (!preDefinedData.byteLength) {
  13062. throw new Error("Pre-defined data could have zero length");
  13063. }
  13064. if (!parameters.keyIdentifier) {
  13065. const keyIdentifierBuffer = new ArrayBuffer(16);
  13066. const keyIdentifierView = new Uint8Array(keyIdentifierBuffer);
  13067. crypto.getRandomValues(keyIdentifierView);
  13068. parameters.keyIdentifier = keyIdentifierBuffer;
  13069. }
  13070. if (!parameters.hmacHashAlgorithm)
  13071. parameters.hmacHashAlgorithm = "SHA-512";
  13072. if (parameters.iterationCount === undefined) {
  13073. parameters.iterationCount = 2048;
  13074. }
  13075. if (!parameters.keyEncryptionAlgorithm) {
  13076. parameters.keyEncryptionAlgorithm = {
  13077. name: "AES-KW",
  13078. length: 256
  13079. };
  13080. }
  13081. if (!parameters.keyEncryptionAlgorithmParams)
  13082. parameters.keyEncryptionAlgorithmParams = new asn1js__namespace.Null();
  13083. switch (variant) {
  13084. case 1:
  13085. {
  13086. const kekOID = crypto.getOIDByAlgorithm(parameters.keyEncryptionAlgorithm, true, "keyEncryptionAlgorithm");
  13087. const keyInfo = new KEKRecipientInfo({
  13088. version: 4,
  13089. kekid: new KEKIdentifier({
  13090. keyIdentifier: new asn1js__namespace.OctetString({ valueHex: parameters.keyIdentifier })
  13091. }),
  13092. keyEncryptionAlgorithm: new AlgorithmIdentifier({
  13093. algorithmId: kekOID,
  13094. algorithmParams: parameters.keyEncryptionAlgorithmParams
  13095. }),
  13096. preDefinedKEK: preDefinedData
  13097. });
  13098. this.recipientInfos.push(new RecipientInfo({
  13099. variant: 3,
  13100. value: keyInfo
  13101. }));
  13102. }
  13103. break;
  13104. case 2:
  13105. {
  13106. const pbkdf2OID = crypto.getOIDByAlgorithm({ name: "PBKDF2" }, true, "keyDerivationAlgorithm");
  13107. const saltBuffer = new ArrayBuffer(64);
  13108. const saltView = new Uint8Array(saltBuffer);
  13109. crypto.getRandomValues(saltView);
  13110. const hmacOID = crypto.getOIDByAlgorithm({
  13111. name: "HMAC",
  13112. hash: {
  13113. name: parameters.hmacHashAlgorithm
  13114. }
  13115. }, true, "hmacHashAlgorithm");
  13116. const pbkdf2Params = new PBKDF2Params({
  13117. salt: new asn1js__namespace.OctetString({ valueHex: saltBuffer }),
  13118. iterationCount: parameters.iterationCount,
  13119. prf: new AlgorithmIdentifier({
  13120. algorithmId: hmacOID,
  13121. algorithmParams: new asn1js__namespace.Null()
  13122. })
  13123. });
  13124. const kekOID = crypto.getOIDByAlgorithm(parameters.keyEncryptionAlgorithm, true, "keyEncryptionAlgorithm");
  13125. const keyInfo = new PasswordRecipientinfo({
  13126. version: 0,
  13127. keyDerivationAlgorithm: new AlgorithmIdentifier({
  13128. algorithmId: pbkdf2OID,
  13129. algorithmParams: pbkdf2Params.toSchema()
  13130. }),
  13131. keyEncryptionAlgorithm: new AlgorithmIdentifier({
  13132. algorithmId: kekOID,
  13133. algorithmParams: parameters.keyEncryptionAlgorithmParams
  13134. }),
  13135. password: preDefinedData
  13136. });
  13137. this.recipientInfos.push(new RecipientInfo({
  13138. variant: 4,
  13139. value: keyInfo
  13140. }));
  13141. }
  13142. break;
  13143. default:
  13144. throw new Error(`Unknown value for "variant": ${variant}`);
  13145. }
  13146. }
  13147. addRecipientByKeyIdentifier(key, keyId, parameters, crypto = getCrypto(true)) {
  13148. const encryptionParameters = Object.assign({}, defaultEncryptionParams, parameters || {});
  13149. const recipientIdentifier = new KeyAgreeRecipientIdentifier({
  13150. variant: 2,
  13151. value: new RecipientKeyIdentifier({
  13152. subjectKeyIdentifier: new asn1js__namespace.OctetString({ valueHex: keyId }),
  13153. })
  13154. });
  13155. this._addKeyAgreeRecipientInfo(recipientIdentifier, encryptionParameters, { recipientPublicKey: key }, crypto);
  13156. }
  13157. _addKeyAgreeRecipientInfo(recipientIdentifier, encryptionParameters, extraRecipientInfoParams, crypto = getCrypto(true)) {
  13158. const encryptedKey = new RecipientEncryptedKey({
  13159. rid: recipientIdentifier
  13160. });
  13161. const aesKWoid = crypto.getOIDByAlgorithm({
  13162. name: "AES-KW",
  13163. length: encryptionParameters.kekEncryptionLength
  13164. }, true, "keyEncryptionAlgorithm");
  13165. const aesKW = new AlgorithmIdentifier({
  13166. algorithmId: aesKWoid,
  13167. });
  13168. const ecdhOID = crypto.getOIDByAlgorithm({
  13169. name: "ECDH",
  13170. kdf: encryptionParameters.kdfAlgorithm
  13171. }, true, "KeyAgreeRecipientInfo");
  13172. const ukmBuffer = new ArrayBuffer(64);
  13173. const ukmView = new Uint8Array(ukmBuffer);
  13174. crypto.getRandomValues(ukmView);
  13175. const recipientInfoParams = {
  13176. version: 3,
  13177. ukm: new asn1js__namespace.OctetString({ valueHex: ukmBuffer }),
  13178. keyEncryptionAlgorithm: new AlgorithmIdentifier({
  13179. algorithmId: ecdhOID,
  13180. algorithmParams: aesKW.toSchema()
  13181. }),
  13182. recipientEncryptedKeys: new RecipientEncryptedKeys({
  13183. encryptedKeys: [encryptedKey]
  13184. })
  13185. };
  13186. const keyInfo = new KeyAgreeRecipientInfo(Object.assign(recipientInfoParams, extraRecipientInfoParams));
  13187. this.recipientInfos.push(new RecipientInfo({
  13188. variant: 2,
  13189. value: keyInfo
  13190. }));
  13191. }
  13192. async encrypt(contentEncryptionAlgorithm, contentToEncrypt, crypto = getCrypto(true)) {
  13193. const ivBuffer = new ArrayBuffer(16);
  13194. const ivView = new Uint8Array(ivBuffer);
  13195. crypto.getRandomValues(ivView);
  13196. const contentView = new Uint8Array(contentToEncrypt);
  13197. const contentEncryptionOID = crypto.getOIDByAlgorithm(contentEncryptionAlgorithm, true, "contentEncryptionAlgorithm");
  13198. const sessionKey = await crypto.generateKey(contentEncryptionAlgorithm, true, ["encrypt"]);
  13199. const encryptedContent = await crypto.encrypt({
  13200. name: contentEncryptionAlgorithm.name,
  13201. iv: ivView
  13202. }, sessionKey, contentView);
  13203. const exportedSessionKey = await crypto.exportKey("raw", sessionKey);
  13204. this.version = 2;
  13205. this.encryptedContentInfo = new EncryptedContentInfo({
  13206. disableSplit: this.policy.disableSplit,
  13207. contentType: "1.2.840.113549.1.7.1",
  13208. contentEncryptionAlgorithm: new AlgorithmIdentifier({
  13209. algorithmId: contentEncryptionOID,
  13210. algorithmParams: new asn1js__namespace.OctetString({ valueHex: ivBuffer })
  13211. }),
  13212. encryptedContent: new asn1js__namespace.OctetString({ valueHex: encryptedContent })
  13213. });
  13214. const SubKeyAgreeRecipientInfo = async (index) => {
  13215. const recipientInfo = this.recipientInfos[index].value;
  13216. let recipientCurve;
  13217. let recipientPublicKey;
  13218. if (recipientInfo.recipientPublicKey) {
  13219. recipientCurve = recipientInfo.recipientPublicKey.algorithm.namedCurve;
  13220. recipientPublicKey = recipientInfo.recipientPublicKey;
  13221. }
  13222. else if (recipientInfo.recipientCertificate) {
  13223. const curveObject = recipientInfo.recipientCertificate.subjectPublicKeyInfo.algorithm.algorithmParams;
  13224. if (curveObject.constructor.blockName() !== asn1js__namespace.ObjectIdentifier.blockName())
  13225. throw new Error(`Incorrect "recipientCertificate" for index ${index}`);
  13226. const curveOID = curveObject.valueBlock.toString();
  13227. switch (curveOID) {
  13228. case "1.2.840.10045.3.1.7":
  13229. recipientCurve = "P-256";
  13230. break;
  13231. case "1.3.132.0.34":
  13232. recipientCurve = "P-384";
  13233. break;
  13234. case "1.3.132.0.35":
  13235. recipientCurve = "P-521";
  13236. break;
  13237. default:
  13238. throw new Error(`Incorrect curve OID for index ${index}`);
  13239. }
  13240. recipientPublicKey = await recipientInfo.recipientCertificate.getPublicKey({
  13241. algorithm: {
  13242. algorithm: {
  13243. name: "ECDH",
  13244. namedCurve: recipientCurve
  13245. },
  13246. usages: []
  13247. }
  13248. }, crypto);
  13249. }
  13250. else {
  13251. throw new Error("Unsupported RecipientInfo");
  13252. }
  13253. const recipientCurveLength = curveLengthByName[recipientCurve];
  13254. const ecdhKeys = await crypto.generateKey({ name: "ECDH", namedCurve: recipientCurve }, true, ["deriveBits"]);
  13255. const exportedECDHPublicKey = await crypto.exportKey("spki", ecdhKeys.publicKey);
  13256. const derivedBits = await crypto.deriveBits({
  13257. name: "ECDH",
  13258. public: recipientPublicKey
  13259. }, ecdhKeys.privateKey, recipientCurveLength);
  13260. const aesKWAlgorithm = new AlgorithmIdentifier({ schema: recipientInfo.keyEncryptionAlgorithm.algorithmParams });
  13261. const kwAlgorithm = crypto.getAlgorithmByOID(aesKWAlgorithm.algorithmId, true, "aesKWAlgorithm");
  13262. let kwLength = kwAlgorithm.length;
  13263. const kwLengthBuffer = new ArrayBuffer(4);
  13264. const kwLengthView = new Uint8Array(kwLengthBuffer);
  13265. for (let j = 3; j >= 0; j--) {
  13266. kwLengthView[j] = kwLength;
  13267. kwLength >>= 8;
  13268. }
  13269. const eccInfo = new ECCCMSSharedInfo({
  13270. keyInfo: new AlgorithmIdentifier({
  13271. algorithmId: aesKWAlgorithm.algorithmId
  13272. }),
  13273. entityUInfo: recipientInfo.ukm,
  13274. suppPubInfo: new asn1js__namespace.OctetString({ valueHex: kwLengthBuffer })
  13275. });
  13276. const encodedInfo = eccInfo.toSchema().toBER(false);
  13277. const ecdhAlgorithm = crypto.getAlgorithmByOID(recipientInfo.keyEncryptionAlgorithm.algorithmId, true, "ecdhAlgorithm");
  13278. const derivedKeyRaw = await kdf(ecdhAlgorithm.kdf, derivedBits, kwAlgorithm.length, encodedInfo, crypto);
  13279. const awsKW = await crypto.importKey("raw", derivedKeyRaw, { name: "AES-KW" }, true, ["wrapKey"]);
  13280. const wrappedKey = await crypto.wrapKey("raw", sessionKey, awsKW, { name: "AES-KW" });
  13281. const originator = new OriginatorIdentifierOrKey();
  13282. originator.variant = 3;
  13283. originator.value = OriginatorPublicKey.fromBER(exportedECDHPublicKey);
  13284. recipientInfo.originator = originator;
  13285. recipientInfo.recipientEncryptedKeys.encryptedKeys[0].encryptedKey = new asn1js__namespace.OctetString({ valueHex: wrappedKey });
  13286. return { ecdhPrivateKey: ecdhKeys.privateKey };
  13287. };
  13288. const SubKeyTransRecipientInfo = async (index) => {
  13289. const recipientInfo = this.recipientInfos[index].value;
  13290. const algorithmParameters = crypto.getAlgorithmByOID(recipientInfo.keyEncryptionAlgorithm.algorithmId, true, "keyEncryptionAlgorithm");
  13291. if (algorithmParameters.name === "RSA-OAEP") {
  13292. const schema = recipientInfo.keyEncryptionAlgorithm.algorithmParams;
  13293. const rsaOAEPParams = new RSAESOAEPParams({ schema });
  13294. algorithmParameters.hash = crypto.getAlgorithmByOID(rsaOAEPParams.hashAlgorithm.algorithmId);
  13295. if (("name" in algorithmParameters.hash) === false)
  13296. throw new Error(`Incorrect OID for hash algorithm: ${rsaOAEPParams.hashAlgorithm.algorithmId}`);
  13297. }
  13298. try {
  13299. const publicKey = await recipientInfo.recipientCertificate.getPublicKey({
  13300. algorithm: {
  13301. algorithm: algorithmParameters,
  13302. usages: ["encrypt", "wrapKey"]
  13303. }
  13304. }, crypto);
  13305. const encryptedKey = await crypto.encrypt(publicKey.algorithm, publicKey, exportedSessionKey);
  13306. recipientInfo.encryptedKey = new asn1js__namespace.OctetString({ valueHex: encryptedKey });
  13307. }
  13308. catch {
  13309. }
  13310. };
  13311. const SubKEKRecipientInfo = async (index) => {
  13312. const recipientInfo = this.recipientInfos[index].value;
  13313. const kekAlgorithm = crypto.getAlgorithmByOID(recipientInfo.keyEncryptionAlgorithm.algorithmId, true, "kekAlgorithm");
  13314. const kekKey = await crypto.importKey("raw", new Uint8Array(recipientInfo.preDefinedKEK), kekAlgorithm, true, ["wrapKey"]);
  13315. const wrappedKey = await crypto.wrapKey("raw", sessionKey, kekKey, kekAlgorithm);
  13316. recipientInfo.encryptedKey = new asn1js__namespace.OctetString({ valueHex: wrappedKey });
  13317. };
  13318. const SubPasswordRecipientinfo = async (index) => {
  13319. const recipientInfo = this.recipientInfos[index].value;
  13320. let pbkdf2Params;
  13321. if (!recipientInfo.keyDerivationAlgorithm)
  13322. throw new Error("Please append encoded \"keyDerivationAlgorithm\"");
  13323. if (!recipientInfo.keyDerivationAlgorithm.algorithmParams)
  13324. throw new Error("Incorrectly encoded \"keyDerivationAlgorithm\"");
  13325. try {
  13326. pbkdf2Params = new PBKDF2Params({ schema: recipientInfo.keyDerivationAlgorithm.algorithmParams });
  13327. }
  13328. catch {
  13329. throw new Error("Incorrectly encoded \"keyDerivationAlgorithm\"");
  13330. }
  13331. const passwordView = new Uint8Array(recipientInfo.password);
  13332. const derivationKey = await crypto.importKey("raw", passwordView, "PBKDF2", false, ["deriveKey"]);
  13333. const kekAlgorithm = crypto.getAlgorithmByOID(recipientInfo.keyEncryptionAlgorithm.algorithmId, true, "kekAlgorithm");
  13334. let hmacHashAlgorithm = "SHA-1";
  13335. if (pbkdf2Params.prf) {
  13336. const prfAlgorithm = crypto.getAlgorithmByOID(pbkdf2Params.prf.algorithmId, true, "prfAlgorithm");
  13337. hmacHashAlgorithm = prfAlgorithm.hash.name;
  13338. }
  13339. const saltView = new Uint8Array(pbkdf2Params.salt.valueBlock.valueHex);
  13340. const iterations = pbkdf2Params.iterationCount;
  13341. const derivedKey = await crypto.deriveKey({
  13342. name: "PBKDF2",
  13343. hash: {
  13344. name: hmacHashAlgorithm
  13345. },
  13346. salt: saltView,
  13347. iterations
  13348. }, derivationKey, kekAlgorithm, true, ["wrapKey"]);
  13349. const wrappedKey = await crypto.wrapKey("raw", sessionKey, derivedKey, kekAlgorithm);
  13350. recipientInfo.encryptedKey = new asn1js__namespace.OctetString({ valueHex: wrappedKey });
  13351. };
  13352. const res = [];
  13353. for (let i = 0; i < this.recipientInfos.length; i++) {
  13354. switch (this.recipientInfos[i].variant) {
  13355. case 1:
  13356. res.push(await SubKeyTransRecipientInfo(i));
  13357. break;
  13358. case 2:
  13359. res.push(await SubKeyAgreeRecipientInfo(i));
  13360. break;
  13361. case 3:
  13362. res.push(await SubKEKRecipientInfo(i));
  13363. break;
  13364. case 4:
  13365. res.push(await SubPasswordRecipientinfo(i));
  13366. break;
  13367. default:
  13368. throw new Error(`Unknown recipient type in array with index ${i}`);
  13369. }
  13370. }
  13371. return res;
  13372. }
  13373. async decrypt(recipientIndex, parameters, crypto = getCrypto(true)) {
  13374. const decryptionParameters = parameters || {};
  13375. if ((recipientIndex + 1) > this.recipientInfos.length) {
  13376. throw new Error(`Maximum value for "index" is: ${this.recipientInfos.length - 1}`);
  13377. }
  13378. const SubKeyAgreeRecipientInfo = async (index) => {
  13379. const recipientInfo = this.recipientInfos[index].value;
  13380. let curveOID;
  13381. let recipientCurve;
  13382. let recipientCurveLength;
  13383. const originator = recipientInfo.originator;
  13384. if (decryptionParameters.recipientCertificate) {
  13385. const curveObject = decryptionParameters.recipientCertificate.subjectPublicKeyInfo.algorithm.algorithmParams;
  13386. if (curveObject.constructor.blockName() !== asn1js__namespace.ObjectIdentifier.blockName()) {
  13387. throw new Error(`Incorrect "recipientCertificate" for index ${index}`);
  13388. }
  13389. curveOID = curveObject.valueBlock.toString();
  13390. }
  13391. else if (originator.value.algorithm.algorithmParams) {
  13392. const curveObject = originator.value.algorithm.algorithmParams;
  13393. if (curveObject.constructor.blockName() !== asn1js__namespace.ObjectIdentifier.blockName()) {
  13394. throw new Error(`Incorrect originator for index ${index}`);
  13395. }
  13396. curveOID = curveObject.valueBlock.toString();
  13397. }
  13398. else {
  13399. throw new Error("Parameter \"recipientCertificate\" is mandatory for \"KeyAgreeRecipientInfo\" if algorithm params are missing from originator");
  13400. }
  13401. if (!decryptionParameters.recipientPrivateKey)
  13402. throw new Error("Parameter \"recipientPrivateKey\" is mandatory for \"KeyAgreeRecipientInfo\"");
  13403. switch (curveOID) {
  13404. case "1.2.840.10045.3.1.7":
  13405. recipientCurve = "P-256";
  13406. recipientCurveLength = 256;
  13407. break;
  13408. case "1.3.132.0.34":
  13409. recipientCurve = "P-384";
  13410. recipientCurveLength = 384;
  13411. break;
  13412. case "1.3.132.0.35":
  13413. recipientCurve = "P-521";
  13414. recipientCurveLength = 528;
  13415. break;
  13416. default:
  13417. throw new Error(`Incorrect curve OID for index ${index}`);
  13418. }
  13419. let ecdhPrivateKey;
  13420. let keyCrypto = crypto;
  13421. if (pvtsutils.BufferSourceConverter.isBufferSource(decryptionParameters.recipientPrivateKey)) {
  13422. ecdhPrivateKey = await crypto.importKey("pkcs8", decryptionParameters.recipientPrivateKey, {
  13423. name: "ECDH",
  13424. namedCurve: recipientCurve
  13425. }, true, ["deriveBits"]);
  13426. }
  13427. else {
  13428. ecdhPrivateKey = decryptionParameters.recipientPrivateKey;
  13429. if ("crypto" in decryptionParameters && decryptionParameters.crypto) {
  13430. keyCrypto = decryptionParameters.crypto.subtle;
  13431. }
  13432. }
  13433. if (("algorithmParams" in originator.value.algorithm) === false)
  13434. originator.value.algorithm.algorithmParams = new asn1js__namespace.ObjectIdentifier({ value: curveOID });
  13435. const buffer = originator.value.toSchema().toBER(false);
  13436. const ecdhPublicKey = await crypto.importKey("spki", buffer, {
  13437. name: "ECDH",
  13438. namedCurve: recipientCurve
  13439. }, true, []);
  13440. const sharedSecret = await keyCrypto.deriveBits({
  13441. name: "ECDH",
  13442. public: ecdhPublicKey
  13443. }, ecdhPrivateKey, recipientCurveLength);
  13444. async function applyKDF(includeAlgorithmParams) {
  13445. includeAlgorithmParams = includeAlgorithmParams || false;
  13446. const aesKWAlgorithm = new AlgorithmIdentifier({ schema: recipientInfo.keyEncryptionAlgorithm.algorithmParams });
  13447. const kwAlgorithm = crypto.getAlgorithmByOID(aesKWAlgorithm.algorithmId, true, "kwAlgorithm");
  13448. let kwLength = kwAlgorithm.length;
  13449. const kwLengthBuffer = new ArrayBuffer(4);
  13450. const kwLengthView = new Uint8Array(kwLengthBuffer);
  13451. for (let j = 3; j >= 0; j--) {
  13452. kwLengthView[j] = kwLength;
  13453. kwLength >>= 8;
  13454. }
  13455. const keyInfoAlgorithm = {
  13456. algorithmId: aesKWAlgorithm.algorithmId
  13457. };
  13458. if (includeAlgorithmParams) {
  13459. keyInfoAlgorithm.algorithmParams = new asn1js__namespace.Null();
  13460. }
  13461. const eccInfo = new ECCCMSSharedInfo({
  13462. keyInfo: new AlgorithmIdentifier(keyInfoAlgorithm),
  13463. entityUInfo: recipientInfo.ukm,
  13464. suppPubInfo: new asn1js__namespace.OctetString({ valueHex: kwLengthBuffer })
  13465. });
  13466. const encodedInfo = eccInfo.toSchema().toBER(false);
  13467. const ecdhAlgorithm = crypto.getAlgorithmByOID(recipientInfo.keyEncryptionAlgorithm.algorithmId, true, "ecdhAlgorithm");
  13468. if (!ecdhAlgorithm.name) {
  13469. throw new Error(`Incorrect OID for key encryption algorithm: ${recipientInfo.keyEncryptionAlgorithm.algorithmId}`);
  13470. }
  13471. return kdf(ecdhAlgorithm.kdf, sharedSecret, kwAlgorithm.length, encodedInfo, crypto);
  13472. }
  13473. const kdfResult = await applyKDF();
  13474. const importAesKwKey = async (kdfResult) => {
  13475. return crypto.importKey("raw", kdfResult, { name: "AES-KW" }, true, ["unwrapKey"]);
  13476. };
  13477. const aesKwKey = await importAesKwKey(kdfResult);
  13478. const unwrapSessionKey = async (aesKwKey) => {
  13479. const algorithmId = this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId;
  13480. const contentEncryptionAlgorithm = crypto.getAlgorithmByOID(algorithmId, true, "contentEncryptionAlgorithm");
  13481. return crypto.unwrapKey("raw", recipientInfo.recipientEncryptedKeys.encryptedKeys[0].encryptedKey.valueBlock.valueHexView, aesKwKey, { name: "AES-KW" }, contentEncryptionAlgorithm, true, ["decrypt"]);
  13482. };
  13483. try {
  13484. return await unwrapSessionKey(aesKwKey);
  13485. }
  13486. catch {
  13487. const kdfResult = await applyKDF(true);
  13488. const aesKwKey = await importAesKwKey(kdfResult);
  13489. return unwrapSessionKey(aesKwKey);
  13490. }
  13491. };
  13492. const SubKeyTransRecipientInfo = async (index) => {
  13493. const recipientInfo = this.recipientInfos[index].value;
  13494. if (!decryptionParameters.recipientPrivateKey) {
  13495. throw new Error("Parameter \"recipientPrivateKey\" is mandatory for \"KeyTransRecipientInfo\"");
  13496. }
  13497. const algorithmParameters = crypto.getAlgorithmByOID(recipientInfo.keyEncryptionAlgorithm.algorithmId, true, "keyEncryptionAlgorithm");
  13498. if (algorithmParameters.name === "RSA-OAEP") {
  13499. const schema = recipientInfo.keyEncryptionAlgorithm.algorithmParams;
  13500. const rsaOAEPParams = new RSAESOAEPParams({ schema });
  13501. algorithmParameters.hash = crypto.getAlgorithmByOID(rsaOAEPParams.hashAlgorithm.algorithmId);
  13502. if (("name" in algorithmParameters.hash) === false)
  13503. throw new Error(`Incorrect OID for hash algorithm: ${rsaOAEPParams.hashAlgorithm.algorithmId}`);
  13504. }
  13505. let privateKey;
  13506. let keyCrypto = crypto;
  13507. if (pvtsutils.BufferSourceConverter.isBufferSource(decryptionParameters.recipientPrivateKey)) {
  13508. privateKey = await crypto.importKey("pkcs8", decryptionParameters.recipientPrivateKey, algorithmParameters, true, ["decrypt"]);
  13509. }
  13510. else {
  13511. privateKey = decryptionParameters.recipientPrivateKey;
  13512. if ("crypto" in decryptionParameters && decryptionParameters.crypto) {
  13513. keyCrypto = decryptionParameters.crypto.subtle;
  13514. }
  13515. }
  13516. const sessionKey = await keyCrypto.decrypt(privateKey.algorithm, privateKey, recipientInfo.encryptedKey.valueBlock.valueHexView);
  13517. const algorithmId = this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId;
  13518. const contentEncryptionAlgorithm = crypto.getAlgorithmByOID(algorithmId, true, "contentEncryptionAlgorithm");
  13519. if (("name" in contentEncryptionAlgorithm) === false)
  13520. throw new Error(`Incorrect "contentEncryptionAlgorithm": ${algorithmId}`);
  13521. return crypto.importKey("raw", sessionKey, contentEncryptionAlgorithm, true, ["decrypt"]);
  13522. };
  13523. const SubKEKRecipientInfo = async (index) => {
  13524. const recipientInfo = this.recipientInfos[index].value;
  13525. if (!decryptionParameters.preDefinedData)
  13526. throw new Error("Parameter \"preDefinedData\" is mandatory for \"KEKRecipientInfo\"");
  13527. const kekAlgorithm = crypto.getAlgorithmByOID(recipientInfo.keyEncryptionAlgorithm.algorithmId, true, "kekAlgorithm");
  13528. const importedKey = await crypto.importKey("raw", decryptionParameters.preDefinedData, kekAlgorithm, true, ["unwrapKey"]);
  13529. const algorithmId = this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId;
  13530. const contentEncryptionAlgorithm = crypto.getAlgorithmByOID(algorithmId, true, "contentEncryptionAlgorithm");
  13531. if (!contentEncryptionAlgorithm.name) {
  13532. throw new Error(`Incorrect "contentEncryptionAlgorithm": ${algorithmId}`);
  13533. }
  13534. return crypto.unwrapKey("raw", recipientInfo.encryptedKey.valueBlock.valueHexView, importedKey, kekAlgorithm, contentEncryptionAlgorithm, true, ["decrypt"]);
  13535. };
  13536. const SubPasswordRecipientinfo = async (index) => {
  13537. const recipientInfo = this.recipientInfos[index].value;
  13538. let pbkdf2Params;
  13539. if (!decryptionParameters.preDefinedData) {
  13540. throw new Error("Parameter \"preDefinedData\" is mandatory for \"KEKRecipientInfo\"");
  13541. }
  13542. if (!recipientInfo.keyDerivationAlgorithm) {
  13543. throw new Error("Please append encoded \"keyDerivationAlgorithm\"");
  13544. }
  13545. if (!recipientInfo.keyDerivationAlgorithm.algorithmParams) {
  13546. throw new Error("Incorrectly encoded \"keyDerivationAlgorithm\"");
  13547. }
  13548. try {
  13549. pbkdf2Params = new PBKDF2Params({ schema: recipientInfo.keyDerivationAlgorithm.algorithmParams });
  13550. }
  13551. catch {
  13552. throw new Error("Incorrectly encoded \"keyDerivationAlgorithm\"");
  13553. }
  13554. const pbkdf2Key = await crypto.importKey("raw", decryptionParameters.preDefinedData, "PBKDF2", false, ["deriveKey"]);
  13555. const kekAlgorithm = crypto.getAlgorithmByOID(recipientInfo.keyEncryptionAlgorithm.algorithmId, true, "keyEncryptionAlgorithm");
  13556. const hmacHashAlgorithm = pbkdf2Params.prf
  13557. ? crypto.getAlgorithmByOID(pbkdf2Params.prf.algorithmId, true, "prfAlgorithm").hash.name
  13558. : "SHA-1";
  13559. const saltView = new Uint8Array(pbkdf2Params.salt.valueBlock.valueHex);
  13560. const iterations = pbkdf2Params.iterationCount;
  13561. const kekKey = await crypto.deriveKey({
  13562. name: "PBKDF2",
  13563. hash: {
  13564. name: hmacHashAlgorithm
  13565. },
  13566. salt: saltView,
  13567. iterations
  13568. }, pbkdf2Key, kekAlgorithm, true, ["unwrapKey"]);
  13569. const algorithmId = this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId;
  13570. const contentEncryptionAlgorithm = crypto.getAlgorithmByOID(algorithmId, true, "contentEncryptionAlgorithm");
  13571. return crypto.unwrapKey("raw", recipientInfo.encryptedKey.valueBlock.valueHexView, kekKey, kekAlgorithm, contentEncryptionAlgorithm, true, ["decrypt"]);
  13572. };
  13573. let unwrappedKey;
  13574. switch (this.recipientInfos[recipientIndex].variant) {
  13575. case 1:
  13576. unwrappedKey = await SubKeyTransRecipientInfo(recipientIndex);
  13577. break;
  13578. case 2:
  13579. unwrappedKey = await SubKeyAgreeRecipientInfo(recipientIndex);
  13580. break;
  13581. case 3:
  13582. unwrappedKey = await SubKEKRecipientInfo(recipientIndex);
  13583. break;
  13584. case 4:
  13585. unwrappedKey = await SubPasswordRecipientinfo(recipientIndex);
  13586. break;
  13587. default:
  13588. throw new Error(`Unknown recipient type in array with index ${recipientIndex}`);
  13589. }
  13590. const algorithmId = this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmId;
  13591. const contentEncryptionAlgorithm = crypto.getAlgorithmByOID(algorithmId, true, "contentEncryptionAlgorithm");
  13592. const ivBuffer = this.encryptedContentInfo.contentEncryptionAlgorithm.algorithmParams.valueBlock.valueHex;
  13593. const ivView = new Uint8Array(ivBuffer);
  13594. if (!this.encryptedContentInfo.encryptedContent) {
  13595. throw new Error("Required property `encryptedContent` is empty");
  13596. }
  13597. const dataBuffer = this.encryptedContentInfo.getEncryptedContent();
  13598. return crypto.decrypt({
  13599. name: contentEncryptionAlgorithm.name,
  13600. iv: ivView
  13601. }, unwrappedKey, dataBuffer);
  13602. }
  13603. }
  13604. EnvelopedData.CLASS_NAME = "EnvelopedData";
  13605. const SAFE_CONTENTS = "safeContents";
  13606. const PARSED_VALUE$1 = "parsedValue";
  13607. const CONTENT_INFOS = "contentInfos";
  13608. class AuthenticatedSafe extends PkiObject {
  13609. constructor(parameters = {}) {
  13610. super();
  13611. this.safeContents = pvutils__namespace.getParametersValue(parameters, SAFE_CONTENTS, AuthenticatedSafe.defaultValues(SAFE_CONTENTS));
  13612. if (PARSED_VALUE$1 in parameters) {
  13613. this.parsedValue = pvutils__namespace.getParametersValue(parameters, PARSED_VALUE$1, AuthenticatedSafe.defaultValues(PARSED_VALUE$1));
  13614. }
  13615. if (parameters.schema) {
  13616. this.fromSchema(parameters.schema);
  13617. }
  13618. }
  13619. static defaultValues(memberName) {
  13620. switch (memberName) {
  13621. case SAFE_CONTENTS:
  13622. return [];
  13623. case PARSED_VALUE$1:
  13624. return {};
  13625. default:
  13626. return super.defaultValues(memberName);
  13627. }
  13628. }
  13629. static compareWithDefault(memberName, memberValue) {
  13630. switch (memberName) {
  13631. case SAFE_CONTENTS:
  13632. return (memberValue.length === 0);
  13633. case PARSED_VALUE$1:
  13634. return ((memberValue instanceof Object) && (Object.keys(memberValue).length === 0));
  13635. default:
  13636. return super.defaultValues(memberName);
  13637. }
  13638. }
  13639. static schema(parameters = {}) {
  13640. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  13641. return (new asn1js__namespace.Sequence({
  13642. name: (names.blockName || EMPTY_STRING),
  13643. value: [
  13644. new asn1js__namespace.Repeated({
  13645. name: (names.contentInfos || EMPTY_STRING),
  13646. value: ContentInfo.schema()
  13647. })
  13648. ]
  13649. }));
  13650. }
  13651. fromSchema(schema) {
  13652. pvutils__namespace.clearProps(schema, [
  13653. CONTENT_INFOS
  13654. ]);
  13655. const asn1 = asn1js__namespace.compareSchema(schema, schema, AuthenticatedSafe.schema({
  13656. names: {
  13657. contentInfos: CONTENT_INFOS
  13658. }
  13659. }));
  13660. AsnError.assertSchema(asn1, this.className);
  13661. this.safeContents = Array.from(asn1.result.contentInfos, element => new ContentInfo({ schema: element }));
  13662. }
  13663. toSchema() {
  13664. return (new asn1js__namespace.Sequence({
  13665. value: Array.from(this.safeContents, o => o.toSchema())
  13666. }));
  13667. }
  13668. toJSON() {
  13669. return {
  13670. safeContents: Array.from(this.safeContents, o => o.toJSON())
  13671. };
  13672. }
  13673. async parseInternalValues(parameters, crypto = getCrypto(true)) {
  13674. ParameterError.assert(parameters, SAFE_CONTENTS);
  13675. ArgumentError.assert(parameters.safeContents, SAFE_CONTENTS, "Array");
  13676. if (parameters.safeContents.length !== this.safeContents.length) {
  13677. throw new ArgumentError("Length of \"parameters.safeContents\" must be equal to \"this.safeContents.length\"");
  13678. }
  13679. this.parsedValue = {
  13680. safeContents: [],
  13681. };
  13682. for (const [index, content] of this.safeContents.entries()) {
  13683. const safeContent = parameters.safeContents[index];
  13684. const errorTarget = `parameters.safeContents[${index}]`;
  13685. switch (content.contentType) {
  13686. case id_ContentType_Data:
  13687. {
  13688. ArgumentError.assert(content.content, "this.safeContents[j].content", asn1js__namespace.OctetString);
  13689. const authSafeContent = content.content.getValue();
  13690. this.parsedValue.safeContents.push({
  13691. privacyMode: 0,
  13692. value: SafeContents.fromBER(authSafeContent)
  13693. });
  13694. }
  13695. break;
  13696. case id_ContentType_EnvelopedData:
  13697. {
  13698. const cmsEnveloped = new EnvelopedData({ schema: content.content });
  13699. ParameterError.assert(errorTarget, safeContent, "recipientCertificate", "recipientKey");
  13700. const envelopedData = safeContent;
  13701. const recipientCertificate = envelopedData.recipientCertificate;
  13702. const recipientKey = envelopedData.recipientKey;
  13703. const decrypted = await cmsEnveloped.decrypt(0, {
  13704. recipientCertificate,
  13705. recipientPrivateKey: recipientKey
  13706. }, crypto);
  13707. this.parsedValue.safeContents.push({
  13708. privacyMode: 2,
  13709. value: SafeContents.fromBER(decrypted),
  13710. });
  13711. }
  13712. break;
  13713. case id_ContentType_EncryptedData:
  13714. {
  13715. const cmsEncrypted = new EncryptedData({ schema: content.content });
  13716. ParameterError.assert(errorTarget, safeContent, "password");
  13717. const password = safeContent.password;
  13718. const decrypted = await cmsEncrypted.decrypt({
  13719. password
  13720. }, crypto);
  13721. this.parsedValue.safeContents.push({
  13722. privacyMode: 1,
  13723. value: SafeContents.fromBER(decrypted),
  13724. });
  13725. }
  13726. break;
  13727. default:
  13728. throw new Error(`Unknown "contentType" for AuthenticatedSafe: " ${content.contentType}`);
  13729. }
  13730. }
  13731. }
  13732. async makeInternalValues(parameters, crypto = getCrypto(true)) {
  13733. if (!(this.parsedValue)) {
  13734. throw new Error("Please run \"parseValues\" first or add \"parsedValue\" manually");
  13735. }
  13736. ArgumentError.assert(this.parsedValue, "this.parsedValue", "object");
  13737. ArgumentError.assert(this.parsedValue.safeContents, "this.parsedValue.safeContents", "Array");
  13738. ArgumentError.assert(parameters, "parameters", "object");
  13739. ParameterError.assert(parameters, "safeContents");
  13740. ArgumentError.assert(parameters.safeContents, "parameters.safeContents", "Array");
  13741. if (parameters.safeContents.length !== this.parsedValue.safeContents.length) {
  13742. throw new ArgumentError("Length of \"parameters.safeContents\" must be equal to \"this.parsedValue.safeContents\"");
  13743. }
  13744. this.safeContents = [];
  13745. for (const [index, content] of this.parsedValue.safeContents.entries()) {
  13746. ParameterError.assert("content", content, "privacyMode", "value");
  13747. ArgumentError.assert(content.value, "content.value", SafeContents);
  13748. switch (content.privacyMode) {
  13749. case 0:
  13750. {
  13751. const contentBuffer = content.value.toSchema().toBER(false);
  13752. this.safeContents.push(new ContentInfo({
  13753. contentType: "1.2.840.113549.1.7.1",
  13754. content: new asn1js__namespace.OctetString({ valueHex: contentBuffer })
  13755. }));
  13756. }
  13757. break;
  13758. case 1:
  13759. {
  13760. const cmsEncrypted = new EncryptedData();
  13761. const currentParameters = parameters.safeContents[index];
  13762. currentParameters.contentToEncrypt = content.value.toSchema().toBER(false);
  13763. await cmsEncrypted.encrypt(currentParameters, crypto);
  13764. this.safeContents.push(new ContentInfo({
  13765. contentType: "1.2.840.113549.1.7.6",
  13766. content: cmsEncrypted.toSchema()
  13767. }));
  13768. }
  13769. break;
  13770. case 2:
  13771. {
  13772. const cmsEnveloped = new EnvelopedData();
  13773. const contentToEncrypt = content.value.toSchema().toBER(false);
  13774. const safeContent = parameters.safeContents[index];
  13775. ParameterError.assert(`parameters.safeContents[${index}]`, safeContent, "encryptingCertificate", "encryptionAlgorithm");
  13776. switch (true) {
  13777. case (safeContent.encryptionAlgorithm.name.toLowerCase() === "aes-cbc"):
  13778. case (safeContent.encryptionAlgorithm.name.toLowerCase() === "aes-gcm"):
  13779. break;
  13780. default:
  13781. throw new Error(`Incorrect parameter "encryptionAlgorithm" in "parameters.safeContents[i]": ${safeContent.encryptionAlgorithm}`);
  13782. }
  13783. switch (true) {
  13784. case (safeContent.encryptionAlgorithm.length === 128):
  13785. case (safeContent.encryptionAlgorithm.length === 192):
  13786. case (safeContent.encryptionAlgorithm.length === 256):
  13787. break;
  13788. default:
  13789. throw new Error(`Incorrect parameter "encryptionAlgorithm.length" in "parameters.safeContents[i]": ${safeContent.encryptionAlgorithm.length}`);
  13790. }
  13791. const encryptionAlgorithm = safeContent.encryptionAlgorithm;
  13792. cmsEnveloped.addRecipientByCertificate(safeContent.encryptingCertificate, {}, undefined, crypto);
  13793. await cmsEnveloped.encrypt(encryptionAlgorithm, contentToEncrypt, crypto);
  13794. this.safeContents.push(new ContentInfo({
  13795. contentType: "1.2.840.113549.1.7.3",
  13796. content: cmsEnveloped.toSchema()
  13797. }));
  13798. }
  13799. break;
  13800. default:
  13801. throw new Error(`Incorrect value for "content.privacyMode": ${content.privacyMode}`);
  13802. }
  13803. }
  13804. return this;
  13805. }
  13806. }
  13807. AuthenticatedSafe.CLASS_NAME = "AuthenticatedSafe";
  13808. const HASH_ALGORITHM$1 = "hashAlgorithm";
  13809. const ISSUER_NAME_HASH = "issuerNameHash";
  13810. const ISSUER_KEY_HASH = "issuerKeyHash";
  13811. const SERIAL_NUMBER$1 = "serialNumber";
  13812. const CLEAR_PROPS$j = [
  13813. HASH_ALGORITHM$1,
  13814. ISSUER_NAME_HASH,
  13815. ISSUER_KEY_HASH,
  13816. SERIAL_NUMBER$1,
  13817. ];
  13818. class CertID extends PkiObject {
  13819. static async create(certificate, parameters, crypto = getCrypto(true)) {
  13820. const certID = new CertID();
  13821. await certID.createForCertificate(certificate, parameters, crypto);
  13822. return certID;
  13823. }
  13824. constructor(parameters = {}) {
  13825. super();
  13826. this.hashAlgorithm = pvutils__namespace.getParametersValue(parameters, HASH_ALGORITHM$1, CertID.defaultValues(HASH_ALGORITHM$1));
  13827. this.issuerNameHash = pvutils__namespace.getParametersValue(parameters, ISSUER_NAME_HASH, CertID.defaultValues(ISSUER_NAME_HASH));
  13828. this.issuerKeyHash = pvutils__namespace.getParametersValue(parameters, ISSUER_KEY_HASH, CertID.defaultValues(ISSUER_KEY_HASH));
  13829. this.serialNumber = pvutils__namespace.getParametersValue(parameters, SERIAL_NUMBER$1, CertID.defaultValues(SERIAL_NUMBER$1));
  13830. if (parameters.schema) {
  13831. this.fromSchema(parameters.schema);
  13832. }
  13833. }
  13834. static defaultValues(memberName) {
  13835. switch (memberName) {
  13836. case HASH_ALGORITHM$1:
  13837. return new AlgorithmIdentifier();
  13838. case ISSUER_NAME_HASH:
  13839. case ISSUER_KEY_HASH:
  13840. return new asn1js__namespace.OctetString();
  13841. case SERIAL_NUMBER$1:
  13842. return new asn1js__namespace.Integer();
  13843. default:
  13844. return super.defaultValues(memberName);
  13845. }
  13846. }
  13847. static compareWithDefault(memberName, memberValue) {
  13848. switch (memberName) {
  13849. case HASH_ALGORITHM$1:
  13850. return ((memberValue.algorithmId === EMPTY_STRING) && (("algorithmParams" in memberValue) === false));
  13851. case ISSUER_NAME_HASH:
  13852. case ISSUER_KEY_HASH:
  13853. case SERIAL_NUMBER$1:
  13854. return (memberValue.isEqual(CertID.defaultValues(SERIAL_NUMBER$1)));
  13855. default:
  13856. return super.defaultValues(memberName);
  13857. }
  13858. }
  13859. static schema(parameters = {}) {
  13860. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  13861. return (new asn1js__namespace.Sequence({
  13862. name: (names.blockName || EMPTY_STRING),
  13863. value: [
  13864. AlgorithmIdentifier.schema(names.hashAlgorithmObject || {
  13865. names: {
  13866. blockName: (names.hashAlgorithm || EMPTY_STRING)
  13867. }
  13868. }),
  13869. new asn1js__namespace.OctetString({ name: (names.issuerNameHash || EMPTY_STRING) }),
  13870. new asn1js__namespace.OctetString({ name: (names.issuerKeyHash || EMPTY_STRING) }),
  13871. new asn1js__namespace.Integer({ name: (names.serialNumber || EMPTY_STRING) })
  13872. ]
  13873. }));
  13874. }
  13875. fromSchema(schema) {
  13876. pvutils__namespace.clearProps(schema, CLEAR_PROPS$j);
  13877. const asn1 = asn1js__namespace.compareSchema(schema, schema, CertID.schema({
  13878. names: {
  13879. hashAlgorithm: HASH_ALGORITHM$1,
  13880. issuerNameHash: ISSUER_NAME_HASH,
  13881. issuerKeyHash: ISSUER_KEY_HASH,
  13882. serialNumber: SERIAL_NUMBER$1
  13883. }
  13884. }));
  13885. AsnError.assertSchema(asn1, this.className);
  13886. this.hashAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.hashAlgorithm });
  13887. this.issuerNameHash = asn1.result.issuerNameHash;
  13888. this.issuerKeyHash = asn1.result.issuerKeyHash;
  13889. this.serialNumber = asn1.result.serialNumber;
  13890. }
  13891. toSchema() {
  13892. return (new asn1js__namespace.Sequence({
  13893. value: [
  13894. this.hashAlgorithm.toSchema(),
  13895. this.issuerNameHash,
  13896. this.issuerKeyHash,
  13897. this.serialNumber
  13898. ]
  13899. }));
  13900. }
  13901. toJSON() {
  13902. return {
  13903. hashAlgorithm: this.hashAlgorithm.toJSON(),
  13904. issuerNameHash: this.issuerNameHash.toJSON(),
  13905. issuerKeyHash: this.issuerKeyHash.toJSON(),
  13906. serialNumber: this.serialNumber.toJSON(),
  13907. };
  13908. }
  13909. isEqual(certificateID) {
  13910. if (this.hashAlgorithm.algorithmId !== certificateID.hashAlgorithm.algorithmId) {
  13911. return false;
  13912. }
  13913. if (!pvtsutils__namespace.BufferSourceConverter.isEqual(this.issuerNameHash.valueBlock.valueHexView, certificateID.issuerNameHash.valueBlock.valueHexView)) {
  13914. return false;
  13915. }
  13916. if (!pvtsutils__namespace.BufferSourceConverter.isEqual(this.issuerKeyHash.valueBlock.valueHexView, certificateID.issuerKeyHash.valueBlock.valueHexView)) {
  13917. return false;
  13918. }
  13919. if (!this.serialNumber.isEqual(certificateID.serialNumber)) {
  13920. return false;
  13921. }
  13922. return true;
  13923. }
  13924. async createForCertificate(certificate, parameters, crypto = getCrypto(true)) {
  13925. ParameterError.assert(parameters, HASH_ALGORITHM$1, "issuerCertificate");
  13926. const hashOID = crypto.getOIDByAlgorithm({ name: parameters.hashAlgorithm }, true, "hashAlgorithm");
  13927. this.hashAlgorithm = new AlgorithmIdentifier({
  13928. algorithmId: hashOID,
  13929. algorithmParams: new asn1js__namespace.Null()
  13930. });
  13931. const issuerCertificate = parameters.issuerCertificate;
  13932. this.serialNumber = certificate.serialNumber;
  13933. const hashIssuerName = await crypto.digest({ name: parameters.hashAlgorithm }, issuerCertificate.subject.toSchema().toBER(false));
  13934. this.issuerNameHash = new asn1js__namespace.OctetString({ valueHex: hashIssuerName });
  13935. const issuerKeyBuffer = issuerCertificate.subjectPublicKeyInfo.subjectPublicKey.valueBlock.valueHexView;
  13936. const hashIssuerKey = await crypto.digest({ name: parameters.hashAlgorithm }, issuerKeyBuffer);
  13937. this.issuerKeyHash = new asn1js__namespace.OctetString({ valueHex: hashIssuerKey });
  13938. }
  13939. }
  13940. CertID.CLASS_NAME = "CertID";
  13941. const CERT_ID = "certID";
  13942. const CERT_STATUS = "certStatus";
  13943. const THIS_UPDATE = "thisUpdate";
  13944. const NEXT_UPDATE = "nextUpdate";
  13945. const SINGLE_EXTENSIONS = "singleExtensions";
  13946. const CLEAR_PROPS$i = [
  13947. CERT_ID,
  13948. CERT_STATUS,
  13949. THIS_UPDATE,
  13950. NEXT_UPDATE,
  13951. SINGLE_EXTENSIONS,
  13952. ];
  13953. class SingleResponse extends PkiObject {
  13954. constructor(parameters = {}) {
  13955. super();
  13956. this.certID = pvutils__namespace.getParametersValue(parameters, CERT_ID, SingleResponse.defaultValues(CERT_ID));
  13957. this.certStatus = pvutils__namespace.getParametersValue(parameters, CERT_STATUS, SingleResponse.defaultValues(CERT_STATUS));
  13958. this.thisUpdate = pvutils__namespace.getParametersValue(parameters, THIS_UPDATE, SingleResponse.defaultValues(THIS_UPDATE));
  13959. if (NEXT_UPDATE in parameters) {
  13960. this.nextUpdate = pvutils__namespace.getParametersValue(parameters, NEXT_UPDATE, SingleResponse.defaultValues(NEXT_UPDATE));
  13961. }
  13962. if (SINGLE_EXTENSIONS in parameters) {
  13963. this.singleExtensions = pvutils__namespace.getParametersValue(parameters, SINGLE_EXTENSIONS, SingleResponse.defaultValues(SINGLE_EXTENSIONS));
  13964. }
  13965. if (parameters.schema) {
  13966. this.fromSchema(parameters.schema);
  13967. }
  13968. }
  13969. static defaultValues(memberName) {
  13970. switch (memberName) {
  13971. case CERT_ID:
  13972. return new CertID();
  13973. case CERT_STATUS:
  13974. return {};
  13975. case THIS_UPDATE:
  13976. case NEXT_UPDATE:
  13977. return new Date(0, 0, 0);
  13978. case SINGLE_EXTENSIONS:
  13979. return [];
  13980. default:
  13981. return super.defaultValues(memberName);
  13982. }
  13983. }
  13984. static compareWithDefault(memberName, memberValue) {
  13985. switch (memberName) {
  13986. case CERT_ID:
  13987. return ((CertID.compareWithDefault("hashAlgorithm", memberValue.hashAlgorithm)) &&
  13988. (CertID.compareWithDefault("issuerNameHash", memberValue.issuerNameHash)) &&
  13989. (CertID.compareWithDefault("issuerKeyHash", memberValue.issuerKeyHash)) &&
  13990. (CertID.compareWithDefault("serialNumber", memberValue.serialNumber)));
  13991. case CERT_STATUS:
  13992. return (Object.keys(memberValue).length === 0);
  13993. case THIS_UPDATE:
  13994. case NEXT_UPDATE:
  13995. return (memberValue === SingleResponse.defaultValues(memberName));
  13996. default:
  13997. return super.defaultValues(memberName);
  13998. }
  13999. }
  14000. static schema(parameters = {}) {
  14001. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  14002. return (new asn1js__namespace.Sequence({
  14003. name: (names.blockName || EMPTY_STRING),
  14004. value: [
  14005. CertID.schema(names.certID || {}),
  14006. new asn1js__namespace.Choice({
  14007. value: [
  14008. new asn1js__namespace.Primitive({
  14009. name: (names.certStatus || EMPTY_STRING),
  14010. idBlock: {
  14011. tagClass: 3,
  14012. tagNumber: 0
  14013. },
  14014. }),
  14015. new asn1js__namespace.Constructed({
  14016. name: (names.certStatus || EMPTY_STRING),
  14017. idBlock: {
  14018. tagClass: 3,
  14019. tagNumber: 1
  14020. },
  14021. value: [
  14022. new asn1js__namespace.GeneralizedTime(),
  14023. new asn1js__namespace.Constructed({
  14024. optional: true,
  14025. idBlock: {
  14026. tagClass: 3,
  14027. tagNumber: 0
  14028. },
  14029. value: [new asn1js__namespace.Enumerated()]
  14030. })
  14031. ]
  14032. }),
  14033. new asn1js__namespace.Primitive({
  14034. name: (names.certStatus || EMPTY_STRING),
  14035. idBlock: {
  14036. tagClass: 3,
  14037. tagNumber: 2
  14038. },
  14039. lenBlock: { length: 1 }
  14040. })
  14041. ]
  14042. }),
  14043. new asn1js__namespace.GeneralizedTime({ name: (names.thisUpdate || EMPTY_STRING) }),
  14044. new asn1js__namespace.Constructed({
  14045. optional: true,
  14046. idBlock: {
  14047. tagClass: 3,
  14048. tagNumber: 0
  14049. },
  14050. value: [new asn1js__namespace.GeneralizedTime({ name: (names.nextUpdate || EMPTY_STRING) })]
  14051. }),
  14052. new asn1js__namespace.Constructed({
  14053. optional: true,
  14054. idBlock: {
  14055. tagClass: 3,
  14056. tagNumber: 1
  14057. },
  14058. value: [Extensions.schema(names.singleExtensions || {})]
  14059. })
  14060. ]
  14061. }));
  14062. }
  14063. fromSchema(schema) {
  14064. pvutils__namespace.clearProps(schema, CLEAR_PROPS$i);
  14065. const asn1 = asn1js__namespace.compareSchema(schema, schema, SingleResponse.schema({
  14066. names: {
  14067. certID: {
  14068. names: {
  14069. blockName: CERT_ID
  14070. }
  14071. },
  14072. certStatus: CERT_STATUS,
  14073. thisUpdate: THIS_UPDATE,
  14074. nextUpdate: NEXT_UPDATE,
  14075. singleExtensions: {
  14076. names: {
  14077. blockName: SINGLE_EXTENSIONS
  14078. }
  14079. }
  14080. }
  14081. }));
  14082. AsnError.assertSchema(asn1, this.className);
  14083. this.certID = new CertID({ schema: asn1.result.certID });
  14084. this.certStatus = asn1.result.certStatus;
  14085. this.thisUpdate = asn1.result.thisUpdate.toDate();
  14086. if (NEXT_UPDATE in asn1.result)
  14087. this.nextUpdate = asn1.result.nextUpdate.toDate();
  14088. if (SINGLE_EXTENSIONS in asn1.result)
  14089. this.singleExtensions = Array.from(asn1.result.singleExtensions.valueBlock.value, element => new Extension({ schema: element }));
  14090. }
  14091. toSchema() {
  14092. const outputArray = [];
  14093. outputArray.push(this.certID.toSchema());
  14094. outputArray.push(this.certStatus);
  14095. outputArray.push(new asn1js__namespace.GeneralizedTime({ valueDate: this.thisUpdate }));
  14096. if (this.nextUpdate) {
  14097. outputArray.push(new asn1js__namespace.Constructed({
  14098. idBlock: {
  14099. tagClass: 3,
  14100. tagNumber: 0
  14101. },
  14102. value: [new asn1js__namespace.GeneralizedTime({ valueDate: this.nextUpdate })]
  14103. }));
  14104. }
  14105. if (this.singleExtensions) {
  14106. outputArray.push(new asn1js__namespace.Constructed({
  14107. idBlock: {
  14108. tagClass: 3,
  14109. tagNumber: 1
  14110. },
  14111. value: [new asn1js__namespace.Sequence({ value: Array.from(this.singleExtensions, o => o.toSchema()) })]
  14112. }));
  14113. }
  14114. return (new asn1js__namespace.Sequence({
  14115. value: outputArray
  14116. }));
  14117. }
  14118. toJSON() {
  14119. const res = {
  14120. certID: this.certID.toJSON(),
  14121. certStatus: this.certStatus.toJSON(),
  14122. thisUpdate: this.thisUpdate
  14123. };
  14124. if (this.nextUpdate) {
  14125. res.nextUpdate = this.nextUpdate;
  14126. }
  14127. if (this.singleExtensions) {
  14128. res.singleExtensions = Array.from(this.singleExtensions, o => o.toJSON());
  14129. }
  14130. return res;
  14131. }
  14132. }
  14133. SingleResponse.CLASS_NAME = "SingleResponse";
  14134. const TBS$2 = "tbs";
  14135. const VERSION$7 = "version";
  14136. const RESPONDER_ID = "responderID";
  14137. const PRODUCED_AT = "producedAt";
  14138. const RESPONSES = "responses";
  14139. const RESPONSE_EXTENSIONS = "responseExtensions";
  14140. const RESPONSE_DATA = "ResponseData";
  14141. const RESPONSE_DATA_VERSION = `${RESPONSE_DATA}.${VERSION$7}`;
  14142. const RESPONSE_DATA_RESPONDER_ID = `${RESPONSE_DATA}.${RESPONDER_ID}`;
  14143. const RESPONSE_DATA_PRODUCED_AT = `${RESPONSE_DATA}.${PRODUCED_AT}`;
  14144. const RESPONSE_DATA_RESPONSES = `${RESPONSE_DATA}.${RESPONSES}`;
  14145. const RESPONSE_DATA_RESPONSE_EXTENSIONS = `${RESPONSE_DATA}.${RESPONSE_EXTENSIONS}`;
  14146. const CLEAR_PROPS$h = [
  14147. RESPONSE_DATA,
  14148. RESPONSE_DATA_VERSION,
  14149. RESPONSE_DATA_RESPONDER_ID,
  14150. RESPONSE_DATA_PRODUCED_AT,
  14151. RESPONSE_DATA_RESPONSES,
  14152. RESPONSE_DATA_RESPONSE_EXTENSIONS
  14153. ];
  14154. class ResponseData extends PkiObject {
  14155. get tbs() {
  14156. return pvtsutils__namespace.BufferSourceConverter.toArrayBuffer(this.tbsView);
  14157. }
  14158. set tbs(value) {
  14159. this.tbsView = new Uint8Array(value);
  14160. }
  14161. constructor(parameters = {}) {
  14162. super();
  14163. this.tbsView = new Uint8Array(pvutils__namespace.getParametersValue(parameters, TBS$2, ResponseData.defaultValues(TBS$2)));
  14164. if (VERSION$7 in parameters) {
  14165. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$7, ResponseData.defaultValues(VERSION$7));
  14166. }
  14167. this.responderID = pvutils__namespace.getParametersValue(parameters, RESPONDER_ID, ResponseData.defaultValues(RESPONDER_ID));
  14168. this.producedAt = pvutils__namespace.getParametersValue(parameters, PRODUCED_AT, ResponseData.defaultValues(PRODUCED_AT));
  14169. this.responses = pvutils__namespace.getParametersValue(parameters, RESPONSES, ResponseData.defaultValues(RESPONSES));
  14170. if (RESPONSE_EXTENSIONS in parameters) {
  14171. this.responseExtensions = pvutils__namespace.getParametersValue(parameters, RESPONSE_EXTENSIONS, ResponseData.defaultValues(RESPONSE_EXTENSIONS));
  14172. }
  14173. if (parameters.schema) {
  14174. this.fromSchema(parameters.schema);
  14175. }
  14176. }
  14177. static defaultValues(memberName) {
  14178. switch (memberName) {
  14179. case VERSION$7:
  14180. return 0;
  14181. case TBS$2:
  14182. return EMPTY_BUFFER;
  14183. case RESPONDER_ID:
  14184. return {};
  14185. case PRODUCED_AT:
  14186. return new Date(0, 0, 0);
  14187. case RESPONSES:
  14188. case RESPONSE_EXTENSIONS:
  14189. return [];
  14190. default:
  14191. return super.defaultValues(memberName);
  14192. }
  14193. }
  14194. static compareWithDefault(memberName, memberValue) {
  14195. switch (memberName) {
  14196. case TBS$2:
  14197. return (memberValue.byteLength === 0);
  14198. case RESPONDER_ID:
  14199. return (Object.keys(memberValue).length === 0);
  14200. case PRODUCED_AT:
  14201. return (memberValue === ResponseData.defaultValues(memberName));
  14202. case RESPONSES:
  14203. case RESPONSE_EXTENSIONS:
  14204. return (memberValue.length === 0);
  14205. default:
  14206. return super.defaultValues(memberName);
  14207. }
  14208. }
  14209. static schema(parameters = {}) {
  14210. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  14211. return (new asn1js__namespace.Sequence({
  14212. name: (names.blockName || RESPONSE_DATA),
  14213. value: [
  14214. new asn1js__namespace.Constructed({
  14215. optional: true,
  14216. idBlock: {
  14217. tagClass: 3,
  14218. tagNumber: 0
  14219. },
  14220. value: [new asn1js__namespace.Integer({ name: (names.version || RESPONSE_DATA_VERSION) })]
  14221. }),
  14222. new asn1js__namespace.Choice({
  14223. value: [
  14224. new asn1js__namespace.Constructed({
  14225. name: (names.responderID || RESPONSE_DATA_RESPONDER_ID),
  14226. idBlock: {
  14227. tagClass: 3,
  14228. tagNumber: 1
  14229. },
  14230. value: [RelativeDistinguishedNames.schema(names.ResponseDataByName || {
  14231. names: {
  14232. blockName: "ResponseData.byName"
  14233. }
  14234. })]
  14235. }),
  14236. new asn1js__namespace.Constructed({
  14237. name: (names.responderID || RESPONSE_DATA_RESPONDER_ID),
  14238. idBlock: {
  14239. tagClass: 3,
  14240. tagNumber: 2
  14241. },
  14242. value: [new asn1js__namespace.OctetString({ name: (names.ResponseDataByKey || "ResponseData.byKey") })]
  14243. })
  14244. ]
  14245. }),
  14246. new asn1js__namespace.GeneralizedTime({ name: (names.producedAt || RESPONSE_DATA_PRODUCED_AT) }),
  14247. new asn1js__namespace.Sequence({
  14248. value: [
  14249. new asn1js__namespace.Repeated({
  14250. name: RESPONSE_DATA_RESPONSES,
  14251. value: SingleResponse.schema(names.response || {})
  14252. })
  14253. ]
  14254. }),
  14255. new asn1js__namespace.Constructed({
  14256. optional: true,
  14257. idBlock: {
  14258. tagClass: 3,
  14259. tagNumber: 1
  14260. },
  14261. value: [Extensions.schema(names.extensions || {
  14262. names: {
  14263. blockName: RESPONSE_DATA_RESPONSE_EXTENSIONS
  14264. }
  14265. })]
  14266. })
  14267. ]
  14268. }));
  14269. }
  14270. fromSchema(schema) {
  14271. pvutils__namespace.clearProps(schema, CLEAR_PROPS$h);
  14272. const asn1 = asn1js__namespace.compareSchema(schema, schema, ResponseData.schema());
  14273. AsnError.assertSchema(asn1, this.className);
  14274. this.tbsView = asn1.result.ResponseData.valueBeforeDecodeView;
  14275. if (RESPONSE_DATA_VERSION in asn1.result)
  14276. this.version = asn1.result[RESPONSE_DATA_VERSION].valueBlock.valueDec;
  14277. if (asn1.result[RESPONSE_DATA_RESPONDER_ID].idBlock.tagNumber === 1)
  14278. this.responderID = new RelativeDistinguishedNames({ schema: asn1.result[RESPONSE_DATA_RESPONDER_ID].valueBlock.value[0] });
  14279. else
  14280. this.responderID = asn1.result[RESPONSE_DATA_RESPONDER_ID].valueBlock.value[0];
  14281. this.producedAt = asn1.result[RESPONSE_DATA_PRODUCED_AT].toDate();
  14282. this.responses = Array.from(asn1.result[RESPONSE_DATA_RESPONSES], element => new SingleResponse({ schema: element }));
  14283. if (RESPONSE_DATA_RESPONSE_EXTENSIONS in asn1.result)
  14284. this.responseExtensions = Array.from(asn1.result[RESPONSE_DATA_RESPONSE_EXTENSIONS].valueBlock.value, element => new Extension({ schema: element }));
  14285. }
  14286. toSchema(encodeFlag = false) {
  14287. let tbsSchema;
  14288. if (encodeFlag === false) {
  14289. if (!this.tbsView.byteLength) {
  14290. return ResponseData.schema();
  14291. }
  14292. const asn1 = asn1js__namespace.fromBER(this.tbsView);
  14293. AsnError.assert(asn1, "TBS Response Data");
  14294. tbsSchema = asn1.result;
  14295. }
  14296. else {
  14297. const outputArray = [];
  14298. if (VERSION$7 in this) {
  14299. outputArray.push(new asn1js__namespace.Constructed({
  14300. idBlock: {
  14301. tagClass: 3,
  14302. tagNumber: 0
  14303. },
  14304. value: [new asn1js__namespace.Integer({ value: this.version })]
  14305. }));
  14306. }
  14307. if (this.responderID instanceof RelativeDistinguishedNames) {
  14308. outputArray.push(new asn1js__namespace.Constructed({
  14309. idBlock: {
  14310. tagClass: 3,
  14311. tagNumber: 1
  14312. },
  14313. value: [this.responderID.toSchema()]
  14314. }));
  14315. }
  14316. else {
  14317. outputArray.push(new asn1js__namespace.Constructed({
  14318. idBlock: {
  14319. tagClass: 3,
  14320. tagNumber: 2
  14321. },
  14322. value: [this.responderID]
  14323. }));
  14324. }
  14325. outputArray.push(new asn1js__namespace.GeneralizedTime({ valueDate: this.producedAt }));
  14326. outputArray.push(new asn1js__namespace.Sequence({
  14327. value: Array.from(this.responses, o => o.toSchema())
  14328. }));
  14329. if (this.responseExtensions) {
  14330. outputArray.push(new asn1js__namespace.Constructed({
  14331. idBlock: {
  14332. tagClass: 3,
  14333. tagNumber: 1
  14334. },
  14335. value: [new asn1js__namespace.Sequence({
  14336. value: Array.from(this.responseExtensions, o => o.toSchema())
  14337. })]
  14338. }));
  14339. }
  14340. tbsSchema = new asn1js__namespace.Sequence({
  14341. value: outputArray
  14342. });
  14343. }
  14344. return tbsSchema;
  14345. }
  14346. toJSON() {
  14347. const res = {};
  14348. if (VERSION$7 in this) {
  14349. res.version = this.version;
  14350. }
  14351. if (this.responderID) {
  14352. res.responderID = this.responderID;
  14353. }
  14354. if (this.producedAt) {
  14355. res.producedAt = this.producedAt;
  14356. }
  14357. if (this.responses) {
  14358. res.responses = Array.from(this.responses, o => o.toJSON());
  14359. }
  14360. if (this.responseExtensions) {
  14361. res.responseExtensions = Array.from(this.responseExtensions, o => o.toJSON());
  14362. }
  14363. return res;
  14364. }
  14365. }
  14366. ResponseData.CLASS_NAME = "ResponseData";
  14367. const TRUSTED_CERTS = "trustedCerts";
  14368. const CERTS$2 = "certs";
  14369. const CRLS$1 = "crls";
  14370. const OCSPS$1 = "ocsps";
  14371. const CHECK_DATE = "checkDate";
  14372. const FIND_ORIGIN = "findOrigin";
  14373. const FIND_ISSUER = "findIssuer";
  14374. exports.ChainValidationCode = void 0;
  14375. (function (ChainValidationCode) {
  14376. ChainValidationCode[ChainValidationCode["unknown"] = -1] = "unknown";
  14377. ChainValidationCode[ChainValidationCode["success"] = 0] = "success";
  14378. ChainValidationCode[ChainValidationCode["noRevocation"] = 11] = "noRevocation";
  14379. ChainValidationCode[ChainValidationCode["noPath"] = 60] = "noPath";
  14380. ChainValidationCode[ChainValidationCode["noValidPath"] = 97] = "noValidPath";
  14381. })(exports.ChainValidationCode || (exports.ChainValidationCode = {}));
  14382. class ChainValidationError extends Error {
  14383. constructor(code, message) {
  14384. super(message);
  14385. this.name = ChainValidationError.NAME;
  14386. this.code = code;
  14387. this.message = message;
  14388. }
  14389. }
  14390. ChainValidationError.NAME = "ChainValidationError";
  14391. function isTrusted(cert, trustedList) {
  14392. for (let i = 0; i < trustedList.length; i++) {
  14393. if (pvtsutils__namespace.BufferSourceConverter.isEqual(cert.tbsView, trustedList[i].tbsView)) {
  14394. return true;
  14395. }
  14396. }
  14397. return false;
  14398. }
  14399. class CertificateChainValidationEngine {
  14400. constructor(parameters = {}) {
  14401. this.trustedCerts = pvutils__namespace.getParametersValue(parameters, TRUSTED_CERTS, this.defaultValues(TRUSTED_CERTS));
  14402. this.certs = pvutils__namespace.getParametersValue(parameters, CERTS$2, this.defaultValues(CERTS$2));
  14403. this.crls = pvutils__namespace.getParametersValue(parameters, CRLS$1, this.defaultValues(CRLS$1));
  14404. this.ocsps = pvutils__namespace.getParametersValue(parameters, OCSPS$1, this.defaultValues(OCSPS$1));
  14405. this.checkDate = pvutils__namespace.getParametersValue(parameters, CHECK_DATE, this.defaultValues(CHECK_DATE));
  14406. this.findOrigin = pvutils__namespace.getParametersValue(parameters, FIND_ORIGIN, this.defaultValues(FIND_ORIGIN));
  14407. this.findIssuer = pvutils__namespace.getParametersValue(parameters, FIND_ISSUER, this.defaultValues(FIND_ISSUER));
  14408. }
  14409. static defaultFindOrigin(certificate, validationEngine) {
  14410. if (certificate.tbsView.byteLength === 0) {
  14411. certificate.tbsView = new Uint8Array(certificate.encodeTBS().toBER());
  14412. }
  14413. for (const localCert of validationEngine.certs) {
  14414. if (localCert.tbsView.byteLength === 0) {
  14415. localCert.tbsView = new Uint8Array(localCert.encodeTBS().toBER());
  14416. }
  14417. if (pvtsutils__namespace.BufferSourceConverter.isEqual(certificate.tbsView, localCert.tbsView))
  14418. return "Intermediate Certificates";
  14419. }
  14420. for (const trustedCert of validationEngine.trustedCerts) {
  14421. if (trustedCert.tbsView.byteLength === 0)
  14422. trustedCert.tbsView = new Uint8Array(trustedCert.encodeTBS().toBER());
  14423. if (pvtsutils__namespace.BufferSourceConverter.isEqual(certificate.tbsView, trustedCert.tbsView))
  14424. return "Trusted Certificates";
  14425. }
  14426. return "Unknown";
  14427. }
  14428. async defaultFindIssuer(certificate, validationEngine, crypto = getCrypto(true)) {
  14429. const result = [];
  14430. let keyIdentifier = null;
  14431. let authorityCertIssuer = null;
  14432. let authorityCertSerialNumber = null;
  14433. if (certificate.subject.isEqual(certificate.issuer)) {
  14434. try {
  14435. const verificationResult = await certificate.verify(undefined, crypto);
  14436. if (verificationResult) {
  14437. return [certificate];
  14438. }
  14439. }
  14440. catch {
  14441. }
  14442. }
  14443. if (certificate.extensions) {
  14444. for (const extension of certificate.extensions) {
  14445. if (extension.extnID === id_AuthorityKeyIdentifier && extension.parsedValue instanceof AuthorityKeyIdentifier) {
  14446. if (extension.parsedValue.keyIdentifier) {
  14447. keyIdentifier = extension.parsedValue.keyIdentifier;
  14448. }
  14449. else {
  14450. if (extension.parsedValue.authorityCertIssuer) {
  14451. authorityCertIssuer = extension.parsedValue.authorityCertIssuer;
  14452. }
  14453. if (extension.parsedValue.authorityCertSerialNumber) {
  14454. authorityCertSerialNumber = extension.parsedValue.authorityCertSerialNumber;
  14455. }
  14456. }
  14457. break;
  14458. }
  14459. }
  14460. }
  14461. function checkCertificate(possibleIssuer) {
  14462. if (keyIdentifier !== null) {
  14463. if (possibleIssuer.extensions) {
  14464. let extensionFound = false;
  14465. for (const extension of possibleIssuer.extensions) {
  14466. if (extension.extnID === id_SubjectKeyIdentifier && extension.parsedValue) {
  14467. extensionFound = true;
  14468. if (pvtsutils__namespace.BufferSourceConverter.isEqual(extension.parsedValue.valueBlock.valueHex, keyIdentifier.valueBlock.valueHexView)) {
  14469. result.push(possibleIssuer);
  14470. }
  14471. break;
  14472. }
  14473. }
  14474. if (extensionFound) {
  14475. return;
  14476. }
  14477. }
  14478. }
  14479. let authorityCertSerialNumberEqual = false;
  14480. if (authorityCertSerialNumber !== null)
  14481. authorityCertSerialNumberEqual = possibleIssuer.serialNumber.isEqual(authorityCertSerialNumber);
  14482. if (authorityCertIssuer !== null) {
  14483. if (possibleIssuer.subject.isEqual(authorityCertIssuer)) {
  14484. if (authorityCertSerialNumberEqual)
  14485. result.push(possibleIssuer);
  14486. }
  14487. }
  14488. else {
  14489. if (certificate.issuer.isEqual(possibleIssuer.subject))
  14490. result.push(possibleIssuer);
  14491. }
  14492. }
  14493. for (const trustedCert of validationEngine.trustedCerts) {
  14494. checkCertificate(trustedCert);
  14495. }
  14496. for (const intermediateCert of validationEngine.certs) {
  14497. checkCertificate(intermediateCert);
  14498. }
  14499. for (let i = result.length - 1; i >= 0; i--) {
  14500. try {
  14501. const verificationResult = await certificate.verify(result[i], crypto);
  14502. if (verificationResult === false)
  14503. result.splice(i, 1);
  14504. }
  14505. catch {
  14506. result.splice(i, 1);
  14507. }
  14508. }
  14509. return result;
  14510. }
  14511. defaultValues(memberName) {
  14512. switch (memberName) {
  14513. case TRUSTED_CERTS:
  14514. return [];
  14515. case CERTS$2:
  14516. return [];
  14517. case CRLS$1:
  14518. return [];
  14519. case OCSPS$1:
  14520. return [];
  14521. case CHECK_DATE:
  14522. return new Date();
  14523. case FIND_ORIGIN:
  14524. return CertificateChainValidationEngine.defaultFindOrigin;
  14525. case FIND_ISSUER:
  14526. return this.defaultFindIssuer;
  14527. default:
  14528. throw new Error(`Invalid member name for CertificateChainValidationEngine class: ${memberName}`);
  14529. }
  14530. }
  14531. async sort(passedWhenNotRevValues = false, crypto = getCrypto(true)) {
  14532. const localCerts = [];
  14533. const buildPath = async (certificate, crypto) => {
  14534. const result = [];
  14535. function checkUnique(array) {
  14536. let unique = true;
  14537. for (let i = 0; i < array.length; i++) {
  14538. for (let j = 0; j < array.length; j++) {
  14539. if (j === i)
  14540. continue;
  14541. if (array[i] === array[j]) {
  14542. unique = false;
  14543. break;
  14544. }
  14545. }
  14546. if (!unique)
  14547. break;
  14548. }
  14549. return unique;
  14550. }
  14551. if (isTrusted(certificate, this.trustedCerts)) {
  14552. return [[certificate]];
  14553. }
  14554. const findIssuerResult = await this.findIssuer(certificate, this, crypto);
  14555. if (findIssuerResult.length === 0) {
  14556. throw new Error("No valid certificate paths found");
  14557. }
  14558. for (let i = 0; i < findIssuerResult.length; i++) {
  14559. if (pvtsutils__namespace.BufferSourceConverter.isEqual(findIssuerResult[i].tbsView, certificate.tbsView)) {
  14560. result.push([findIssuerResult[i]]);
  14561. continue;
  14562. }
  14563. const buildPathResult = await buildPath(findIssuerResult[i], crypto);
  14564. for (let j = 0; j < buildPathResult.length; j++) {
  14565. const copy = buildPathResult[j].slice();
  14566. copy.splice(0, 0, findIssuerResult[i]);
  14567. if (checkUnique(copy))
  14568. result.push(copy);
  14569. else
  14570. result.push(buildPathResult[j]);
  14571. }
  14572. }
  14573. return result;
  14574. };
  14575. const findCRL = async (certificate) => {
  14576. const issuerCertificates = [];
  14577. const crls = [];
  14578. const crlsAndCertificates = [];
  14579. issuerCertificates.push(...localCerts.filter(element => certificate.issuer.isEqual(element.subject)));
  14580. if (issuerCertificates.length === 0) {
  14581. return {
  14582. status: 1,
  14583. statusMessage: "No certificate's issuers"
  14584. };
  14585. }
  14586. crls.push(...this.crls.filter(o => o.issuer.isEqual(certificate.issuer)));
  14587. if (crls.length === 0) {
  14588. return {
  14589. status: 2,
  14590. statusMessage: "No CRLs for specific certificate issuer"
  14591. };
  14592. }
  14593. for (let i = 0; i < crls.length; i++) {
  14594. const crl = crls[i];
  14595. if (crl.nextUpdate && crl.nextUpdate.value < this.checkDate) {
  14596. continue;
  14597. }
  14598. for (let j = 0; j < issuerCertificates.length; j++) {
  14599. try {
  14600. const result = await crls[i].verify({ issuerCertificate: issuerCertificates[j] }, crypto);
  14601. if (result) {
  14602. crlsAndCertificates.push({
  14603. crl: crls[i],
  14604. certificate: issuerCertificates[j]
  14605. });
  14606. break;
  14607. }
  14608. }
  14609. catch {
  14610. }
  14611. }
  14612. }
  14613. if (crlsAndCertificates.length) {
  14614. return {
  14615. status: 0,
  14616. statusMessage: EMPTY_STRING,
  14617. result: crlsAndCertificates
  14618. };
  14619. }
  14620. return {
  14621. status: 3,
  14622. statusMessage: "No valid CRLs found"
  14623. };
  14624. };
  14625. const findOCSP = async (certificate, issuerCertificate) => {
  14626. const hashAlgorithm = crypto.getAlgorithmByOID(certificate.signatureAlgorithm.algorithmId);
  14627. if (!hashAlgorithm.name) {
  14628. return 1;
  14629. }
  14630. if (!hashAlgorithm.hash) {
  14631. return 1;
  14632. }
  14633. for (let i = 0; i < this.ocsps.length; i++) {
  14634. const ocsp = this.ocsps[i];
  14635. const result = await ocsp.getCertificateStatus(certificate, issuerCertificate, crypto);
  14636. if (result.isForCertificate) {
  14637. if (result.status === 0)
  14638. return 0;
  14639. return 1;
  14640. }
  14641. }
  14642. return 2;
  14643. };
  14644. async function checkForCA(certificate, needToCheckCRL = false) {
  14645. let isCA = false;
  14646. let mustBeCA = false;
  14647. let keyUsagePresent = false;
  14648. let cRLSign = false;
  14649. if (certificate.extensions) {
  14650. for (let j = 0; j < certificate.extensions.length; j++) {
  14651. const extension = certificate.extensions[j];
  14652. if (extension.critical && !extension.parsedValue) {
  14653. return {
  14654. result: false,
  14655. resultCode: 6,
  14656. resultMessage: `Unable to parse critical certificate extension: ${extension.extnID}`
  14657. };
  14658. }
  14659. if (extension.extnID === id_KeyUsage) {
  14660. keyUsagePresent = true;
  14661. const view = new Uint8Array(extension.parsedValue.valueBlock.valueHex);
  14662. if ((view[0] & 0x04) === 0x04)
  14663. mustBeCA = true;
  14664. if ((view[0] & 0x02) === 0x02)
  14665. cRLSign = true;
  14666. }
  14667. if (extension.extnID === id_BasicConstraints) {
  14668. if ("cA" in extension.parsedValue) {
  14669. if (extension.parsedValue.cA === true)
  14670. isCA = true;
  14671. }
  14672. }
  14673. }
  14674. if ((mustBeCA === true) && (isCA === false)) {
  14675. return {
  14676. result: false,
  14677. resultCode: 3,
  14678. resultMessage: "Unable to build certificate chain - using \"keyCertSign\" flag set without BasicConstraints"
  14679. };
  14680. }
  14681. if ((keyUsagePresent === true) && (isCA === true) && (mustBeCA === false)) {
  14682. return {
  14683. result: false,
  14684. resultCode: 4,
  14685. resultMessage: "Unable to build certificate chain - \"keyCertSign\" flag was not set"
  14686. };
  14687. }
  14688. if ((isCA === true) && (keyUsagePresent === true) && ((needToCheckCRL) && (cRLSign === false))) {
  14689. return {
  14690. result: false,
  14691. resultCode: 5,
  14692. resultMessage: "Unable to build certificate chain - intermediate certificate must have \"cRLSign\" key usage flag"
  14693. };
  14694. }
  14695. }
  14696. if (isCA === false) {
  14697. return {
  14698. result: false,
  14699. resultCode: 7,
  14700. resultMessage: "Unable to build certificate chain - more than one possible end-user certificate"
  14701. };
  14702. }
  14703. return {
  14704. result: true,
  14705. resultCode: 0,
  14706. resultMessage: EMPTY_STRING
  14707. };
  14708. }
  14709. const basicCheck = async (path, checkDate) => {
  14710. for (let i = 0; i < path.length; i++) {
  14711. if ((path[i].notBefore.value > checkDate) ||
  14712. (path[i].notAfter.value < checkDate)) {
  14713. return {
  14714. result: false,
  14715. resultCode: 8,
  14716. resultMessage: "The certificate is either not yet valid or expired"
  14717. };
  14718. }
  14719. }
  14720. if (path.length < 2) {
  14721. return {
  14722. result: false,
  14723. resultCode: 9,
  14724. resultMessage: "Too short certificate path"
  14725. };
  14726. }
  14727. for (let i = (path.length - 2); i >= 0; i--) {
  14728. if (path[i].issuer.isEqual(path[i].subject) === false) {
  14729. if (path[i].issuer.isEqual(path[i + 1].subject) === false) {
  14730. return {
  14731. result: false,
  14732. resultCode: 10,
  14733. resultMessage: "Incorrect name chaining"
  14734. };
  14735. }
  14736. }
  14737. }
  14738. if ((this.crls.length !== 0) || (this.ocsps.length !== 0)) {
  14739. for (let i = 0; i < (path.length - 1); i++) {
  14740. let ocspResult = 2;
  14741. let crlResult = {
  14742. status: 0,
  14743. statusMessage: EMPTY_STRING
  14744. };
  14745. if (this.ocsps.length !== 0) {
  14746. ocspResult = await findOCSP(path[i], path[i + 1]);
  14747. switch (ocspResult) {
  14748. case 0:
  14749. continue;
  14750. case 1:
  14751. return {
  14752. result: false,
  14753. resultCode: 12,
  14754. resultMessage: "One of certificates was revoked via OCSP response"
  14755. };
  14756. }
  14757. }
  14758. if (this.crls.length !== 0) {
  14759. crlResult = await findCRL(path[i]);
  14760. if (crlResult.status === 0 && crlResult.result) {
  14761. for (let j = 0; j < crlResult.result.length; j++) {
  14762. const isCertificateRevoked = crlResult.result[j].crl.isCertificateRevoked(path[i]);
  14763. if (isCertificateRevoked) {
  14764. return {
  14765. result: false,
  14766. resultCode: 12,
  14767. resultMessage: "One of certificates had been revoked"
  14768. };
  14769. }
  14770. const isCertificateCA = await checkForCA(crlResult.result[j].certificate, true);
  14771. if (isCertificateCA.result === false) {
  14772. return {
  14773. result: false,
  14774. resultCode: 13,
  14775. resultMessage: "CRL issuer certificate is not a CA certificate or does not have crlSign flag"
  14776. };
  14777. }
  14778. }
  14779. }
  14780. else {
  14781. if (passedWhenNotRevValues === false) {
  14782. throw new ChainValidationError(exports.ChainValidationCode.noRevocation, `No revocation values found for one of certificates: ${crlResult.statusMessage}`);
  14783. }
  14784. }
  14785. }
  14786. else {
  14787. if (ocspResult === 2) {
  14788. return {
  14789. result: false,
  14790. resultCode: 11,
  14791. resultMessage: "No revocation values found for one of certificates"
  14792. };
  14793. }
  14794. }
  14795. if ((ocspResult === 2) && (crlResult.status === 2) && passedWhenNotRevValues) {
  14796. const issuerCertificate = path[i + 1];
  14797. let extensionFound = false;
  14798. if (issuerCertificate.extensions) {
  14799. for (const extension of issuerCertificate.extensions) {
  14800. switch (extension.extnID) {
  14801. case id_CRLDistributionPoints:
  14802. case id_FreshestCRL:
  14803. case id_AuthorityInfoAccess:
  14804. extensionFound = true;
  14805. break;
  14806. }
  14807. }
  14808. }
  14809. if (extensionFound) {
  14810. throw new ChainValidationError(exports.ChainValidationCode.noRevocation, `No revocation values found for one of certificates: ${crlResult.statusMessage}`);
  14811. }
  14812. }
  14813. }
  14814. }
  14815. for (const [i, cert] of path.entries()) {
  14816. if (!i) {
  14817. continue;
  14818. }
  14819. const result = await checkForCA(cert);
  14820. if (!result.result) {
  14821. return {
  14822. result: false,
  14823. resultCode: 14,
  14824. resultMessage: "One of intermediate certificates is not a CA certificate"
  14825. };
  14826. }
  14827. }
  14828. return {
  14829. result: true
  14830. };
  14831. };
  14832. localCerts.push(...this.trustedCerts);
  14833. localCerts.push(...this.certs);
  14834. for (let i = 0; i < localCerts.length; i++) {
  14835. for (let j = 0; j < localCerts.length; j++) {
  14836. if (i === j)
  14837. continue;
  14838. if (pvtsutils__namespace.BufferSourceConverter.isEqual(localCerts[i].tbsView, localCerts[j].tbsView)) {
  14839. localCerts.splice(j, 1);
  14840. i = 0;
  14841. break;
  14842. }
  14843. }
  14844. }
  14845. const leafCert = localCerts[localCerts.length - 1];
  14846. let result;
  14847. const certificatePath = [leafCert];
  14848. result = await buildPath(leafCert, crypto);
  14849. if (result.length === 0) {
  14850. throw new ChainValidationError(exports.ChainValidationCode.noPath, "Unable to find certificate path");
  14851. }
  14852. for (let i = result.length - 1; i >= 0; i--) {
  14853. let found = false;
  14854. for (let j = 0; j < (result[i]).length; j++) {
  14855. const certificate = (result[i])[j];
  14856. for (let k = 0; k < this.trustedCerts.length; k++) {
  14857. if (pvtsutils__namespace.BufferSourceConverter.isEqual(certificate.tbsView, this.trustedCerts[k].tbsView)) {
  14858. found = true;
  14859. break;
  14860. }
  14861. }
  14862. if (found)
  14863. break;
  14864. }
  14865. if (!found) {
  14866. result.splice(i, 1);
  14867. }
  14868. }
  14869. if (result.length === 0) {
  14870. throw new ChainValidationError(exports.ChainValidationCode.noValidPath, "No valid certificate paths found");
  14871. }
  14872. let shortestLength = result[0].length;
  14873. let shortestIndex = 0;
  14874. for (let i = 0; i < result.length; i++) {
  14875. if (result[i].length < shortestLength) {
  14876. shortestLength = result[i].length;
  14877. shortestIndex = i;
  14878. }
  14879. }
  14880. for (let i = 0; i < result[shortestIndex].length; i++)
  14881. certificatePath.push((result[shortestIndex])[i]);
  14882. result = await basicCheck(certificatePath, this.checkDate);
  14883. if (result.result === false)
  14884. throw result;
  14885. return certificatePath;
  14886. }
  14887. async verify(parameters = {}, crypto = getCrypto(true)) {
  14888. function compareDNSName(name, constraint) {
  14889. const namePrepared = stringPrep(name);
  14890. const constraintPrepared = stringPrep(constraint);
  14891. const nameSplitted = namePrepared.split(".");
  14892. const constraintSplitted = constraintPrepared.split(".");
  14893. const nameLen = nameSplitted.length;
  14894. const constrLen = constraintSplitted.length;
  14895. if ((nameLen === 0) || (constrLen === 0) || (nameLen < constrLen)) {
  14896. return false;
  14897. }
  14898. for (let i = 0; i < nameLen; i++) {
  14899. if (nameSplitted[i].length === 0) {
  14900. return false;
  14901. }
  14902. }
  14903. for (let i = 0; i < constrLen; i++) {
  14904. if (constraintSplitted[i].length === 0) {
  14905. if (i === 0) {
  14906. if (constrLen === 1) {
  14907. return false;
  14908. }
  14909. continue;
  14910. }
  14911. return false;
  14912. }
  14913. }
  14914. for (let i = 0; i < constrLen; i++) {
  14915. if (constraintSplitted[constrLen - 1 - i].length === 0) {
  14916. continue;
  14917. }
  14918. if (nameSplitted[nameLen - 1 - i].localeCompare(constraintSplitted[constrLen - 1 - i]) !== 0) {
  14919. return false;
  14920. }
  14921. }
  14922. return true;
  14923. }
  14924. function compareRFC822Name(name, constraint) {
  14925. const namePrepared = stringPrep(name);
  14926. const constraintPrepared = stringPrep(constraint);
  14927. const nameSplitted = namePrepared.split("@");
  14928. const constraintSplitted = constraintPrepared.split("@");
  14929. if ((nameSplitted.length === 0) || (constraintSplitted.length === 0) || (nameSplitted.length < constraintSplitted.length))
  14930. return false;
  14931. if (constraintSplitted.length === 1) {
  14932. const result = compareDNSName(nameSplitted[1], constraintSplitted[0]);
  14933. if (result) {
  14934. const ns = nameSplitted[1].split(".");
  14935. const cs = constraintSplitted[0].split(".");
  14936. if (cs[0].length === 0)
  14937. return true;
  14938. return ns.length === cs.length;
  14939. }
  14940. return false;
  14941. }
  14942. return (namePrepared.localeCompare(constraintPrepared) === 0);
  14943. }
  14944. function compareUniformResourceIdentifier(name, constraint) {
  14945. let namePrepared = stringPrep(name);
  14946. const constraintPrepared = stringPrep(constraint);
  14947. const ns = namePrepared.split("/");
  14948. const cs = constraintPrepared.split("/");
  14949. if (cs.length > 1)
  14950. return false;
  14951. if (ns.length > 1) {
  14952. for (let i = 0; i < ns.length; i++) {
  14953. if ((ns[i].length > 0) && (ns[i].charAt(ns[i].length - 1) !== ":")) {
  14954. const nsPort = ns[i].split(":");
  14955. namePrepared = nsPort[0];
  14956. break;
  14957. }
  14958. }
  14959. }
  14960. const result = compareDNSName(namePrepared, constraintPrepared);
  14961. if (result) {
  14962. const nameSplitted = namePrepared.split(".");
  14963. const constraintSplitted = constraintPrepared.split(".");
  14964. if (constraintSplitted[0].length === 0)
  14965. return true;
  14966. return nameSplitted.length === constraintSplitted.length;
  14967. }
  14968. return false;
  14969. }
  14970. function compareIPAddress(name, constraint) {
  14971. const nameView = name.valueBlock.valueHexView;
  14972. const constraintView = constraint.valueBlock.valueHexView;
  14973. if ((nameView.length === 4) && (constraintView.length === 8)) {
  14974. for (let i = 0; i < 4; i++) {
  14975. if ((nameView[i] ^ constraintView[i]) & constraintView[i + 4])
  14976. return false;
  14977. }
  14978. return true;
  14979. }
  14980. if ((nameView.length === 16) && (constraintView.length === 32)) {
  14981. for (let i = 0; i < 16; i++) {
  14982. if ((nameView[i] ^ constraintView[i]) & constraintView[i + 16])
  14983. return false;
  14984. }
  14985. return true;
  14986. }
  14987. return false;
  14988. }
  14989. function compareDirectoryName(name, constraint) {
  14990. if ((name.typesAndValues.length === 0) || (constraint.typesAndValues.length === 0))
  14991. return true;
  14992. if (name.typesAndValues.length < constraint.typesAndValues.length)
  14993. return false;
  14994. let result = true;
  14995. let nameStart = 0;
  14996. for (let i = 0; i < constraint.typesAndValues.length; i++) {
  14997. let localResult = false;
  14998. for (let j = nameStart; j < name.typesAndValues.length; j++) {
  14999. localResult = name.typesAndValues[j].isEqual(constraint.typesAndValues[i]);
  15000. if (name.typesAndValues[j].type === constraint.typesAndValues[i].type)
  15001. result = result && localResult;
  15002. if (localResult === true) {
  15003. if ((nameStart === 0) || (nameStart === j)) {
  15004. nameStart = j + 1;
  15005. break;
  15006. }
  15007. else
  15008. return false;
  15009. }
  15010. }
  15011. if (localResult === false)
  15012. return false;
  15013. }
  15014. return (nameStart === 0) ? false : result;
  15015. }
  15016. try {
  15017. if (this.certs.length === 0)
  15018. throw new Error("Empty certificate array");
  15019. const passedWhenNotRevValues = parameters.passedWhenNotRevValues || false;
  15020. const initialPolicySet = parameters.initialPolicySet || [id_AnyPolicy];
  15021. const initialExplicitPolicy = parameters.initialExplicitPolicy || false;
  15022. const initialPolicyMappingInhibit = parameters.initialPolicyMappingInhibit || false;
  15023. const initialInhibitPolicy = parameters.initialInhibitPolicy || false;
  15024. const initialPermittedSubtreesSet = parameters.initialPermittedSubtreesSet || [];
  15025. const initialExcludedSubtreesSet = parameters.initialExcludedSubtreesSet || [];
  15026. const initialRequiredNameForms = parameters.initialRequiredNameForms || [];
  15027. let explicitPolicyIndicator = initialExplicitPolicy;
  15028. let policyMappingInhibitIndicator = initialPolicyMappingInhibit;
  15029. let inhibitAnyPolicyIndicator = initialInhibitPolicy;
  15030. const pendingConstraints = [
  15031. false,
  15032. false,
  15033. false,
  15034. ];
  15035. let explicitPolicyPending = 0;
  15036. let policyMappingInhibitPending = 0;
  15037. let inhibitAnyPolicyPending = 0;
  15038. let permittedSubtrees = initialPermittedSubtreesSet;
  15039. let excludedSubtrees = initialExcludedSubtreesSet;
  15040. const requiredNameForms = initialRequiredNameForms;
  15041. let pathDepth = 1;
  15042. this.certs = await this.sort(passedWhenNotRevValues, crypto);
  15043. const allPolicies = [];
  15044. allPolicies.push(id_AnyPolicy);
  15045. const policiesAndCerts = [];
  15046. const anyPolicyArray = new Array(this.certs.length - 1);
  15047. for (let ii = 0; ii < (this.certs.length - 1); ii++)
  15048. anyPolicyArray[ii] = true;
  15049. policiesAndCerts.push(anyPolicyArray);
  15050. const policyMappings = new Array(this.certs.length - 1);
  15051. const certPolicies = new Array(this.certs.length - 1);
  15052. let explicitPolicyStart = (explicitPolicyIndicator) ? (this.certs.length - 1) : (-1);
  15053. for (let i = (this.certs.length - 2); i >= 0; i--, pathDepth++) {
  15054. const cert = this.certs[i];
  15055. if (cert.extensions) {
  15056. for (let j = 0; j < cert.extensions.length; j++) {
  15057. const extension = cert.extensions[j];
  15058. if (extension.extnID === id_CertificatePolicies) {
  15059. certPolicies[i] = extension.parsedValue;
  15060. for (let s = 0; s < allPolicies.length; s++) {
  15061. if (allPolicies[s] === id_AnyPolicy) {
  15062. delete (policiesAndCerts[s])[i];
  15063. break;
  15064. }
  15065. }
  15066. for (let k = 0; k < extension.parsedValue.certificatePolicies.length; k++) {
  15067. let policyIndex = (-1);
  15068. const policyId = extension.parsedValue.certificatePolicies[k].policyIdentifier;
  15069. for (let s = 0; s < allPolicies.length; s++) {
  15070. if (policyId === allPolicies[s]) {
  15071. policyIndex = s;
  15072. break;
  15073. }
  15074. }
  15075. if (policyIndex === (-1)) {
  15076. allPolicies.push(policyId);
  15077. const certArray = new Array(this.certs.length - 1);
  15078. certArray[i] = true;
  15079. policiesAndCerts.push(certArray);
  15080. }
  15081. else
  15082. (policiesAndCerts[policyIndex])[i] = true;
  15083. }
  15084. }
  15085. if (extension.extnID === id_PolicyMappings) {
  15086. if (policyMappingInhibitIndicator) {
  15087. return {
  15088. result: false,
  15089. resultCode: 98,
  15090. resultMessage: "Policy mapping prohibited"
  15091. };
  15092. }
  15093. policyMappings[i] = extension.parsedValue;
  15094. }
  15095. if (extension.extnID === id_PolicyConstraints) {
  15096. if (explicitPolicyIndicator === false) {
  15097. if (extension.parsedValue.requireExplicitPolicy === 0) {
  15098. explicitPolicyIndicator = true;
  15099. explicitPolicyStart = i;
  15100. }
  15101. else {
  15102. if (pendingConstraints[0] === false) {
  15103. pendingConstraints[0] = true;
  15104. explicitPolicyPending = extension.parsedValue.requireExplicitPolicy;
  15105. }
  15106. else
  15107. explicitPolicyPending = (explicitPolicyPending > extension.parsedValue.requireExplicitPolicy) ? extension.parsedValue.requireExplicitPolicy : explicitPolicyPending;
  15108. }
  15109. if (extension.parsedValue.inhibitPolicyMapping === 0)
  15110. policyMappingInhibitIndicator = true;
  15111. else {
  15112. if (pendingConstraints[1] === false) {
  15113. pendingConstraints[1] = true;
  15114. policyMappingInhibitPending = extension.parsedValue.inhibitPolicyMapping + 1;
  15115. }
  15116. else
  15117. policyMappingInhibitPending = (policyMappingInhibitPending > (extension.parsedValue.inhibitPolicyMapping + 1)) ? (extension.parsedValue.inhibitPolicyMapping + 1) : policyMappingInhibitPending;
  15118. }
  15119. }
  15120. }
  15121. if (extension.extnID === id_InhibitAnyPolicy) {
  15122. if (inhibitAnyPolicyIndicator === false) {
  15123. if (extension.parsedValue.valueBlock.valueDec === 0)
  15124. inhibitAnyPolicyIndicator = true;
  15125. else {
  15126. if (pendingConstraints[2] === false) {
  15127. pendingConstraints[2] = true;
  15128. inhibitAnyPolicyPending = extension.parsedValue.valueBlock.valueDec;
  15129. }
  15130. else
  15131. inhibitAnyPolicyPending = (inhibitAnyPolicyPending > extension.parsedValue.valueBlock.valueDec) ? extension.parsedValue.valueBlock.valueDec : inhibitAnyPolicyPending;
  15132. }
  15133. }
  15134. }
  15135. }
  15136. if (inhibitAnyPolicyIndicator === true) {
  15137. let policyIndex = (-1);
  15138. for (let searchAnyPolicy = 0; searchAnyPolicy < allPolicies.length; searchAnyPolicy++) {
  15139. if (allPolicies[searchAnyPolicy] === id_AnyPolicy) {
  15140. policyIndex = searchAnyPolicy;
  15141. break;
  15142. }
  15143. }
  15144. if (policyIndex !== (-1))
  15145. delete (policiesAndCerts[0])[i];
  15146. }
  15147. if (explicitPolicyIndicator === false) {
  15148. if (pendingConstraints[0] === true) {
  15149. explicitPolicyPending--;
  15150. if (explicitPolicyPending === 0) {
  15151. explicitPolicyIndicator = true;
  15152. explicitPolicyStart = i;
  15153. pendingConstraints[0] = false;
  15154. }
  15155. }
  15156. }
  15157. if (policyMappingInhibitIndicator === false) {
  15158. if (pendingConstraints[1] === true) {
  15159. policyMappingInhibitPending--;
  15160. if (policyMappingInhibitPending === 0) {
  15161. policyMappingInhibitIndicator = true;
  15162. pendingConstraints[1] = false;
  15163. }
  15164. }
  15165. }
  15166. if (inhibitAnyPolicyIndicator === false) {
  15167. if (pendingConstraints[2] === true) {
  15168. inhibitAnyPolicyPending--;
  15169. if (inhibitAnyPolicyPending === 0) {
  15170. inhibitAnyPolicyIndicator = true;
  15171. pendingConstraints[2] = false;
  15172. }
  15173. }
  15174. }
  15175. }
  15176. }
  15177. for (let i = 0; i < (this.certs.length - 1); i++) {
  15178. if ((i < (this.certs.length - 2)) && (typeof policyMappings[i + 1] !== "undefined")) {
  15179. for (let k = 0; k < policyMappings[i + 1].mappings.length; k++) {
  15180. if ((policyMappings[i + 1].mappings[k].issuerDomainPolicy === id_AnyPolicy) || (policyMappings[i + 1].mappings[k].subjectDomainPolicy === id_AnyPolicy)) {
  15181. return {
  15182. result: false,
  15183. resultCode: 99,
  15184. resultMessage: "The \"anyPolicy\" should not be a part of policy mapping scheme"
  15185. };
  15186. }
  15187. let issuerDomainPolicyIndex = (-1);
  15188. let subjectDomainPolicyIndex = (-1);
  15189. for (let n = 0; n < allPolicies.length; n++) {
  15190. if (allPolicies[n] === policyMappings[i + 1].mappings[k].issuerDomainPolicy)
  15191. issuerDomainPolicyIndex = n;
  15192. if (allPolicies[n] === policyMappings[i + 1].mappings[k].subjectDomainPolicy)
  15193. subjectDomainPolicyIndex = n;
  15194. }
  15195. if (typeof (policiesAndCerts[issuerDomainPolicyIndex])[i] !== "undefined")
  15196. delete (policiesAndCerts[issuerDomainPolicyIndex])[i];
  15197. for (let j = 0; j < certPolicies[i].certificatePolicies.length; j++) {
  15198. if (policyMappings[i + 1].mappings[k].subjectDomainPolicy === certPolicies[i].certificatePolicies[j].policyIdentifier) {
  15199. if ((issuerDomainPolicyIndex !== (-1)) && (subjectDomainPolicyIndex !== (-1))) {
  15200. for (let m = 0; m <= i; m++) {
  15201. if (typeof (policiesAndCerts[subjectDomainPolicyIndex])[m] !== "undefined") {
  15202. (policiesAndCerts[issuerDomainPolicyIndex])[m] = true;
  15203. delete (policiesAndCerts[subjectDomainPolicyIndex])[m];
  15204. }
  15205. }
  15206. }
  15207. }
  15208. }
  15209. }
  15210. }
  15211. }
  15212. for (let i = 0; i < allPolicies.length; i++) {
  15213. if (allPolicies[i] === id_AnyPolicy) {
  15214. for (let j = 0; j < explicitPolicyStart; j++)
  15215. delete (policiesAndCerts[i])[j];
  15216. }
  15217. }
  15218. const authConstrPolicies = [];
  15219. for (let i = 0; i < policiesAndCerts.length; i++) {
  15220. let found = true;
  15221. for (let j = 0; j < (this.certs.length - 1); j++) {
  15222. let anyPolicyFound = false;
  15223. if ((j < explicitPolicyStart) && (allPolicies[i] === id_AnyPolicy) && (allPolicies.length > 1)) {
  15224. found = false;
  15225. break;
  15226. }
  15227. if (typeof (policiesAndCerts[i])[j] === "undefined") {
  15228. if (j >= explicitPolicyStart) {
  15229. for (let k = 0; k < allPolicies.length; k++) {
  15230. if (allPolicies[k] === id_AnyPolicy) {
  15231. if ((policiesAndCerts[k])[j] === true)
  15232. anyPolicyFound = true;
  15233. break;
  15234. }
  15235. }
  15236. }
  15237. if (!anyPolicyFound) {
  15238. found = false;
  15239. break;
  15240. }
  15241. }
  15242. }
  15243. if (found === true)
  15244. authConstrPolicies.push(allPolicies[i]);
  15245. }
  15246. let userConstrPolicies = [];
  15247. if ((initialPolicySet.length === 1) && (initialPolicySet[0] === id_AnyPolicy) && (explicitPolicyIndicator === false))
  15248. userConstrPolicies = initialPolicySet;
  15249. else {
  15250. if ((authConstrPolicies.length === 1) && (authConstrPolicies[0] === id_AnyPolicy))
  15251. userConstrPolicies = initialPolicySet;
  15252. else {
  15253. for (let i = 0; i < authConstrPolicies.length; i++) {
  15254. for (let j = 0; j < initialPolicySet.length; j++) {
  15255. if ((initialPolicySet[j] === authConstrPolicies[i]) || (initialPolicySet[j] === id_AnyPolicy)) {
  15256. userConstrPolicies.push(authConstrPolicies[i]);
  15257. break;
  15258. }
  15259. }
  15260. }
  15261. }
  15262. }
  15263. const policyResult = {
  15264. result: (userConstrPolicies.length > 0),
  15265. resultCode: 0,
  15266. resultMessage: (userConstrPolicies.length > 0) ? EMPTY_STRING : "Zero \"userConstrPolicies\" array, no intersections with \"authConstrPolicies\"",
  15267. authConstrPolicies,
  15268. userConstrPolicies,
  15269. explicitPolicyIndicator,
  15270. policyMappings,
  15271. certificatePath: this.certs
  15272. };
  15273. if (userConstrPolicies.length === 0)
  15274. return policyResult;
  15275. if (policyResult.result === false)
  15276. return policyResult;
  15277. pathDepth = 1;
  15278. for (let i = (this.certs.length - 2); i >= 0; i--, pathDepth++) {
  15279. const cert = this.certs[i];
  15280. let subjectAltNames = [];
  15281. let certPermittedSubtrees = [];
  15282. let certExcludedSubtrees = [];
  15283. if (cert.extensions) {
  15284. for (let j = 0; j < cert.extensions.length; j++) {
  15285. const extension = cert.extensions[j];
  15286. if (extension.extnID === id_NameConstraints) {
  15287. if ("permittedSubtrees" in extension.parsedValue)
  15288. certPermittedSubtrees = certPermittedSubtrees.concat(extension.parsedValue.permittedSubtrees);
  15289. if ("excludedSubtrees" in extension.parsedValue)
  15290. certExcludedSubtrees = certExcludedSubtrees.concat(extension.parsedValue.excludedSubtrees);
  15291. }
  15292. if (extension.extnID === id_SubjectAltName)
  15293. subjectAltNames = subjectAltNames.concat(extension.parsedValue.altNames);
  15294. }
  15295. }
  15296. let formFound = (requiredNameForms.length <= 0);
  15297. for (let j = 0; j < requiredNameForms.length; j++) {
  15298. switch (requiredNameForms[j].base.type) {
  15299. case 4:
  15300. {
  15301. if (requiredNameForms[j].base.value.typesAndValues.length !== cert.subject.typesAndValues.length)
  15302. continue;
  15303. formFound = true;
  15304. for (let k = 0; k < cert.subject.typesAndValues.length; k++) {
  15305. if (cert.subject.typesAndValues[k].type !== requiredNameForms[j].base.value.typesAndValues[k].type) {
  15306. formFound = false;
  15307. break;
  15308. }
  15309. }
  15310. if (formFound === true)
  15311. break;
  15312. }
  15313. break;
  15314. default:
  15315. }
  15316. }
  15317. if (formFound === false) {
  15318. policyResult.result = false;
  15319. policyResult.resultCode = 21;
  15320. policyResult.resultMessage = "No necessary name form found";
  15321. throw policyResult;
  15322. }
  15323. const constrGroups = [
  15324. [],
  15325. [],
  15326. [],
  15327. [],
  15328. [],
  15329. ];
  15330. for (let j = 0; j < permittedSubtrees.length; j++) {
  15331. switch (permittedSubtrees[j].base.type) {
  15332. case 1:
  15333. constrGroups[0].push(permittedSubtrees[j]);
  15334. break;
  15335. case 2:
  15336. constrGroups[1].push(permittedSubtrees[j]);
  15337. break;
  15338. case 4:
  15339. constrGroups[2].push(permittedSubtrees[j]);
  15340. break;
  15341. case 6:
  15342. constrGroups[3].push(permittedSubtrees[j]);
  15343. break;
  15344. case 7:
  15345. constrGroups[4].push(permittedSubtrees[j]);
  15346. break;
  15347. default:
  15348. }
  15349. }
  15350. for (let p = 0; p < 5; p++) {
  15351. let groupPermitted = false;
  15352. let valueExists = false;
  15353. const group = constrGroups[p];
  15354. for (let j = 0; j < group.length; j++) {
  15355. switch (p) {
  15356. case 0:
  15357. if (subjectAltNames.length > 0) {
  15358. for (let k = 0; k < subjectAltNames.length; k++) {
  15359. if (subjectAltNames[k].type === 1) {
  15360. valueExists = true;
  15361. groupPermitted = groupPermitted || compareRFC822Name(subjectAltNames[k].value, group[j].base.value);
  15362. }
  15363. }
  15364. }
  15365. else {
  15366. for (let k = 0; k < cert.subject.typesAndValues.length; k++) {
  15367. if ((cert.subject.typesAndValues[k].type === "1.2.840.113549.1.9.1") ||
  15368. (cert.subject.typesAndValues[k].type === "0.9.2342.19200300.100.1.3")) {
  15369. valueExists = true;
  15370. groupPermitted = groupPermitted || compareRFC822Name(cert.subject.typesAndValues[k].value.valueBlock.value, group[j].base.value);
  15371. }
  15372. }
  15373. }
  15374. break;
  15375. case 1:
  15376. if (subjectAltNames.length > 0) {
  15377. for (let k = 0; k < subjectAltNames.length; k++) {
  15378. if (subjectAltNames[k].type === 2) {
  15379. valueExists = true;
  15380. groupPermitted = groupPermitted || compareDNSName(subjectAltNames[k].value, group[j].base.value);
  15381. }
  15382. }
  15383. }
  15384. break;
  15385. case 2:
  15386. valueExists = true;
  15387. groupPermitted = compareDirectoryName(cert.subject, group[j].base.value);
  15388. break;
  15389. case 3:
  15390. if (subjectAltNames.length > 0) {
  15391. for (let k = 0; k < subjectAltNames.length; k++) {
  15392. if (subjectAltNames[k].type === 6) {
  15393. valueExists = true;
  15394. groupPermitted = groupPermitted || compareUniformResourceIdentifier(subjectAltNames[k].value, group[j].base.value);
  15395. }
  15396. }
  15397. }
  15398. break;
  15399. case 4:
  15400. if (subjectAltNames.length > 0) {
  15401. for (let k = 0; k < subjectAltNames.length; k++) {
  15402. if (subjectAltNames[k].type === 7) {
  15403. valueExists = true;
  15404. groupPermitted = groupPermitted || compareIPAddress(subjectAltNames[k].value, group[j].base.value);
  15405. }
  15406. }
  15407. }
  15408. break;
  15409. default:
  15410. }
  15411. if (groupPermitted)
  15412. break;
  15413. }
  15414. if ((groupPermitted === false) && (group.length > 0) && valueExists) {
  15415. policyResult.result = false;
  15416. policyResult.resultCode = 41;
  15417. policyResult.resultMessage = "Failed to meet \"permitted sub-trees\" name constraint";
  15418. throw policyResult;
  15419. }
  15420. }
  15421. let excluded = false;
  15422. for (let j = 0; j < excludedSubtrees.length; j++) {
  15423. switch (excludedSubtrees[j].base.type) {
  15424. case 1:
  15425. if (subjectAltNames.length >= 0) {
  15426. for (let k = 0; k < subjectAltNames.length; k++) {
  15427. if (subjectAltNames[k].type === 1)
  15428. excluded = excluded || compareRFC822Name(subjectAltNames[k].value, excludedSubtrees[j].base.value);
  15429. }
  15430. }
  15431. else {
  15432. for (let k = 0; k < cert.subject.typesAndValues.length; k++) {
  15433. if ((cert.subject.typesAndValues[k].type === "1.2.840.113549.1.9.1") ||
  15434. (cert.subject.typesAndValues[k].type === "0.9.2342.19200300.100.1.3"))
  15435. excluded = excluded || compareRFC822Name(cert.subject.typesAndValues[k].value.valueBlock.value, excludedSubtrees[j].base.value);
  15436. }
  15437. }
  15438. break;
  15439. case 2:
  15440. if (subjectAltNames.length > 0) {
  15441. for (let k = 0; k < subjectAltNames.length; k++) {
  15442. if (subjectAltNames[k].type === 2)
  15443. excluded = excluded || compareDNSName(subjectAltNames[k].value, excludedSubtrees[j].base.value);
  15444. }
  15445. }
  15446. break;
  15447. case 4:
  15448. excluded = excluded || compareDirectoryName(cert.subject, excludedSubtrees[j].base.value);
  15449. break;
  15450. case 6:
  15451. if (subjectAltNames.length > 0) {
  15452. for (let k = 0; k < subjectAltNames.length; k++) {
  15453. if (subjectAltNames[k].type === 6)
  15454. excluded = excluded || compareUniformResourceIdentifier(subjectAltNames[k].value, excludedSubtrees[j].base.value);
  15455. }
  15456. }
  15457. break;
  15458. case 7:
  15459. if (subjectAltNames.length > 0) {
  15460. for (let k = 0; k < subjectAltNames.length; k++) {
  15461. if (subjectAltNames[k].type === 7)
  15462. excluded = excluded || compareIPAddress(subjectAltNames[k].value, excludedSubtrees[j].base.value);
  15463. }
  15464. }
  15465. break;
  15466. default:
  15467. }
  15468. if (excluded)
  15469. break;
  15470. }
  15471. if (excluded === true) {
  15472. policyResult.result = false;
  15473. policyResult.resultCode = 42;
  15474. policyResult.resultMessage = "Failed to meet \"excluded sub-trees\" name constraint";
  15475. throw policyResult;
  15476. }
  15477. permittedSubtrees = permittedSubtrees.concat(certPermittedSubtrees);
  15478. excludedSubtrees = excludedSubtrees.concat(certExcludedSubtrees);
  15479. }
  15480. return policyResult;
  15481. }
  15482. catch (error) {
  15483. if (error instanceof Error) {
  15484. if (error instanceof ChainValidationError) {
  15485. return {
  15486. result: false,
  15487. resultCode: error.code,
  15488. resultMessage: error.message,
  15489. error: error,
  15490. };
  15491. }
  15492. return {
  15493. result: false,
  15494. resultCode: exports.ChainValidationCode.unknown,
  15495. resultMessage: error.message,
  15496. error: error,
  15497. };
  15498. }
  15499. if (error && typeof error === "object" && "resultMessage" in error) {
  15500. return error;
  15501. }
  15502. return {
  15503. result: false,
  15504. resultCode: -1,
  15505. resultMessage: `${error}`,
  15506. };
  15507. }
  15508. }
  15509. }
  15510. const TBS_RESPONSE_DATA = "tbsResponseData";
  15511. const SIGNATURE_ALGORITHM$3 = "signatureAlgorithm";
  15512. const SIGNATURE$2 = "signature";
  15513. const CERTS$1 = "certs";
  15514. const BASIC_OCSP_RESPONSE = "BasicOCSPResponse";
  15515. const BASIC_OCSP_RESPONSE_TBS_RESPONSE_DATA = `${BASIC_OCSP_RESPONSE}.${TBS_RESPONSE_DATA}`;
  15516. const BASIC_OCSP_RESPONSE_SIGNATURE_ALGORITHM = `${BASIC_OCSP_RESPONSE}.${SIGNATURE_ALGORITHM$3}`;
  15517. const BASIC_OCSP_RESPONSE_SIGNATURE = `${BASIC_OCSP_RESPONSE}.${SIGNATURE$2}`;
  15518. const BASIC_OCSP_RESPONSE_CERTS = `${BASIC_OCSP_RESPONSE}.${CERTS$1}`;
  15519. const CLEAR_PROPS$g = [
  15520. BASIC_OCSP_RESPONSE_TBS_RESPONSE_DATA,
  15521. BASIC_OCSP_RESPONSE_SIGNATURE_ALGORITHM,
  15522. BASIC_OCSP_RESPONSE_SIGNATURE,
  15523. BASIC_OCSP_RESPONSE_CERTS
  15524. ];
  15525. class BasicOCSPResponse extends PkiObject {
  15526. constructor(parameters = {}) {
  15527. super();
  15528. this.tbsResponseData = pvutils__namespace.getParametersValue(parameters, TBS_RESPONSE_DATA, BasicOCSPResponse.defaultValues(TBS_RESPONSE_DATA));
  15529. this.signatureAlgorithm = pvutils__namespace.getParametersValue(parameters, SIGNATURE_ALGORITHM$3, BasicOCSPResponse.defaultValues(SIGNATURE_ALGORITHM$3));
  15530. this.signature = pvutils__namespace.getParametersValue(parameters, SIGNATURE$2, BasicOCSPResponse.defaultValues(SIGNATURE$2));
  15531. if (CERTS$1 in parameters) {
  15532. this.certs = pvutils__namespace.getParametersValue(parameters, CERTS$1, BasicOCSPResponse.defaultValues(CERTS$1));
  15533. }
  15534. if (parameters.schema) {
  15535. this.fromSchema(parameters.schema);
  15536. }
  15537. }
  15538. static defaultValues(memberName) {
  15539. switch (memberName) {
  15540. case TBS_RESPONSE_DATA:
  15541. return new ResponseData();
  15542. case SIGNATURE_ALGORITHM$3:
  15543. return new AlgorithmIdentifier();
  15544. case SIGNATURE$2:
  15545. return new asn1js__namespace.BitString();
  15546. case CERTS$1:
  15547. return [];
  15548. default:
  15549. return super.defaultValues(memberName);
  15550. }
  15551. }
  15552. static compareWithDefault(memberName, memberValue) {
  15553. switch (memberName) {
  15554. case "type":
  15555. {
  15556. let comparisonResult = ((ResponseData.compareWithDefault("tbs", memberValue.tbs)) &&
  15557. (ResponseData.compareWithDefault("responderID", memberValue.responderID)) &&
  15558. (ResponseData.compareWithDefault("producedAt", memberValue.producedAt)) &&
  15559. (ResponseData.compareWithDefault("responses", memberValue.responses)));
  15560. if ("responseExtensions" in memberValue)
  15561. comparisonResult = comparisonResult && (ResponseData.compareWithDefault("responseExtensions", memberValue.responseExtensions));
  15562. return comparisonResult;
  15563. }
  15564. case SIGNATURE_ALGORITHM$3:
  15565. return ((memberValue.algorithmId === EMPTY_STRING) && (("algorithmParams" in memberValue) === false));
  15566. case SIGNATURE$2:
  15567. return (memberValue.isEqual(BasicOCSPResponse.defaultValues(memberName)));
  15568. case CERTS$1:
  15569. return (memberValue.length === 0);
  15570. default:
  15571. return super.defaultValues(memberName);
  15572. }
  15573. }
  15574. static schema(parameters = {}) {
  15575. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  15576. return (new asn1js__namespace.Sequence({
  15577. name: (names.blockName || BASIC_OCSP_RESPONSE),
  15578. value: [
  15579. ResponseData.schema(names.tbsResponseData || {
  15580. names: {
  15581. blockName: BASIC_OCSP_RESPONSE_TBS_RESPONSE_DATA
  15582. }
  15583. }),
  15584. AlgorithmIdentifier.schema(names.signatureAlgorithm || {
  15585. names: {
  15586. blockName: BASIC_OCSP_RESPONSE_SIGNATURE_ALGORITHM
  15587. }
  15588. }),
  15589. new asn1js__namespace.BitString({ name: (names.signature || BASIC_OCSP_RESPONSE_SIGNATURE) }),
  15590. new asn1js__namespace.Constructed({
  15591. optional: true,
  15592. idBlock: {
  15593. tagClass: 3,
  15594. tagNumber: 0
  15595. },
  15596. value: [
  15597. new asn1js__namespace.Sequence({
  15598. value: [new asn1js__namespace.Repeated({
  15599. name: BASIC_OCSP_RESPONSE_CERTS,
  15600. value: Certificate.schema(names.certs || {})
  15601. })]
  15602. })
  15603. ]
  15604. })
  15605. ]
  15606. }));
  15607. }
  15608. fromSchema(schema) {
  15609. pvutils__namespace.clearProps(schema, CLEAR_PROPS$g);
  15610. const asn1 = asn1js__namespace.compareSchema(schema, schema, BasicOCSPResponse.schema());
  15611. AsnError.assertSchema(asn1, this.className);
  15612. this.tbsResponseData = new ResponseData({ schema: asn1.result[BASIC_OCSP_RESPONSE_TBS_RESPONSE_DATA] });
  15613. this.signatureAlgorithm = new AlgorithmIdentifier({ schema: asn1.result[BASIC_OCSP_RESPONSE_SIGNATURE_ALGORITHM] });
  15614. this.signature = asn1.result[BASIC_OCSP_RESPONSE_SIGNATURE];
  15615. if (BASIC_OCSP_RESPONSE_CERTS in asn1.result) {
  15616. this.certs = Array.from(asn1.result[BASIC_OCSP_RESPONSE_CERTS], element => new Certificate({ schema: element }));
  15617. }
  15618. }
  15619. toSchema() {
  15620. const outputArray = [];
  15621. outputArray.push(this.tbsResponseData.toSchema());
  15622. outputArray.push(this.signatureAlgorithm.toSchema());
  15623. outputArray.push(this.signature);
  15624. if (this.certs) {
  15625. outputArray.push(new asn1js__namespace.Constructed({
  15626. idBlock: {
  15627. tagClass: 3,
  15628. tagNumber: 0
  15629. },
  15630. value: [
  15631. new asn1js__namespace.Sequence({
  15632. value: Array.from(this.certs, o => o.toSchema())
  15633. })
  15634. ]
  15635. }));
  15636. }
  15637. return (new asn1js__namespace.Sequence({
  15638. value: outputArray
  15639. }));
  15640. }
  15641. toJSON() {
  15642. const res = {
  15643. tbsResponseData: this.tbsResponseData.toJSON(),
  15644. signatureAlgorithm: this.signatureAlgorithm.toJSON(),
  15645. signature: this.signature.toJSON(),
  15646. };
  15647. if (this.certs) {
  15648. res.certs = Array.from(this.certs, o => o.toJSON());
  15649. }
  15650. return res;
  15651. }
  15652. async getCertificateStatus(certificate, issuerCertificate, crypto = getCrypto(true)) {
  15653. const result = {
  15654. isForCertificate: false,
  15655. status: 2
  15656. };
  15657. const hashesObject = {};
  15658. const certIDs = [];
  15659. for (const response of this.tbsResponseData.responses) {
  15660. const hashAlgorithm = crypto.getAlgorithmByOID(response.certID.hashAlgorithm.algorithmId, true, "CertID.hashAlgorithm");
  15661. if (!hashesObject[hashAlgorithm.name]) {
  15662. hashesObject[hashAlgorithm.name] = 1;
  15663. const certID = new CertID();
  15664. certIDs.push(certID);
  15665. await certID.createForCertificate(certificate, {
  15666. hashAlgorithm: hashAlgorithm.name,
  15667. issuerCertificate
  15668. }, crypto);
  15669. }
  15670. }
  15671. for (const response of this.tbsResponseData.responses) {
  15672. for (const id of certIDs) {
  15673. if (response.certID.isEqual(id)) {
  15674. result.isForCertificate = true;
  15675. try {
  15676. switch (response.certStatus.idBlock.isConstructed) {
  15677. case true:
  15678. if (response.certStatus.idBlock.tagNumber === 1)
  15679. result.status = 1;
  15680. break;
  15681. case false:
  15682. switch (response.certStatus.idBlock.tagNumber) {
  15683. case 0:
  15684. result.status = 0;
  15685. break;
  15686. case 2:
  15687. result.status = 2;
  15688. break;
  15689. default:
  15690. }
  15691. break;
  15692. default:
  15693. }
  15694. }
  15695. catch {
  15696. }
  15697. return result;
  15698. }
  15699. }
  15700. }
  15701. return result;
  15702. }
  15703. async sign(privateKey, hashAlgorithm = "SHA-1", crypto = getCrypto(true)) {
  15704. if (!privateKey) {
  15705. throw new Error("Need to provide a private key for signing");
  15706. }
  15707. const signatureParams = await crypto.getSignatureParameters(privateKey, hashAlgorithm);
  15708. const algorithm = signatureParams.parameters.algorithm;
  15709. if (!("name" in algorithm)) {
  15710. throw new Error("Empty algorithm");
  15711. }
  15712. this.signatureAlgorithm = signatureParams.signatureAlgorithm;
  15713. this.tbsResponseData.tbsView = new Uint8Array(this.tbsResponseData.toSchema(true).toBER());
  15714. const signature = await crypto.signWithPrivateKey(this.tbsResponseData.tbsView, privateKey, { algorithm });
  15715. this.signature = new asn1js__namespace.BitString({ valueHex: signature });
  15716. }
  15717. async verify(params = {}, crypto = getCrypto(true)) {
  15718. let signerCert = null;
  15719. let certIndex = -1;
  15720. const trustedCerts = params.trustedCerts || [];
  15721. if (!this.certs) {
  15722. throw new Error("No certificates attached to the BasicOCSPResponse");
  15723. }
  15724. switch (true) {
  15725. case (this.tbsResponseData.responderID instanceof RelativeDistinguishedNames):
  15726. for (const [index, certificate] of this.certs.entries()) {
  15727. if (certificate.subject.isEqual(this.tbsResponseData.responderID)) {
  15728. certIndex = index;
  15729. break;
  15730. }
  15731. }
  15732. break;
  15733. case (this.tbsResponseData.responderID instanceof asn1js__namespace.OctetString):
  15734. for (const [index, cert] of this.certs.entries()) {
  15735. const hash = await crypto.digest({ name: "sha-1" }, cert.subjectPublicKeyInfo.subjectPublicKey.valueBlock.valueHexView);
  15736. if (pvutils__namespace.isEqualBuffer(hash, this.tbsResponseData.responderID.valueBlock.valueHex)) {
  15737. certIndex = index;
  15738. break;
  15739. }
  15740. }
  15741. break;
  15742. default:
  15743. throw new Error("Wrong value for responderID");
  15744. }
  15745. if (certIndex === (-1))
  15746. throw new Error("Correct certificate was not found in OCSP response");
  15747. signerCert = this.certs[certIndex];
  15748. const additionalCerts = [signerCert];
  15749. for (const cert of this.certs) {
  15750. const caCert = await checkCA(cert, signerCert);
  15751. if (caCert) {
  15752. additionalCerts.push(caCert);
  15753. }
  15754. }
  15755. const certChain = new CertificateChainValidationEngine({
  15756. certs: additionalCerts,
  15757. trustedCerts,
  15758. });
  15759. const verificationResult = await certChain.verify({}, crypto);
  15760. if (!verificationResult.result) {
  15761. throw new Error("Validation of signer's certificate failed");
  15762. }
  15763. return crypto.verifyWithPublicKey(this.tbsResponseData.tbsView, this.signature, this.certs[certIndex].subjectPublicKeyInfo, this.signatureAlgorithm);
  15764. }
  15765. }
  15766. BasicOCSPResponse.CLASS_NAME = "BasicOCSPResponse";
  15767. const TBS$1 = "tbs";
  15768. const VERSION$6 = "version";
  15769. const SUBJECT = "subject";
  15770. const SPKI = "subjectPublicKeyInfo";
  15771. const ATTRIBUTES$1 = "attributes";
  15772. const SIGNATURE_ALGORITHM$2 = "signatureAlgorithm";
  15773. const SIGNATURE_VALUE = "signatureValue";
  15774. const CSR_INFO = "CertificationRequestInfo";
  15775. const CSR_INFO_VERSION = `${CSR_INFO}.version`;
  15776. const CSR_INFO_SUBJECT = `${CSR_INFO}.subject`;
  15777. const CSR_INFO_SPKI = `${CSR_INFO}.subjectPublicKeyInfo`;
  15778. const CSR_INFO_ATTRS = `${CSR_INFO}.attributes`;
  15779. const CLEAR_PROPS$f = [
  15780. CSR_INFO,
  15781. CSR_INFO_VERSION,
  15782. CSR_INFO_SUBJECT,
  15783. CSR_INFO_SPKI,
  15784. CSR_INFO_ATTRS,
  15785. SIGNATURE_ALGORITHM$2,
  15786. SIGNATURE_VALUE
  15787. ];
  15788. function CertificationRequestInfo(parameters = {}) {
  15789. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  15790. return (new asn1js__namespace.Sequence({
  15791. name: (names.CertificationRequestInfo || CSR_INFO),
  15792. value: [
  15793. new asn1js__namespace.Integer({ name: (names.CertificationRequestInfoVersion || CSR_INFO_VERSION) }),
  15794. RelativeDistinguishedNames.schema(names.subject || {
  15795. names: {
  15796. blockName: CSR_INFO_SUBJECT
  15797. }
  15798. }),
  15799. PublicKeyInfo.schema({
  15800. names: {
  15801. blockName: CSR_INFO_SPKI
  15802. }
  15803. }),
  15804. new asn1js__namespace.Constructed({
  15805. optional: true,
  15806. idBlock: {
  15807. tagClass: 3,
  15808. tagNumber: 0
  15809. },
  15810. value: [
  15811. new asn1js__namespace.Repeated({
  15812. optional: true,
  15813. name: (names.CertificationRequestInfoAttributes || CSR_INFO_ATTRS),
  15814. value: Attribute.schema(names.attributes || {})
  15815. })
  15816. ]
  15817. })
  15818. ]
  15819. }));
  15820. }
  15821. class CertificationRequest extends PkiObject {
  15822. get tbs() {
  15823. return pvtsutils__namespace.BufferSourceConverter.toArrayBuffer(this.tbsView);
  15824. }
  15825. set tbs(value) {
  15826. this.tbsView = new Uint8Array(value);
  15827. }
  15828. constructor(parameters = {}) {
  15829. super();
  15830. this.tbsView = new Uint8Array(pvutils__namespace.getParametersValue(parameters, TBS$1, CertificationRequest.defaultValues(TBS$1)));
  15831. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$6, CertificationRequest.defaultValues(VERSION$6));
  15832. this.subject = pvutils__namespace.getParametersValue(parameters, SUBJECT, CertificationRequest.defaultValues(SUBJECT));
  15833. this.subjectPublicKeyInfo = pvutils__namespace.getParametersValue(parameters, SPKI, CertificationRequest.defaultValues(SPKI));
  15834. if (ATTRIBUTES$1 in parameters) {
  15835. this.attributes = pvutils__namespace.getParametersValue(parameters, ATTRIBUTES$1, CertificationRequest.defaultValues(ATTRIBUTES$1));
  15836. }
  15837. this.signatureAlgorithm = pvutils__namespace.getParametersValue(parameters, SIGNATURE_ALGORITHM$2, CertificationRequest.defaultValues(SIGNATURE_ALGORITHM$2));
  15838. this.signatureValue = pvutils__namespace.getParametersValue(parameters, SIGNATURE_VALUE, CertificationRequest.defaultValues(SIGNATURE_VALUE));
  15839. if (parameters.schema) {
  15840. this.fromSchema(parameters.schema);
  15841. }
  15842. }
  15843. static defaultValues(memberName) {
  15844. switch (memberName) {
  15845. case TBS$1:
  15846. return EMPTY_BUFFER;
  15847. case VERSION$6:
  15848. return 0;
  15849. case SUBJECT:
  15850. return new RelativeDistinguishedNames();
  15851. case SPKI:
  15852. return new PublicKeyInfo();
  15853. case ATTRIBUTES$1:
  15854. return [];
  15855. case SIGNATURE_ALGORITHM$2:
  15856. return new AlgorithmIdentifier();
  15857. case SIGNATURE_VALUE:
  15858. return new asn1js__namespace.BitString();
  15859. default:
  15860. return super.defaultValues(memberName);
  15861. }
  15862. }
  15863. static schema(parameters = {}) {
  15864. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  15865. return (new asn1js__namespace.Sequence({
  15866. value: [
  15867. CertificationRequestInfo(names.certificationRequestInfo || {}),
  15868. new asn1js__namespace.Sequence({
  15869. name: (names.signatureAlgorithm || SIGNATURE_ALGORITHM$2),
  15870. value: [
  15871. new asn1js__namespace.ObjectIdentifier(),
  15872. new asn1js__namespace.Any({ optional: true })
  15873. ]
  15874. }),
  15875. new asn1js__namespace.BitString({ name: (names.signatureValue || SIGNATURE_VALUE) })
  15876. ]
  15877. }));
  15878. }
  15879. fromSchema(schema) {
  15880. pvutils__namespace.clearProps(schema, CLEAR_PROPS$f);
  15881. const asn1 = asn1js__namespace.compareSchema(schema, schema, CertificationRequest.schema());
  15882. AsnError.assertSchema(asn1, this.className);
  15883. this.tbsView = asn1.result.CertificationRequestInfo.valueBeforeDecodeView;
  15884. this.version = asn1.result[CSR_INFO_VERSION].valueBlock.valueDec;
  15885. this.subject = new RelativeDistinguishedNames({ schema: asn1.result[CSR_INFO_SUBJECT] });
  15886. this.subjectPublicKeyInfo = new PublicKeyInfo({ schema: asn1.result[CSR_INFO_SPKI] });
  15887. if (CSR_INFO_ATTRS in asn1.result) {
  15888. this.attributes = Array.from(asn1.result[CSR_INFO_ATTRS], element => new Attribute({ schema: element }));
  15889. }
  15890. this.signatureAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.signatureAlgorithm });
  15891. this.signatureValue = asn1.result.signatureValue;
  15892. }
  15893. encodeTBS() {
  15894. const outputArray = [
  15895. new asn1js__namespace.Integer({ value: this.version }),
  15896. this.subject.toSchema(),
  15897. this.subjectPublicKeyInfo.toSchema()
  15898. ];
  15899. if (ATTRIBUTES$1 in this) {
  15900. outputArray.push(new asn1js__namespace.Constructed({
  15901. idBlock: {
  15902. tagClass: 3,
  15903. tagNumber: 0
  15904. },
  15905. value: Array.from(this.attributes || [], o => o.toSchema())
  15906. }));
  15907. }
  15908. return (new asn1js__namespace.Sequence({
  15909. value: outputArray
  15910. }));
  15911. }
  15912. toSchema(encodeFlag = false) {
  15913. let tbsSchema;
  15914. if (encodeFlag === false) {
  15915. if (this.tbsView.byteLength === 0) {
  15916. return CertificationRequest.schema();
  15917. }
  15918. const asn1 = asn1js__namespace.fromBER(this.tbsView);
  15919. AsnError.assert(asn1, "PKCS#10 Certificate Request");
  15920. tbsSchema = asn1.result;
  15921. }
  15922. else {
  15923. tbsSchema = this.encodeTBS();
  15924. }
  15925. return (new asn1js__namespace.Sequence({
  15926. value: [
  15927. tbsSchema,
  15928. this.signatureAlgorithm.toSchema(),
  15929. this.signatureValue
  15930. ]
  15931. }));
  15932. }
  15933. toJSON() {
  15934. const object = {
  15935. tbs: pvtsutils__namespace.Convert.ToHex(this.tbsView),
  15936. version: this.version,
  15937. subject: this.subject.toJSON(),
  15938. subjectPublicKeyInfo: this.subjectPublicKeyInfo.toJSON(),
  15939. signatureAlgorithm: this.signatureAlgorithm.toJSON(),
  15940. signatureValue: this.signatureValue.toJSON(),
  15941. };
  15942. if (ATTRIBUTES$1 in this) {
  15943. object.attributes = Array.from(this.attributes || [], o => o.toJSON());
  15944. }
  15945. return object;
  15946. }
  15947. async sign(privateKey, hashAlgorithm = "SHA-1", crypto = getCrypto(true)) {
  15948. if (!privateKey) {
  15949. throw new Error("Need to provide a private key for signing");
  15950. }
  15951. const signatureParams = await crypto.getSignatureParameters(privateKey, hashAlgorithm);
  15952. const parameters = signatureParams.parameters;
  15953. this.signatureAlgorithm = signatureParams.signatureAlgorithm;
  15954. this.tbsView = new Uint8Array(this.encodeTBS().toBER());
  15955. const signature = await crypto.signWithPrivateKey(this.tbsView, privateKey, parameters);
  15956. this.signatureValue = new asn1js__namespace.BitString({ valueHex: signature });
  15957. }
  15958. async verify(crypto = getCrypto(true)) {
  15959. return crypto.verifyWithPublicKey(this.tbsView, this.signatureValue, this.subjectPublicKeyInfo, this.signatureAlgorithm);
  15960. }
  15961. async getPublicKey(parameters, crypto = getCrypto(true)) {
  15962. return crypto.getPublicKey(this.subjectPublicKeyInfo, this.signatureAlgorithm, parameters);
  15963. }
  15964. }
  15965. CertificationRequest.CLASS_NAME = "CertificationRequest";
  15966. const DIGEST_ALGORITHM$1 = "digestAlgorithm";
  15967. const DIGEST = "digest";
  15968. const CLEAR_PROPS$e = [
  15969. DIGEST_ALGORITHM$1,
  15970. DIGEST
  15971. ];
  15972. class DigestInfo extends PkiObject {
  15973. constructor(parameters = {}) {
  15974. super();
  15975. this.digestAlgorithm = pvutils__namespace.getParametersValue(parameters, DIGEST_ALGORITHM$1, DigestInfo.defaultValues(DIGEST_ALGORITHM$1));
  15976. this.digest = pvutils__namespace.getParametersValue(parameters, DIGEST, DigestInfo.defaultValues(DIGEST));
  15977. if (parameters.schema) {
  15978. this.fromSchema(parameters.schema);
  15979. }
  15980. }
  15981. static defaultValues(memberName) {
  15982. switch (memberName) {
  15983. case DIGEST_ALGORITHM$1:
  15984. return new AlgorithmIdentifier();
  15985. case DIGEST:
  15986. return new asn1js__namespace.OctetString();
  15987. default:
  15988. return super.defaultValues(memberName);
  15989. }
  15990. }
  15991. static compareWithDefault(memberName, memberValue) {
  15992. switch (memberName) {
  15993. case DIGEST_ALGORITHM$1:
  15994. return ((AlgorithmIdentifier.compareWithDefault("algorithmId", memberValue.algorithmId)) &&
  15995. (("algorithmParams" in memberValue) === false));
  15996. case DIGEST:
  15997. return (memberValue.isEqual(DigestInfo.defaultValues(memberName)));
  15998. default:
  15999. return super.defaultValues(memberName);
  16000. }
  16001. }
  16002. static schema(parameters = {}) {
  16003. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  16004. return (new asn1js__namespace.Sequence({
  16005. name: (names.blockName || EMPTY_STRING),
  16006. value: [
  16007. AlgorithmIdentifier.schema(names.digestAlgorithm || {
  16008. names: {
  16009. blockName: DIGEST_ALGORITHM$1
  16010. }
  16011. }),
  16012. new asn1js__namespace.OctetString({ name: (names.digest || DIGEST) })
  16013. ]
  16014. }));
  16015. }
  16016. fromSchema(schema) {
  16017. pvutils__namespace.clearProps(schema, CLEAR_PROPS$e);
  16018. const asn1 = asn1js__namespace.compareSchema(schema, schema, DigestInfo.schema({
  16019. names: {
  16020. digestAlgorithm: {
  16021. names: {
  16022. blockName: DIGEST_ALGORITHM$1
  16023. }
  16024. },
  16025. digest: DIGEST
  16026. }
  16027. }));
  16028. AsnError.assertSchema(asn1, this.className);
  16029. this.digestAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.digestAlgorithm });
  16030. this.digest = asn1.result.digest;
  16031. }
  16032. toSchema() {
  16033. return (new asn1js__namespace.Sequence({
  16034. value: [
  16035. this.digestAlgorithm.toSchema(),
  16036. this.digest
  16037. ]
  16038. }));
  16039. }
  16040. toJSON() {
  16041. return {
  16042. digestAlgorithm: this.digestAlgorithm.toJSON(),
  16043. digest: this.digest.toJSON(),
  16044. };
  16045. }
  16046. }
  16047. DigestInfo.CLASS_NAME = "DigestInfo";
  16048. const E_CONTENT_TYPE = "eContentType";
  16049. const E_CONTENT = "eContent";
  16050. const CLEAR_PROPS$d = [
  16051. E_CONTENT_TYPE,
  16052. E_CONTENT,
  16053. ];
  16054. class EncapsulatedContentInfo extends PkiObject {
  16055. constructor(parameters = {}) {
  16056. super();
  16057. this.eContentType = pvutils__namespace.getParametersValue(parameters, E_CONTENT_TYPE, EncapsulatedContentInfo.defaultValues(E_CONTENT_TYPE));
  16058. if (E_CONTENT in parameters) {
  16059. this.eContent = pvutils__namespace.getParametersValue(parameters, E_CONTENT, EncapsulatedContentInfo.defaultValues(E_CONTENT));
  16060. if ((this.eContent.idBlock.tagClass === 1) &&
  16061. (this.eContent.idBlock.tagNumber === 4)) {
  16062. if (this.eContent.idBlock.isConstructed === false) {
  16063. const constrString = new asn1js__namespace.OctetString({
  16064. idBlock: { isConstructed: true },
  16065. isConstructed: true
  16066. });
  16067. let offset = 0;
  16068. const viewHex = this.eContent.valueBlock.valueHexView.slice().buffer;
  16069. let length = viewHex.byteLength;
  16070. while (length > 0) {
  16071. const pieceView = new Uint8Array(viewHex, offset, ((offset + 65536) > viewHex.byteLength) ? (viewHex.byteLength - offset) : 65536);
  16072. const _array = new ArrayBuffer(pieceView.length);
  16073. const _view = new Uint8Array(_array);
  16074. for (let i = 0; i < _view.length; i++) {
  16075. _view[i] = pieceView[i];
  16076. }
  16077. constrString.valueBlock.value.push(new asn1js__namespace.OctetString({ valueHex: _array }));
  16078. length -= pieceView.length;
  16079. offset += pieceView.length;
  16080. }
  16081. this.eContent = constrString;
  16082. }
  16083. }
  16084. }
  16085. if (parameters.schema) {
  16086. this.fromSchema(parameters.schema);
  16087. }
  16088. }
  16089. static defaultValues(memberName) {
  16090. switch (memberName) {
  16091. case E_CONTENT_TYPE:
  16092. return EMPTY_STRING;
  16093. case E_CONTENT:
  16094. return new asn1js__namespace.OctetString();
  16095. default:
  16096. return super.defaultValues(memberName);
  16097. }
  16098. }
  16099. static compareWithDefault(memberName, memberValue) {
  16100. switch (memberName) {
  16101. case E_CONTENT_TYPE:
  16102. return (memberValue === EMPTY_STRING);
  16103. case E_CONTENT:
  16104. {
  16105. if ((memberValue.idBlock.tagClass === 1) && (memberValue.idBlock.tagNumber === 4))
  16106. return (memberValue.isEqual(EncapsulatedContentInfo.defaultValues(E_CONTENT)));
  16107. return false;
  16108. }
  16109. default:
  16110. return super.defaultValues(memberName);
  16111. }
  16112. }
  16113. static schema(parameters = {}) {
  16114. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  16115. return (new asn1js__namespace.Sequence({
  16116. name: (names.blockName || EMPTY_STRING),
  16117. value: [
  16118. new asn1js__namespace.ObjectIdentifier({ name: (names.eContentType || EMPTY_STRING) }),
  16119. new asn1js__namespace.Constructed({
  16120. optional: true,
  16121. idBlock: {
  16122. tagClass: 3,
  16123. tagNumber: 0
  16124. },
  16125. value: [
  16126. new asn1js__namespace.Any({ name: (names.eContent || EMPTY_STRING) })
  16127. ]
  16128. })
  16129. ]
  16130. }));
  16131. }
  16132. fromSchema(schema) {
  16133. pvutils__namespace.clearProps(schema, CLEAR_PROPS$d);
  16134. const asn1 = asn1js__namespace.compareSchema(schema, schema, EncapsulatedContentInfo.schema({
  16135. names: {
  16136. eContentType: E_CONTENT_TYPE,
  16137. eContent: E_CONTENT
  16138. }
  16139. }));
  16140. AsnError.assertSchema(asn1, this.className);
  16141. this.eContentType = asn1.result.eContentType.valueBlock.toString();
  16142. if (E_CONTENT in asn1.result)
  16143. this.eContent = asn1.result.eContent;
  16144. }
  16145. toSchema() {
  16146. const outputArray = [];
  16147. outputArray.push(new asn1js__namespace.ObjectIdentifier({ value: this.eContentType }));
  16148. if (this.eContent) {
  16149. if (EncapsulatedContentInfo.compareWithDefault(E_CONTENT, this.eContent) === false) {
  16150. outputArray.push(new asn1js__namespace.Constructed({
  16151. optional: true,
  16152. idBlock: {
  16153. tagClass: 3,
  16154. tagNumber: 0
  16155. },
  16156. value: [this.eContent]
  16157. }));
  16158. }
  16159. }
  16160. return (new asn1js__namespace.Sequence({
  16161. value: outputArray
  16162. }));
  16163. }
  16164. toJSON() {
  16165. const res = {
  16166. eContentType: this.eContentType
  16167. };
  16168. if (this.eContent && EncapsulatedContentInfo.compareWithDefault(E_CONTENT, this.eContent) === false) {
  16169. res.eContent = this.eContent.toJSON();
  16170. }
  16171. return res;
  16172. }
  16173. }
  16174. EncapsulatedContentInfo.CLASS_NAME = "EncapsulatedContentInfo";
  16175. class KeyBag extends PrivateKeyInfo {
  16176. constructor(parameters = {}) {
  16177. super(parameters);
  16178. }
  16179. }
  16180. const MAC = "mac";
  16181. const MAC_SALT = "macSalt";
  16182. const ITERATIONS = "iterations";
  16183. const CLEAR_PROPS$c = [
  16184. MAC,
  16185. MAC_SALT,
  16186. ITERATIONS
  16187. ];
  16188. class MacData extends PkiObject {
  16189. constructor(parameters = {}) {
  16190. super();
  16191. this.mac = pvutils__namespace.getParametersValue(parameters, MAC, MacData.defaultValues(MAC));
  16192. this.macSalt = pvutils__namespace.getParametersValue(parameters, MAC_SALT, MacData.defaultValues(MAC_SALT));
  16193. if (ITERATIONS in parameters) {
  16194. this.iterations = pvutils__namespace.getParametersValue(parameters, ITERATIONS, MacData.defaultValues(ITERATIONS));
  16195. }
  16196. if (parameters.schema) {
  16197. this.fromSchema(parameters.schema);
  16198. }
  16199. }
  16200. static defaultValues(memberName) {
  16201. switch (memberName) {
  16202. case MAC:
  16203. return new DigestInfo();
  16204. case MAC_SALT:
  16205. return new asn1js__namespace.OctetString();
  16206. case ITERATIONS:
  16207. return 1;
  16208. default:
  16209. return super.defaultValues(memberName);
  16210. }
  16211. }
  16212. static compareWithDefault(memberName, memberValue) {
  16213. switch (memberName) {
  16214. case MAC:
  16215. return ((DigestInfo.compareWithDefault("digestAlgorithm", memberValue.digestAlgorithm)) &&
  16216. (DigestInfo.compareWithDefault("digest", memberValue.digest)));
  16217. case MAC_SALT:
  16218. return (memberValue.isEqual(MacData.defaultValues(memberName)));
  16219. case ITERATIONS:
  16220. return (memberValue === MacData.defaultValues(memberName));
  16221. default:
  16222. return super.defaultValues(memberName);
  16223. }
  16224. }
  16225. static schema(parameters = {}) {
  16226. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  16227. return (new asn1js__namespace.Sequence({
  16228. name: (names.blockName || EMPTY_STRING),
  16229. optional: (names.optional || true),
  16230. value: [
  16231. DigestInfo.schema(names.mac || {
  16232. names: {
  16233. blockName: MAC
  16234. }
  16235. }),
  16236. new asn1js__namespace.OctetString({ name: (names.macSalt || MAC_SALT) }),
  16237. new asn1js__namespace.Integer({
  16238. optional: true,
  16239. name: (names.iterations || ITERATIONS)
  16240. })
  16241. ]
  16242. }));
  16243. }
  16244. fromSchema(schema) {
  16245. pvutils__namespace.clearProps(schema, CLEAR_PROPS$c);
  16246. const asn1 = asn1js__namespace.compareSchema(schema, schema, MacData.schema({
  16247. names: {
  16248. mac: {
  16249. names: {
  16250. blockName: MAC
  16251. }
  16252. },
  16253. macSalt: MAC_SALT,
  16254. iterations: ITERATIONS
  16255. }
  16256. }));
  16257. AsnError.assertSchema(asn1, this.className);
  16258. this.mac = new DigestInfo({ schema: asn1.result.mac });
  16259. this.macSalt = asn1.result.macSalt;
  16260. if (ITERATIONS in asn1.result)
  16261. this.iterations = asn1.result.iterations.valueBlock.valueDec;
  16262. }
  16263. toSchema() {
  16264. const outputArray = [
  16265. this.mac.toSchema(),
  16266. this.macSalt
  16267. ];
  16268. if (this.iterations !== undefined) {
  16269. outputArray.push(new asn1js__namespace.Integer({ value: this.iterations }));
  16270. }
  16271. return (new asn1js__namespace.Sequence({
  16272. value: outputArray
  16273. }));
  16274. }
  16275. toJSON() {
  16276. const res = {
  16277. mac: this.mac.toJSON(),
  16278. macSalt: this.macSalt.toJSON(),
  16279. };
  16280. if (this.iterations !== undefined) {
  16281. res.iterations = this.iterations;
  16282. }
  16283. return res;
  16284. }
  16285. }
  16286. MacData.CLASS_NAME = "MacData";
  16287. const HASH_ALGORITHM = "hashAlgorithm";
  16288. const HASHED_MESSAGE = "hashedMessage";
  16289. const CLEAR_PROPS$b = [
  16290. HASH_ALGORITHM,
  16291. HASHED_MESSAGE,
  16292. ];
  16293. class MessageImprint extends PkiObject {
  16294. static async create(hashAlgorithm, message, crypto = getCrypto(true)) {
  16295. const hashAlgorithmOID = crypto.getOIDByAlgorithm({ name: hashAlgorithm }, true, "hashAlgorithm");
  16296. const hashedMessage = await crypto.digest(hashAlgorithm, message);
  16297. const res = new MessageImprint({
  16298. hashAlgorithm: new AlgorithmIdentifier({
  16299. algorithmId: hashAlgorithmOID,
  16300. algorithmParams: new asn1js__namespace.Null(),
  16301. }),
  16302. hashedMessage: new asn1js__namespace.OctetString({ valueHex: hashedMessage })
  16303. });
  16304. return res;
  16305. }
  16306. constructor(parameters = {}) {
  16307. super();
  16308. this.hashAlgorithm = pvutils__namespace.getParametersValue(parameters, HASH_ALGORITHM, MessageImprint.defaultValues(HASH_ALGORITHM));
  16309. this.hashedMessage = pvutils__namespace.getParametersValue(parameters, HASHED_MESSAGE, MessageImprint.defaultValues(HASHED_MESSAGE));
  16310. if (parameters.schema) {
  16311. this.fromSchema(parameters.schema);
  16312. }
  16313. }
  16314. static defaultValues(memberName) {
  16315. switch (memberName) {
  16316. case HASH_ALGORITHM:
  16317. return new AlgorithmIdentifier();
  16318. case HASHED_MESSAGE:
  16319. return new asn1js__namespace.OctetString();
  16320. default:
  16321. return super.defaultValues(memberName);
  16322. }
  16323. }
  16324. static compareWithDefault(memberName, memberValue) {
  16325. switch (memberName) {
  16326. case HASH_ALGORITHM:
  16327. return ((memberValue.algorithmId === EMPTY_STRING) && (("algorithmParams" in memberValue) === false));
  16328. case HASHED_MESSAGE:
  16329. return (memberValue.isEqual(MessageImprint.defaultValues(memberName)) === 0);
  16330. default:
  16331. return super.defaultValues(memberName);
  16332. }
  16333. }
  16334. static schema(parameters = {}) {
  16335. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  16336. return (new asn1js__namespace.Sequence({
  16337. name: (names.blockName || EMPTY_STRING),
  16338. value: [
  16339. AlgorithmIdentifier.schema(names.hashAlgorithm || {}),
  16340. new asn1js__namespace.OctetString({ name: (names.hashedMessage || EMPTY_STRING) })
  16341. ]
  16342. }));
  16343. }
  16344. fromSchema(schema) {
  16345. pvutils__namespace.clearProps(schema, CLEAR_PROPS$b);
  16346. const asn1 = asn1js__namespace.compareSchema(schema, schema, MessageImprint.schema({
  16347. names: {
  16348. hashAlgorithm: {
  16349. names: {
  16350. blockName: HASH_ALGORITHM
  16351. }
  16352. },
  16353. hashedMessage: HASHED_MESSAGE
  16354. }
  16355. }));
  16356. AsnError.assertSchema(asn1, this.className);
  16357. this.hashAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.hashAlgorithm });
  16358. this.hashedMessage = asn1.result.hashedMessage;
  16359. }
  16360. toSchema() {
  16361. return (new asn1js__namespace.Sequence({
  16362. value: [
  16363. this.hashAlgorithm.toSchema(),
  16364. this.hashedMessage
  16365. ]
  16366. }));
  16367. }
  16368. toJSON() {
  16369. return {
  16370. hashAlgorithm: this.hashAlgorithm.toJSON(),
  16371. hashedMessage: this.hashedMessage.toJSON(),
  16372. };
  16373. }
  16374. }
  16375. MessageImprint.CLASS_NAME = "MessageImprint";
  16376. const REQ_CERT = "reqCert";
  16377. const SINGLE_REQUEST_EXTENSIONS = "singleRequestExtensions";
  16378. const CLEAR_PROPS$a = [
  16379. REQ_CERT,
  16380. SINGLE_REQUEST_EXTENSIONS,
  16381. ];
  16382. class Request extends PkiObject {
  16383. constructor(parameters = {}) {
  16384. super();
  16385. this.reqCert = pvutils__namespace.getParametersValue(parameters, REQ_CERT, Request.defaultValues(REQ_CERT));
  16386. if (SINGLE_REQUEST_EXTENSIONS in parameters) {
  16387. this.singleRequestExtensions = pvutils__namespace.getParametersValue(parameters, SINGLE_REQUEST_EXTENSIONS, Request.defaultValues(SINGLE_REQUEST_EXTENSIONS));
  16388. }
  16389. if (parameters.schema) {
  16390. this.fromSchema(parameters.schema);
  16391. }
  16392. }
  16393. static defaultValues(memberName) {
  16394. switch (memberName) {
  16395. case REQ_CERT:
  16396. return new CertID();
  16397. case SINGLE_REQUEST_EXTENSIONS:
  16398. return [];
  16399. default:
  16400. return super.defaultValues(memberName);
  16401. }
  16402. }
  16403. static compareWithDefault(memberName, memberValue) {
  16404. switch (memberName) {
  16405. case REQ_CERT:
  16406. return (memberValue.isEqual(Request.defaultValues(memberName)));
  16407. case SINGLE_REQUEST_EXTENSIONS:
  16408. return (memberValue.length === 0);
  16409. default:
  16410. return super.defaultValues(memberName);
  16411. }
  16412. }
  16413. static schema(parameters = {}) {
  16414. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  16415. return (new asn1js__namespace.Sequence({
  16416. name: (names.blockName || EMPTY_STRING),
  16417. value: [
  16418. CertID.schema(names.reqCert || {}),
  16419. new asn1js__namespace.Constructed({
  16420. optional: true,
  16421. idBlock: {
  16422. tagClass: 3,
  16423. tagNumber: 0
  16424. },
  16425. value: [Extensions.schema(names.extensions || {
  16426. names: {
  16427. blockName: (names.singleRequestExtensions || EMPTY_STRING)
  16428. }
  16429. })]
  16430. })
  16431. ]
  16432. }));
  16433. }
  16434. fromSchema(schema) {
  16435. pvutils__namespace.clearProps(schema, CLEAR_PROPS$a);
  16436. const asn1 = asn1js__namespace.compareSchema(schema, schema, Request.schema({
  16437. names: {
  16438. reqCert: {
  16439. names: {
  16440. blockName: REQ_CERT
  16441. }
  16442. },
  16443. extensions: {
  16444. names: {
  16445. blockName: SINGLE_REQUEST_EXTENSIONS
  16446. }
  16447. }
  16448. }
  16449. }));
  16450. AsnError.assertSchema(asn1, this.className);
  16451. this.reqCert = new CertID({ schema: asn1.result.reqCert });
  16452. if (SINGLE_REQUEST_EXTENSIONS in asn1.result) {
  16453. this.singleRequestExtensions = Array.from(asn1.result.singleRequestExtensions.valueBlock.value, element => new Extension({ schema: element }));
  16454. }
  16455. }
  16456. toSchema() {
  16457. const outputArray = [];
  16458. outputArray.push(this.reqCert.toSchema());
  16459. if (this.singleRequestExtensions) {
  16460. outputArray.push(new asn1js__namespace.Constructed({
  16461. optional: true,
  16462. idBlock: {
  16463. tagClass: 3,
  16464. tagNumber: 0
  16465. },
  16466. value: [
  16467. new asn1js__namespace.Sequence({
  16468. value: Array.from(this.singleRequestExtensions, o => o.toSchema())
  16469. })
  16470. ]
  16471. }));
  16472. }
  16473. return (new asn1js__namespace.Sequence({
  16474. value: outputArray
  16475. }));
  16476. }
  16477. toJSON() {
  16478. const res = {
  16479. reqCert: this.reqCert.toJSON()
  16480. };
  16481. if (this.singleRequestExtensions) {
  16482. res.singleRequestExtensions = Array.from(this.singleRequestExtensions, o => o.toJSON());
  16483. }
  16484. return res;
  16485. }
  16486. }
  16487. Request.CLASS_NAME = "Request";
  16488. const TBS = "tbs";
  16489. const VERSION$5 = "version";
  16490. const REQUESTOR_NAME = "requestorName";
  16491. const REQUEST_LIST = "requestList";
  16492. const REQUEST_EXTENSIONS = "requestExtensions";
  16493. const TBS_REQUEST$1 = "TBSRequest";
  16494. const TBS_REQUEST_VERSION = `${TBS_REQUEST$1}.${VERSION$5}`;
  16495. const TBS_REQUEST_REQUESTOR_NAME = `${TBS_REQUEST$1}.${REQUESTOR_NAME}`;
  16496. const TBS_REQUEST_REQUESTS = `${TBS_REQUEST$1}.requests`;
  16497. const TBS_REQUEST_REQUEST_EXTENSIONS = `${TBS_REQUEST$1}.${REQUEST_EXTENSIONS}`;
  16498. const CLEAR_PROPS$9 = [
  16499. TBS_REQUEST$1,
  16500. TBS_REQUEST_VERSION,
  16501. TBS_REQUEST_REQUESTOR_NAME,
  16502. TBS_REQUEST_REQUESTS,
  16503. TBS_REQUEST_REQUEST_EXTENSIONS
  16504. ];
  16505. class TBSRequest extends PkiObject {
  16506. get tbs() {
  16507. return pvtsutils__namespace.BufferSourceConverter.toArrayBuffer(this.tbsView);
  16508. }
  16509. set tbs(value) {
  16510. this.tbsView = new Uint8Array(value);
  16511. }
  16512. constructor(parameters = {}) {
  16513. super();
  16514. this.tbsView = new Uint8Array(pvutils__namespace.getParametersValue(parameters, TBS, TBSRequest.defaultValues(TBS)));
  16515. if (VERSION$5 in parameters) {
  16516. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$5, TBSRequest.defaultValues(VERSION$5));
  16517. }
  16518. if (REQUESTOR_NAME in parameters) {
  16519. this.requestorName = pvutils__namespace.getParametersValue(parameters, REQUESTOR_NAME, TBSRequest.defaultValues(REQUESTOR_NAME));
  16520. }
  16521. this.requestList = pvutils__namespace.getParametersValue(parameters, REQUEST_LIST, TBSRequest.defaultValues(REQUEST_LIST));
  16522. if (REQUEST_EXTENSIONS in parameters) {
  16523. this.requestExtensions = pvutils__namespace.getParametersValue(parameters, REQUEST_EXTENSIONS, TBSRequest.defaultValues(REQUEST_EXTENSIONS));
  16524. }
  16525. if (parameters.schema) {
  16526. this.fromSchema(parameters.schema);
  16527. }
  16528. }
  16529. static defaultValues(memberName) {
  16530. switch (memberName) {
  16531. case TBS:
  16532. return EMPTY_BUFFER;
  16533. case VERSION$5:
  16534. return 0;
  16535. case REQUESTOR_NAME:
  16536. return new GeneralName();
  16537. case REQUEST_LIST:
  16538. case REQUEST_EXTENSIONS:
  16539. return [];
  16540. default:
  16541. return super.defaultValues(memberName);
  16542. }
  16543. }
  16544. static compareWithDefault(memberName, memberValue) {
  16545. switch (memberName) {
  16546. case TBS:
  16547. return (memberValue.byteLength === 0);
  16548. case VERSION$5:
  16549. return (memberValue === TBSRequest.defaultValues(memberName));
  16550. case REQUESTOR_NAME:
  16551. return ((memberValue.type === GeneralName.defaultValues("type")) && (Object.keys(memberValue.value).length === 0));
  16552. case REQUEST_LIST:
  16553. case REQUEST_EXTENSIONS:
  16554. return (memberValue.length === 0);
  16555. default:
  16556. return super.defaultValues(memberName);
  16557. }
  16558. }
  16559. static schema(parameters = {}) {
  16560. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  16561. return (new asn1js__namespace.Sequence({
  16562. name: (names.blockName || TBS_REQUEST$1),
  16563. value: [
  16564. new asn1js__namespace.Constructed({
  16565. optional: true,
  16566. idBlock: {
  16567. tagClass: 3,
  16568. tagNumber: 0
  16569. },
  16570. value: [new asn1js__namespace.Integer({ name: (names.TBSRequestVersion || TBS_REQUEST_VERSION) })]
  16571. }),
  16572. new asn1js__namespace.Constructed({
  16573. optional: true,
  16574. idBlock: {
  16575. tagClass: 3,
  16576. tagNumber: 1
  16577. },
  16578. value: [GeneralName.schema(names.requestorName || {
  16579. names: {
  16580. blockName: TBS_REQUEST_REQUESTOR_NAME
  16581. }
  16582. })]
  16583. }),
  16584. new asn1js__namespace.Sequence({
  16585. name: (names.requestList || "TBSRequest.requestList"),
  16586. value: [
  16587. new asn1js__namespace.Repeated({
  16588. name: (names.requests || TBS_REQUEST_REQUESTS),
  16589. value: Request.schema(names.requestNames || {})
  16590. })
  16591. ]
  16592. }),
  16593. new asn1js__namespace.Constructed({
  16594. optional: true,
  16595. idBlock: {
  16596. tagClass: 3,
  16597. tagNumber: 2
  16598. },
  16599. value: [Extensions.schema(names.extensions || {
  16600. names: {
  16601. blockName: (names.requestExtensions || TBS_REQUEST_REQUEST_EXTENSIONS)
  16602. }
  16603. })]
  16604. })
  16605. ]
  16606. }));
  16607. }
  16608. fromSchema(schema) {
  16609. pvutils__namespace.clearProps(schema, CLEAR_PROPS$9);
  16610. const asn1 = asn1js__namespace.compareSchema(schema, schema, TBSRequest.schema());
  16611. AsnError.assertSchema(asn1, this.className);
  16612. this.tbsView = asn1.result.TBSRequest.valueBeforeDecodeView;
  16613. if (TBS_REQUEST_VERSION in asn1.result)
  16614. this.version = asn1.result[TBS_REQUEST_VERSION].valueBlock.valueDec;
  16615. if (TBS_REQUEST_REQUESTOR_NAME in asn1.result)
  16616. this.requestorName = new GeneralName({ schema: asn1.result[TBS_REQUEST_REQUESTOR_NAME] });
  16617. this.requestList = Array.from(asn1.result[TBS_REQUEST_REQUESTS], element => new Request({ schema: element }));
  16618. if (TBS_REQUEST_REQUEST_EXTENSIONS in asn1.result)
  16619. this.requestExtensions = Array.from(asn1.result[TBS_REQUEST_REQUEST_EXTENSIONS].valueBlock.value, element => new Extension({ schema: element }));
  16620. }
  16621. toSchema(encodeFlag = false) {
  16622. let tbsSchema;
  16623. if (encodeFlag === false) {
  16624. if (this.tbsView.byteLength === 0)
  16625. return TBSRequest.schema();
  16626. const asn1 = asn1js__namespace.fromBER(this.tbsView);
  16627. AsnError.assert(asn1, "TBS Request");
  16628. if (!(asn1.result instanceof asn1js__namespace.Sequence)) {
  16629. throw new Error("ASN.1 result should be SEQUENCE");
  16630. }
  16631. tbsSchema = asn1.result;
  16632. }
  16633. else {
  16634. const outputArray = [];
  16635. if (this.version !== undefined) {
  16636. outputArray.push(new asn1js__namespace.Constructed({
  16637. idBlock: {
  16638. tagClass: 3,
  16639. tagNumber: 0
  16640. },
  16641. value: [new asn1js__namespace.Integer({ value: this.version })]
  16642. }));
  16643. }
  16644. if (this.requestorName) {
  16645. outputArray.push(new asn1js__namespace.Constructed({
  16646. idBlock: {
  16647. tagClass: 3,
  16648. tagNumber: 1
  16649. },
  16650. value: [this.requestorName.toSchema()]
  16651. }));
  16652. }
  16653. outputArray.push(new asn1js__namespace.Sequence({
  16654. value: Array.from(this.requestList, o => o.toSchema())
  16655. }));
  16656. if (this.requestExtensions) {
  16657. outputArray.push(new asn1js__namespace.Constructed({
  16658. idBlock: {
  16659. tagClass: 3,
  16660. tagNumber: 2
  16661. },
  16662. value: [
  16663. new asn1js__namespace.Sequence({
  16664. value: Array.from(this.requestExtensions, o => o.toSchema())
  16665. })
  16666. ]
  16667. }));
  16668. }
  16669. tbsSchema = new asn1js__namespace.Sequence({
  16670. value: outputArray
  16671. });
  16672. }
  16673. return tbsSchema;
  16674. }
  16675. toJSON() {
  16676. const res = {};
  16677. if (this.version != undefined)
  16678. res.version = this.version;
  16679. if (this.requestorName) {
  16680. res.requestorName = this.requestorName.toJSON();
  16681. }
  16682. res.requestList = Array.from(this.requestList, o => o.toJSON());
  16683. if (this.requestExtensions) {
  16684. res.requestExtensions = Array.from(this.requestExtensions, o => o.toJSON());
  16685. }
  16686. return res;
  16687. }
  16688. }
  16689. TBSRequest.CLASS_NAME = "TBSRequest";
  16690. const SIGNATURE_ALGORITHM$1 = "signatureAlgorithm";
  16691. const SIGNATURE$1 = "signature";
  16692. const CERTS = "certs";
  16693. class Signature extends PkiObject {
  16694. constructor(parameters = {}) {
  16695. super();
  16696. this.signatureAlgorithm = pvutils__namespace.getParametersValue(parameters, SIGNATURE_ALGORITHM$1, Signature.defaultValues(SIGNATURE_ALGORITHM$1));
  16697. this.signature = pvutils__namespace.getParametersValue(parameters, SIGNATURE$1, Signature.defaultValues(SIGNATURE$1));
  16698. if (CERTS in parameters) {
  16699. this.certs = pvutils__namespace.getParametersValue(parameters, CERTS, Signature.defaultValues(CERTS));
  16700. }
  16701. if (parameters.schema) {
  16702. this.fromSchema(parameters.schema);
  16703. }
  16704. }
  16705. static defaultValues(memberName) {
  16706. switch (memberName) {
  16707. case SIGNATURE_ALGORITHM$1:
  16708. return new AlgorithmIdentifier();
  16709. case SIGNATURE$1:
  16710. return new asn1js__namespace.BitString();
  16711. case CERTS:
  16712. return [];
  16713. default:
  16714. return super.defaultValues(memberName);
  16715. }
  16716. }
  16717. static compareWithDefault(memberName, memberValue) {
  16718. switch (memberName) {
  16719. case SIGNATURE_ALGORITHM$1:
  16720. return ((memberValue.algorithmId === EMPTY_STRING) && (("algorithmParams" in memberValue) === false));
  16721. case SIGNATURE$1:
  16722. return (memberValue.isEqual(Signature.defaultValues(memberName)));
  16723. case CERTS:
  16724. return (memberValue.length === 0);
  16725. default:
  16726. return super.defaultValues(memberName);
  16727. }
  16728. }
  16729. static schema(parameters = {}) {
  16730. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  16731. return (new asn1js__namespace.Sequence({
  16732. name: (names.blockName || EMPTY_STRING),
  16733. value: [
  16734. AlgorithmIdentifier.schema(names.signatureAlgorithm || {}),
  16735. new asn1js__namespace.BitString({ name: (names.signature || EMPTY_STRING) }),
  16736. new asn1js__namespace.Constructed({
  16737. optional: true,
  16738. idBlock: {
  16739. tagClass: 3,
  16740. tagNumber: 0
  16741. },
  16742. value: [
  16743. new asn1js__namespace.Sequence({
  16744. value: [new asn1js__namespace.Repeated({
  16745. name: (names.certs || EMPTY_STRING),
  16746. value: Certificate.schema({})
  16747. })]
  16748. })
  16749. ]
  16750. })
  16751. ]
  16752. }));
  16753. }
  16754. fromSchema(schema) {
  16755. pvutils__namespace.clearProps(schema, [
  16756. SIGNATURE_ALGORITHM$1,
  16757. SIGNATURE$1,
  16758. CERTS
  16759. ]);
  16760. const asn1 = asn1js__namespace.compareSchema(schema, schema, Signature.schema({
  16761. names: {
  16762. signatureAlgorithm: {
  16763. names: {
  16764. blockName: SIGNATURE_ALGORITHM$1
  16765. }
  16766. },
  16767. signature: SIGNATURE$1,
  16768. certs: CERTS
  16769. }
  16770. }));
  16771. AsnError.assertSchema(asn1, this.className);
  16772. this.signatureAlgorithm = new AlgorithmIdentifier({ schema: asn1.result.signatureAlgorithm });
  16773. this.signature = asn1.result.signature;
  16774. if (CERTS in asn1.result)
  16775. this.certs = Array.from(asn1.result.certs, element => new Certificate({ schema: element }));
  16776. }
  16777. toSchema() {
  16778. const outputArray = [];
  16779. outputArray.push(this.signatureAlgorithm.toSchema());
  16780. outputArray.push(this.signature);
  16781. if (this.certs) {
  16782. outputArray.push(new asn1js__namespace.Constructed({
  16783. optional: true,
  16784. idBlock: {
  16785. tagClass: 3,
  16786. tagNumber: 0
  16787. },
  16788. value: [
  16789. new asn1js__namespace.Sequence({
  16790. value: Array.from(this.certs, o => o.toSchema())
  16791. })
  16792. ]
  16793. }));
  16794. }
  16795. return (new asn1js__namespace.Sequence({
  16796. value: outputArray
  16797. }));
  16798. }
  16799. toJSON() {
  16800. const res = {
  16801. signatureAlgorithm: this.signatureAlgorithm.toJSON(),
  16802. signature: this.signature.toJSON(),
  16803. };
  16804. if (this.certs) {
  16805. res.certs = Array.from(this.certs, o => o.toJSON());
  16806. }
  16807. return res;
  16808. }
  16809. }
  16810. Signature.CLASS_NAME = "Signature";
  16811. const TBS_REQUEST = "tbsRequest";
  16812. const OPTIONAL_SIGNATURE = "optionalSignature";
  16813. const CLEAR_PROPS$8 = [
  16814. TBS_REQUEST,
  16815. OPTIONAL_SIGNATURE
  16816. ];
  16817. class OCSPRequest extends PkiObject {
  16818. constructor(parameters = {}) {
  16819. super();
  16820. this.tbsRequest = pvutils__namespace.getParametersValue(parameters, TBS_REQUEST, OCSPRequest.defaultValues(TBS_REQUEST));
  16821. if (OPTIONAL_SIGNATURE in parameters) {
  16822. this.optionalSignature = pvutils__namespace.getParametersValue(parameters, OPTIONAL_SIGNATURE, OCSPRequest.defaultValues(OPTIONAL_SIGNATURE));
  16823. }
  16824. if (parameters.schema) {
  16825. this.fromSchema(parameters.schema);
  16826. }
  16827. }
  16828. static defaultValues(memberName) {
  16829. switch (memberName) {
  16830. case TBS_REQUEST:
  16831. return new TBSRequest();
  16832. case OPTIONAL_SIGNATURE:
  16833. return new Signature();
  16834. default:
  16835. return super.defaultValues(memberName);
  16836. }
  16837. }
  16838. static compareWithDefault(memberName, memberValue) {
  16839. switch (memberName) {
  16840. case TBS_REQUEST:
  16841. return ((TBSRequest.compareWithDefault("tbs", memberValue.tbs)) &&
  16842. (TBSRequest.compareWithDefault("version", memberValue.version)) &&
  16843. (TBSRequest.compareWithDefault("requestorName", memberValue.requestorName)) &&
  16844. (TBSRequest.compareWithDefault("requestList", memberValue.requestList)) &&
  16845. (TBSRequest.compareWithDefault("requestExtensions", memberValue.requestExtensions)));
  16846. case OPTIONAL_SIGNATURE:
  16847. return ((Signature.compareWithDefault("signatureAlgorithm", memberValue.signatureAlgorithm)) &&
  16848. (Signature.compareWithDefault("signature", memberValue.signature)) &&
  16849. (Signature.compareWithDefault("certs", memberValue.certs)));
  16850. default:
  16851. return super.defaultValues(memberName);
  16852. }
  16853. }
  16854. static schema(parameters = {}) {
  16855. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  16856. return (new asn1js__namespace.Sequence({
  16857. name: names.blockName || "OCSPRequest",
  16858. value: [
  16859. TBSRequest.schema(names.tbsRequest || {
  16860. names: {
  16861. blockName: TBS_REQUEST
  16862. }
  16863. }),
  16864. new asn1js__namespace.Constructed({
  16865. optional: true,
  16866. idBlock: {
  16867. tagClass: 3,
  16868. tagNumber: 0
  16869. },
  16870. value: [
  16871. Signature.schema(names.optionalSignature || {
  16872. names: {
  16873. blockName: OPTIONAL_SIGNATURE
  16874. }
  16875. })
  16876. ]
  16877. })
  16878. ]
  16879. }));
  16880. }
  16881. fromSchema(schema) {
  16882. pvutils__namespace.clearProps(schema, CLEAR_PROPS$8);
  16883. const asn1 = asn1js__namespace.compareSchema(schema, schema, OCSPRequest.schema());
  16884. AsnError.assertSchema(asn1, this.className);
  16885. this.tbsRequest = new TBSRequest({ schema: asn1.result.tbsRequest });
  16886. if (OPTIONAL_SIGNATURE in asn1.result)
  16887. this.optionalSignature = new Signature({ schema: asn1.result.optionalSignature });
  16888. }
  16889. toSchema(encodeFlag = false) {
  16890. const outputArray = [];
  16891. outputArray.push(this.tbsRequest.toSchema(encodeFlag));
  16892. if (this.optionalSignature)
  16893. outputArray.push(new asn1js__namespace.Constructed({
  16894. optional: true,
  16895. idBlock: {
  16896. tagClass: 3,
  16897. tagNumber: 0
  16898. },
  16899. value: [
  16900. this.optionalSignature.toSchema()
  16901. ]
  16902. }));
  16903. return (new asn1js__namespace.Sequence({
  16904. value: outputArray
  16905. }));
  16906. }
  16907. toJSON() {
  16908. const res = {
  16909. tbsRequest: this.tbsRequest.toJSON()
  16910. };
  16911. if (this.optionalSignature) {
  16912. res.optionalSignature = this.optionalSignature.toJSON();
  16913. }
  16914. return res;
  16915. }
  16916. async createForCertificate(certificate, parameters, crypto = getCrypto(true)) {
  16917. const certID = new CertID();
  16918. await certID.createForCertificate(certificate, parameters, crypto);
  16919. this.tbsRequest.requestList.push(new Request({
  16920. reqCert: certID,
  16921. }));
  16922. }
  16923. async sign(privateKey, hashAlgorithm = "SHA-1", crypto = getCrypto(true)) {
  16924. ParameterError.assertEmpty(privateKey, "privateKey", "OCSPRequest.sign method");
  16925. if (!this.optionalSignature) {
  16926. throw new Error("Need to create \"optionalSignature\" field before signing");
  16927. }
  16928. const signatureParams = await crypto.getSignatureParameters(privateKey, hashAlgorithm);
  16929. const parameters = signatureParams.parameters;
  16930. this.optionalSignature.signatureAlgorithm = signatureParams.signatureAlgorithm;
  16931. const tbs = this.tbsRequest.toSchema(true).toBER(false);
  16932. const signature = await crypto.signWithPrivateKey(tbs, privateKey, parameters);
  16933. this.optionalSignature.signature = new asn1js__namespace.BitString({ valueHex: signature });
  16934. }
  16935. verify() {
  16936. }
  16937. }
  16938. OCSPRequest.CLASS_NAME = "OCSPRequest";
  16939. const RESPONSE_TYPE = "responseType";
  16940. const RESPONSE = "response";
  16941. const CLEAR_PROPS$7 = [
  16942. RESPONSE_TYPE,
  16943. RESPONSE
  16944. ];
  16945. class ResponseBytes extends PkiObject {
  16946. constructor(parameters = {}) {
  16947. super();
  16948. this.responseType = pvutils__namespace.getParametersValue(parameters, RESPONSE_TYPE, ResponseBytes.defaultValues(RESPONSE_TYPE));
  16949. this.response = pvutils__namespace.getParametersValue(parameters, RESPONSE, ResponseBytes.defaultValues(RESPONSE));
  16950. if (parameters.schema) {
  16951. this.fromSchema(parameters.schema);
  16952. }
  16953. }
  16954. static defaultValues(memberName) {
  16955. switch (memberName) {
  16956. case RESPONSE_TYPE:
  16957. return EMPTY_STRING;
  16958. case RESPONSE:
  16959. return new asn1js__namespace.OctetString();
  16960. default:
  16961. return super.defaultValues(memberName);
  16962. }
  16963. }
  16964. static compareWithDefault(memberName, memberValue) {
  16965. switch (memberName) {
  16966. case RESPONSE_TYPE:
  16967. return (memberValue === EMPTY_STRING);
  16968. case RESPONSE:
  16969. return (memberValue.isEqual(ResponseBytes.defaultValues(memberName)));
  16970. default:
  16971. return super.defaultValues(memberName);
  16972. }
  16973. }
  16974. static schema(parameters = {}) {
  16975. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  16976. return (new asn1js__namespace.Sequence({
  16977. name: (names.blockName || EMPTY_STRING),
  16978. value: [
  16979. new asn1js__namespace.ObjectIdentifier({ name: (names.responseType || EMPTY_STRING) }),
  16980. new asn1js__namespace.OctetString({ name: (names.response || EMPTY_STRING) })
  16981. ]
  16982. }));
  16983. }
  16984. fromSchema(schema) {
  16985. pvutils__namespace.clearProps(schema, CLEAR_PROPS$7);
  16986. const asn1 = asn1js__namespace.compareSchema(schema, schema, ResponseBytes.schema({
  16987. names: {
  16988. responseType: RESPONSE_TYPE,
  16989. response: RESPONSE
  16990. }
  16991. }));
  16992. AsnError.assertSchema(asn1, this.className);
  16993. this.responseType = asn1.result.responseType.valueBlock.toString();
  16994. this.response = asn1.result.response;
  16995. }
  16996. toSchema() {
  16997. return (new asn1js__namespace.Sequence({
  16998. value: [
  16999. new asn1js__namespace.ObjectIdentifier({ value: this.responseType }),
  17000. this.response
  17001. ]
  17002. }));
  17003. }
  17004. toJSON() {
  17005. return {
  17006. responseType: this.responseType,
  17007. response: this.response.toJSON(),
  17008. };
  17009. }
  17010. }
  17011. ResponseBytes.CLASS_NAME = "ResponseBytes";
  17012. const RESPONSE_STATUS = "responseStatus";
  17013. const RESPONSE_BYTES = "responseBytes";
  17014. class OCSPResponse extends PkiObject {
  17015. constructor(parameters = {}) {
  17016. super();
  17017. this.responseStatus = pvutils__namespace.getParametersValue(parameters, RESPONSE_STATUS, OCSPResponse.defaultValues(RESPONSE_STATUS));
  17018. if (RESPONSE_BYTES in parameters) {
  17019. this.responseBytes = pvutils__namespace.getParametersValue(parameters, RESPONSE_BYTES, OCSPResponse.defaultValues(RESPONSE_BYTES));
  17020. }
  17021. if (parameters.schema) {
  17022. this.fromSchema(parameters.schema);
  17023. }
  17024. }
  17025. static defaultValues(memberName) {
  17026. switch (memberName) {
  17027. case RESPONSE_STATUS:
  17028. return new asn1js__namespace.Enumerated();
  17029. case RESPONSE_BYTES:
  17030. return new ResponseBytes();
  17031. default:
  17032. return super.defaultValues(memberName);
  17033. }
  17034. }
  17035. static compareWithDefault(memberName, memberValue) {
  17036. switch (memberName) {
  17037. case RESPONSE_STATUS:
  17038. return (memberValue.isEqual(OCSPResponse.defaultValues(memberName)));
  17039. case RESPONSE_BYTES:
  17040. return ((ResponseBytes.compareWithDefault("responseType", memberValue.responseType)) &&
  17041. (ResponseBytes.compareWithDefault("response", memberValue.response)));
  17042. default:
  17043. return super.defaultValues(memberName);
  17044. }
  17045. }
  17046. static schema(parameters = {}) {
  17047. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  17048. return (new asn1js__namespace.Sequence({
  17049. name: (names.blockName || "OCSPResponse"),
  17050. value: [
  17051. new asn1js__namespace.Enumerated({ name: (names.responseStatus || RESPONSE_STATUS) }),
  17052. new asn1js__namespace.Constructed({
  17053. optional: true,
  17054. idBlock: {
  17055. tagClass: 3,
  17056. tagNumber: 0
  17057. },
  17058. value: [
  17059. ResponseBytes.schema(names.responseBytes || {
  17060. names: {
  17061. blockName: RESPONSE_BYTES
  17062. }
  17063. })
  17064. ]
  17065. })
  17066. ]
  17067. }));
  17068. }
  17069. fromSchema(schema) {
  17070. pvutils__namespace.clearProps(schema, [
  17071. RESPONSE_STATUS,
  17072. RESPONSE_BYTES
  17073. ]);
  17074. const asn1 = asn1js__namespace.compareSchema(schema, schema, OCSPResponse.schema());
  17075. AsnError.assertSchema(asn1, this.className);
  17076. this.responseStatus = asn1.result.responseStatus;
  17077. if (RESPONSE_BYTES in asn1.result)
  17078. this.responseBytes = new ResponseBytes({ schema: asn1.result.responseBytes });
  17079. }
  17080. toSchema() {
  17081. const outputArray = [];
  17082. outputArray.push(this.responseStatus);
  17083. if (this.responseBytes) {
  17084. outputArray.push(new asn1js__namespace.Constructed({
  17085. idBlock: {
  17086. tagClass: 3,
  17087. tagNumber: 0
  17088. },
  17089. value: [this.responseBytes.toSchema()]
  17090. }));
  17091. }
  17092. return (new asn1js__namespace.Sequence({
  17093. value: outputArray
  17094. }));
  17095. }
  17096. toJSON() {
  17097. const res = {
  17098. responseStatus: this.responseStatus.toJSON()
  17099. };
  17100. if (this.responseBytes) {
  17101. res.responseBytes = this.responseBytes.toJSON();
  17102. }
  17103. return res;
  17104. }
  17105. async getCertificateStatus(certificate, issuerCertificate, crypto = getCrypto(true)) {
  17106. let basicResponse;
  17107. const result = {
  17108. isForCertificate: false,
  17109. status: 2
  17110. };
  17111. if (!this.responseBytes)
  17112. return result;
  17113. if (this.responseBytes.responseType !== id_PKIX_OCSP_Basic)
  17114. return result;
  17115. try {
  17116. const asn1Basic = asn1js__namespace.fromBER(this.responseBytes.response.valueBlock.valueHexView);
  17117. AsnError.assert(asn1Basic, "Basic OCSP response");
  17118. basicResponse = new BasicOCSPResponse({ schema: asn1Basic.result });
  17119. }
  17120. catch {
  17121. return result;
  17122. }
  17123. return basicResponse.getCertificateStatus(certificate, issuerCertificate, crypto);
  17124. }
  17125. async sign(privateKey, hashAlgorithm, crypto = getCrypto(true)) {
  17126. var _a;
  17127. if (this.responseBytes && this.responseBytes.responseType === id_PKIX_OCSP_Basic) {
  17128. const basicResponse = BasicOCSPResponse.fromBER(this.responseBytes.response.valueBlock.valueHexView);
  17129. return basicResponse.sign(privateKey, hashAlgorithm, crypto);
  17130. }
  17131. throw new Error(`Unknown ResponseBytes type: ${((_a = this.responseBytes) === null || _a === void 0 ? void 0 : _a.responseType) || "Unknown"}`);
  17132. }
  17133. async verify(issuerCertificate = null, crypto = getCrypto(true)) {
  17134. var _a;
  17135. if ((RESPONSE_BYTES in this) === false)
  17136. throw new Error("Empty ResponseBytes field");
  17137. if (this.responseBytes && this.responseBytes.responseType === id_PKIX_OCSP_Basic) {
  17138. const basicResponse = BasicOCSPResponse.fromBER(this.responseBytes.response.valueBlock.valueHexView);
  17139. if (issuerCertificate !== null) {
  17140. if (!basicResponse.certs) {
  17141. basicResponse.certs = [];
  17142. }
  17143. basicResponse.certs.push(issuerCertificate);
  17144. }
  17145. return basicResponse.verify({}, crypto);
  17146. }
  17147. throw new Error(`Unknown ResponseBytes type: ${((_a = this.responseBytes) === null || _a === void 0 ? void 0 : _a.responseType) || "Unknown"}`);
  17148. }
  17149. }
  17150. OCSPResponse.CLASS_NAME = "OCSPResponse";
  17151. const TYPE = "type";
  17152. const ATTRIBUTES = "attributes";
  17153. const ENCODED_VALUE = "encodedValue";
  17154. const CLEAR_PROPS$6 = [
  17155. ATTRIBUTES
  17156. ];
  17157. class SignedAndUnsignedAttributes extends PkiObject {
  17158. constructor(parameters = {}) {
  17159. super();
  17160. this.type = pvutils__namespace.getParametersValue(parameters, TYPE, SignedAndUnsignedAttributes.defaultValues(TYPE));
  17161. this.attributes = pvutils__namespace.getParametersValue(parameters, ATTRIBUTES, SignedAndUnsignedAttributes.defaultValues(ATTRIBUTES));
  17162. this.encodedValue = pvutils__namespace.getParametersValue(parameters, ENCODED_VALUE, SignedAndUnsignedAttributes.defaultValues(ENCODED_VALUE));
  17163. if (parameters.schema) {
  17164. this.fromSchema(parameters.schema);
  17165. }
  17166. }
  17167. static defaultValues(memberName) {
  17168. switch (memberName) {
  17169. case TYPE:
  17170. return (-1);
  17171. case ATTRIBUTES:
  17172. return [];
  17173. case ENCODED_VALUE:
  17174. return EMPTY_BUFFER;
  17175. default:
  17176. return super.defaultValues(memberName);
  17177. }
  17178. }
  17179. static compareWithDefault(memberName, memberValue) {
  17180. switch (memberName) {
  17181. case TYPE:
  17182. return (memberValue === SignedAndUnsignedAttributes.defaultValues(TYPE));
  17183. case ATTRIBUTES:
  17184. return (memberValue.length === 0);
  17185. case ENCODED_VALUE:
  17186. return (memberValue.byteLength === 0);
  17187. default:
  17188. return super.defaultValues(memberName);
  17189. }
  17190. }
  17191. static schema(parameters = {}) {
  17192. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  17193. return (new asn1js__namespace.Constructed({
  17194. name: (names.blockName || EMPTY_STRING),
  17195. optional: true,
  17196. idBlock: {
  17197. tagClass: 3,
  17198. tagNumber: names.tagNumber || 0
  17199. },
  17200. value: [
  17201. new asn1js__namespace.Repeated({
  17202. name: (names.attributes || EMPTY_STRING),
  17203. value: Attribute.schema()
  17204. })
  17205. ]
  17206. }));
  17207. }
  17208. fromSchema(schema) {
  17209. pvutils__namespace.clearProps(schema, CLEAR_PROPS$6);
  17210. const asn1 = asn1js__namespace.compareSchema(schema, schema, SignedAndUnsignedAttributes.schema({
  17211. names: {
  17212. tagNumber: this.type,
  17213. attributes: ATTRIBUTES
  17214. }
  17215. }));
  17216. AsnError.assertSchema(asn1, this.className);
  17217. this.type = asn1.result.idBlock.tagNumber;
  17218. this.encodedValue = pvtsutils__namespace.BufferSourceConverter.toArrayBuffer(asn1.result.valueBeforeDecodeView);
  17219. const encodedView = new Uint8Array(this.encodedValue);
  17220. encodedView[0] = 0x31;
  17221. if ((ATTRIBUTES in asn1.result) === false) {
  17222. if (this.type === 0)
  17223. throw new Error("Wrong structure of SignedUnsignedAttributes");
  17224. else
  17225. return;
  17226. }
  17227. this.attributes = Array.from(asn1.result.attributes, element => new Attribute({ schema: element }));
  17228. }
  17229. toSchema() {
  17230. if (SignedAndUnsignedAttributes.compareWithDefault(TYPE, this.type) || SignedAndUnsignedAttributes.compareWithDefault(ATTRIBUTES, this.attributes))
  17231. throw new Error("Incorrectly initialized \"SignedAndUnsignedAttributes\" class");
  17232. return (new asn1js__namespace.Constructed({
  17233. optional: true,
  17234. idBlock: {
  17235. tagClass: 3,
  17236. tagNumber: this.type
  17237. },
  17238. value: Array.from(this.attributes, o => o.toSchema())
  17239. }));
  17240. }
  17241. toJSON() {
  17242. if (SignedAndUnsignedAttributes.compareWithDefault(TYPE, this.type) || SignedAndUnsignedAttributes.compareWithDefault(ATTRIBUTES, this.attributes))
  17243. throw new Error("Incorrectly initialized \"SignedAndUnsignedAttributes\" class");
  17244. return {
  17245. type: this.type,
  17246. attributes: Array.from(this.attributes, o => o.toJSON())
  17247. };
  17248. }
  17249. }
  17250. SignedAndUnsignedAttributes.CLASS_NAME = "SignedAndUnsignedAttributes";
  17251. const VERSION$4 = "version";
  17252. const SID = "sid";
  17253. const DIGEST_ALGORITHM = "digestAlgorithm";
  17254. const SIGNED_ATTRS = "signedAttrs";
  17255. const SIGNATURE_ALGORITHM = "signatureAlgorithm";
  17256. const SIGNATURE = "signature";
  17257. const UNSIGNED_ATTRS = "unsignedAttrs";
  17258. const SIGNER_INFO = "SignerInfo";
  17259. const SIGNER_INFO_VERSION = `${SIGNER_INFO}.${VERSION$4}`;
  17260. const SIGNER_INFO_SID = `${SIGNER_INFO}.${SID}`;
  17261. const SIGNER_INFO_DIGEST_ALGORITHM = `${SIGNER_INFO}.${DIGEST_ALGORITHM}`;
  17262. const SIGNER_INFO_SIGNED_ATTRS = `${SIGNER_INFO}.${SIGNED_ATTRS}`;
  17263. const SIGNER_INFO_SIGNATURE_ALGORITHM = `${SIGNER_INFO}.${SIGNATURE_ALGORITHM}`;
  17264. const SIGNER_INFO_SIGNATURE = `${SIGNER_INFO}.${SIGNATURE}`;
  17265. const SIGNER_INFO_UNSIGNED_ATTRS = `${SIGNER_INFO}.${UNSIGNED_ATTRS}`;
  17266. const CLEAR_PROPS$5 = [
  17267. SIGNER_INFO_VERSION,
  17268. SIGNER_INFO_SID,
  17269. SIGNER_INFO_DIGEST_ALGORITHM,
  17270. SIGNER_INFO_SIGNED_ATTRS,
  17271. SIGNER_INFO_SIGNATURE_ALGORITHM,
  17272. SIGNER_INFO_SIGNATURE,
  17273. SIGNER_INFO_UNSIGNED_ATTRS
  17274. ];
  17275. class SignerInfo extends PkiObject {
  17276. constructor(parameters = {}) {
  17277. super();
  17278. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$4, SignerInfo.defaultValues(VERSION$4));
  17279. this.sid = pvutils__namespace.getParametersValue(parameters, SID, SignerInfo.defaultValues(SID));
  17280. this.digestAlgorithm = pvutils__namespace.getParametersValue(parameters, DIGEST_ALGORITHM, SignerInfo.defaultValues(DIGEST_ALGORITHM));
  17281. if (SIGNED_ATTRS in parameters) {
  17282. this.signedAttrs = pvutils__namespace.getParametersValue(parameters, SIGNED_ATTRS, SignerInfo.defaultValues(SIGNED_ATTRS));
  17283. }
  17284. this.signatureAlgorithm = pvutils__namespace.getParametersValue(parameters, SIGNATURE_ALGORITHM, SignerInfo.defaultValues(SIGNATURE_ALGORITHM));
  17285. this.signature = pvutils__namespace.getParametersValue(parameters, SIGNATURE, SignerInfo.defaultValues(SIGNATURE));
  17286. if (UNSIGNED_ATTRS in parameters) {
  17287. this.unsignedAttrs = pvutils__namespace.getParametersValue(parameters, UNSIGNED_ATTRS, SignerInfo.defaultValues(UNSIGNED_ATTRS));
  17288. }
  17289. if (parameters.schema) {
  17290. this.fromSchema(parameters.schema);
  17291. }
  17292. }
  17293. static defaultValues(memberName) {
  17294. switch (memberName) {
  17295. case VERSION$4:
  17296. return 0;
  17297. case SID:
  17298. return new asn1js__namespace.Any();
  17299. case DIGEST_ALGORITHM:
  17300. return new AlgorithmIdentifier();
  17301. case SIGNED_ATTRS:
  17302. return new SignedAndUnsignedAttributes({ type: 0 });
  17303. case SIGNATURE_ALGORITHM:
  17304. return new AlgorithmIdentifier();
  17305. case SIGNATURE:
  17306. return new asn1js__namespace.OctetString();
  17307. case UNSIGNED_ATTRS:
  17308. return new SignedAndUnsignedAttributes({ type: 1 });
  17309. default:
  17310. return super.defaultValues(memberName);
  17311. }
  17312. }
  17313. static compareWithDefault(memberName, memberValue) {
  17314. switch (memberName) {
  17315. case VERSION$4:
  17316. return (SignerInfo.defaultValues(VERSION$4) === memberValue);
  17317. case SID:
  17318. return (memberValue instanceof asn1js__namespace.Any);
  17319. case DIGEST_ALGORITHM:
  17320. if ((memberValue instanceof AlgorithmIdentifier) === false)
  17321. return false;
  17322. return memberValue.isEqual(SignerInfo.defaultValues(DIGEST_ALGORITHM));
  17323. case SIGNED_ATTRS:
  17324. return ((SignedAndUnsignedAttributes.compareWithDefault("type", memberValue.type))
  17325. && (SignedAndUnsignedAttributes.compareWithDefault("attributes", memberValue.attributes))
  17326. && (SignedAndUnsignedAttributes.compareWithDefault("encodedValue", memberValue.encodedValue)));
  17327. case SIGNATURE_ALGORITHM:
  17328. if ((memberValue instanceof AlgorithmIdentifier) === false)
  17329. return false;
  17330. return memberValue.isEqual(SignerInfo.defaultValues(SIGNATURE_ALGORITHM));
  17331. case SIGNATURE:
  17332. case UNSIGNED_ATTRS:
  17333. return ((SignedAndUnsignedAttributes.compareWithDefault("type", memberValue.type))
  17334. && (SignedAndUnsignedAttributes.compareWithDefault("attributes", memberValue.attributes))
  17335. && (SignedAndUnsignedAttributes.compareWithDefault("encodedValue", memberValue.encodedValue)));
  17336. default:
  17337. return super.defaultValues(memberName);
  17338. }
  17339. }
  17340. static schema(parameters = {}) {
  17341. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  17342. return (new asn1js__namespace.Sequence({
  17343. name: SIGNER_INFO,
  17344. value: [
  17345. new asn1js__namespace.Integer({ name: (names.version || SIGNER_INFO_VERSION) }),
  17346. new asn1js__namespace.Choice({
  17347. value: [
  17348. IssuerAndSerialNumber.schema(names.sidSchema || {
  17349. names: {
  17350. blockName: SIGNER_INFO_SID
  17351. }
  17352. }),
  17353. new asn1js__namespace.Choice({
  17354. value: [
  17355. new asn1js__namespace.Constructed({
  17356. optional: true,
  17357. name: (names.sid || SIGNER_INFO_SID),
  17358. idBlock: {
  17359. tagClass: 3,
  17360. tagNumber: 0
  17361. },
  17362. value: [new asn1js__namespace.OctetString()]
  17363. }),
  17364. new asn1js__namespace.Primitive({
  17365. optional: true,
  17366. name: (names.sid || SIGNER_INFO_SID),
  17367. idBlock: {
  17368. tagClass: 3,
  17369. tagNumber: 0
  17370. }
  17371. }),
  17372. ]
  17373. }),
  17374. ]
  17375. }),
  17376. AlgorithmIdentifier.schema(names.digestAlgorithm || {
  17377. names: {
  17378. blockName: SIGNER_INFO_DIGEST_ALGORITHM
  17379. }
  17380. }),
  17381. SignedAndUnsignedAttributes.schema(names.signedAttrs || {
  17382. names: {
  17383. blockName: SIGNER_INFO_SIGNED_ATTRS,
  17384. tagNumber: 0
  17385. }
  17386. }),
  17387. AlgorithmIdentifier.schema(names.signatureAlgorithm || {
  17388. names: {
  17389. blockName: SIGNER_INFO_SIGNATURE_ALGORITHM
  17390. }
  17391. }),
  17392. new asn1js__namespace.OctetString({ name: (names.signature || SIGNER_INFO_SIGNATURE) }),
  17393. SignedAndUnsignedAttributes.schema(names.unsignedAttrs || {
  17394. names: {
  17395. blockName: SIGNER_INFO_UNSIGNED_ATTRS,
  17396. tagNumber: 1
  17397. }
  17398. })
  17399. ]
  17400. }));
  17401. }
  17402. fromSchema(schema) {
  17403. pvutils__namespace.clearProps(schema, CLEAR_PROPS$5);
  17404. const asn1 = asn1js__namespace.compareSchema(schema, schema, SignerInfo.schema());
  17405. AsnError.assertSchema(asn1, this.className);
  17406. this.version = asn1.result[SIGNER_INFO_VERSION].valueBlock.valueDec;
  17407. const currentSid = asn1.result[SIGNER_INFO_SID];
  17408. if (currentSid.idBlock.tagClass === 1)
  17409. this.sid = new IssuerAndSerialNumber({ schema: currentSid });
  17410. else
  17411. this.sid = currentSid;
  17412. this.digestAlgorithm = new AlgorithmIdentifier({ schema: asn1.result[SIGNER_INFO_DIGEST_ALGORITHM] });
  17413. if (SIGNER_INFO_SIGNED_ATTRS in asn1.result)
  17414. this.signedAttrs = new SignedAndUnsignedAttributes({ type: 0, schema: asn1.result[SIGNER_INFO_SIGNED_ATTRS] });
  17415. this.signatureAlgorithm = new AlgorithmIdentifier({ schema: asn1.result[SIGNER_INFO_SIGNATURE_ALGORITHM] });
  17416. this.signature = asn1.result[SIGNER_INFO_SIGNATURE];
  17417. if (SIGNER_INFO_UNSIGNED_ATTRS in asn1.result)
  17418. this.unsignedAttrs = new SignedAndUnsignedAttributes({ type: 1, schema: asn1.result[SIGNER_INFO_UNSIGNED_ATTRS] });
  17419. }
  17420. toSchema() {
  17421. if (SignerInfo.compareWithDefault(SID, this.sid))
  17422. throw new Error("Incorrectly initialized \"SignerInfo\" class");
  17423. const outputArray = [];
  17424. outputArray.push(new asn1js__namespace.Integer({ value: this.version }));
  17425. if (this.sid instanceof IssuerAndSerialNumber)
  17426. outputArray.push(this.sid.toSchema());
  17427. else
  17428. outputArray.push(this.sid);
  17429. outputArray.push(this.digestAlgorithm.toSchema());
  17430. if (this.signedAttrs) {
  17431. if (SignerInfo.compareWithDefault(SIGNED_ATTRS, this.signedAttrs) === false)
  17432. outputArray.push(this.signedAttrs.toSchema());
  17433. }
  17434. outputArray.push(this.signatureAlgorithm.toSchema());
  17435. outputArray.push(this.signature);
  17436. if (this.unsignedAttrs) {
  17437. if (SignerInfo.compareWithDefault(UNSIGNED_ATTRS, this.unsignedAttrs) === false)
  17438. outputArray.push(this.unsignedAttrs.toSchema());
  17439. }
  17440. return (new asn1js__namespace.Sequence({
  17441. value: outputArray
  17442. }));
  17443. }
  17444. toJSON() {
  17445. if (SignerInfo.compareWithDefault(SID, this.sid)) {
  17446. throw new Error("Incorrectly initialized \"SignerInfo\" class");
  17447. }
  17448. const res = {
  17449. version: this.version,
  17450. digestAlgorithm: this.digestAlgorithm.toJSON(),
  17451. signatureAlgorithm: this.signatureAlgorithm.toJSON(),
  17452. signature: this.signature.toJSON(),
  17453. };
  17454. if (!(this.sid instanceof asn1js__namespace.Any))
  17455. res.sid = this.sid.toJSON();
  17456. if (this.signedAttrs && SignerInfo.compareWithDefault(SIGNED_ATTRS, this.signedAttrs) === false) {
  17457. res.signedAttrs = this.signedAttrs.toJSON();
  17458. }
  17459. if (this.unsignedAttrs && SignerInfo.compareWithDefault(UNSIGNED_ATTRS, this.unsignedAttrs) === false) {
  17460. res.unsignedAttrs = this.unsignedAttrs.toJSON();
  17461. }
  17462. return res;
  17463. }
  17464. }
  17465. SignerInfo.CLASS_NAME = "SignerInfo";
  17466. const VERSION$3 = "version";
  17467. const POLICY = "policy";
  17468. const MESSAGE_IMPRINT$1 = "messageImprint";
  17469. const SERIAL_NUMBER = "serialNumber";
  17470. const GEN_TIME = "genTime";
  17471. const ORDERING = "ordering";
  17472. const NONCE$1 = "nonce";
  17473. const ACCURACY = "accuracy";
  17474. const TSA = "tsa";
  17475. const EXTENSIONS$1 = "extensions";
  17476. const TST_INFO = "TSTInfo";
  17477. const TST_INFO_VERSION = `${TST_INFO}.${VERSION$3}`;
  17478. const TST_INFO_POLICY = `${TST_INFO}.${POLICY}`;
  17479. const TST_INFO_MESSAGE_IMPRINT = `${TST_INFO}.${MESSAGE_IMPRINT$1}`;
  17480. const TST_INFO_SERIAL_NUMBER = `${TST_INFO}.${SERIAL_NUMBER}`;
  17481. const TST_INFO_GEN_TIME = `${TST_INFO}.${GEN_TIME}`;
  17482. const TST_INFO_ACCURACY = `${TST_INFO}.${ACCURACY}`;
  17483. const TST_INFO_ORDERING = `${TST_INFO}.${ORDERING}`;
  17484. const TST_INFO_NONCE = `${TST_INFO}.${NONCE$1}`;
  17485. const TST_INFO_TSA = `${TST_INFO}.${TSA}`;
  17486. const TST_INFO_EXTENSIONS = `${TST_INFO}.${EXTENSIONS$1}`;
  17487. const CLEAR_PROPS$4 = [
  17488. TST_INFO_VERSION,
  17489. TST_INFO_POLICY,
  17490. TST_INFO_MESSAGE_IMPRINT,
  17491. TST_INFO_SERIAL_NUMBER,
  17492. TST_INFO_GEN_TIME,
  17493. TST_INFO_ACCURACY,
  17494. TST_INFO_ORDERING,
  17495. TST_INFO_NONCE,
  17496. TST_INFO_TSA,
  17497. TST_INFO_EXTENSIONS
  17498. ];
  17499. class TSTInfo extends PkiObject {
  17500. constructor(parameters = {}) {
  17501. super();
  17502. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$3, TSTInfo.defaultValues(VERSION$3));
  17503. this.policy = pvutils__namespace.getParametersValue(parameters, POLICY, TSTInfo.defaultValues(POLICY));
  17504. this.messageImprint = pvutils__namespace.getParametersValue(parameters, MESSAGE_IMPRINT$1, TSTInfo.defaultValues(MESSAGE_IMPRINT$1));
  17505. this.serialNumber = pvutils__namespace.getParametersValue(parameters, SERIAL_NUMBER, TSTInfo.defaultValues(SERIAL_NUMBER));
  17506. this.genTime = pvutils__namespace.getParametersValue(parameters, GEN_TIME, TSTInfo.defaultValues(GEN_TIME));
  17507. if (ACCURACY in parameters) {
  17508. this.accuracy = pvutils__namespace.getParametersValue(parameters, ACCURACY, TSTInfo.defaultValues(ACCURACY));
  17509. }
  17510. if (ORDERING in parameters) {
  17511. this.ordering = pvutils__namespace.getParametersValue(parameters, ORDERING, TSTInfo.defaultValues(ORDERING));
  17512. }
  17513. if (NONCE$1 in parameters) {
  17514. this.nonce = pvutils__namespace.getParametersValue(parameters, NONCE$1, TSTInfo.defaultValues(NONCE$1));
  17515. }
  17516. if (TSA in parameters) {
  17517. this.tsa = pvutils__namespace.getParametersValue(parameters, TSA, TSTInfo.defaultValues(TSA));
  17518. }
  17519. if (EXTENSIONS$1 in parameters) {
  17520. this.extensions = pvutils__namespace.getParametersValue(parameters, EXTENSIONS$1, TSTInfo.defaultValues(EXTENSIONS$1));
  17521. }
  17522. if (parameters.schema) {
  17523. this.fromSchema(parameters.schema);
  17524. }
  17525. }
  17526. static defaultValues(memberName) {
  17527. switch (memberName) {
  17528. case VERSION$3:
  17529. return 0;
  17530. case POLICY:
  17531. return EMPTY_STRING;
  17532. case MESSAGE_IMPRINT$1:
  17533. return new MessageImprint();
  17534. case SERIAL_NUMBER:
  17535. return new asn1js__namespace.Integer();
  17536. case GEN_TIME:
  17537. return new Date(0, 0, 0);
  17538. case ACCURACY:
  17539. return new Accuracy();
  17540. case ORDERING:
  17541. return false;
  17542. case NONCE$1:
  17543. return new asn1js__namespace.Integer();
  17544. case TSA:
  17545. return new GeneralName();
  17546. case EXTENSIONS$1:
  17547. return [];
  17548. default:
  17549. return super.defaultValues(memberName);
  17550. }
  17551. }
  17552. static compareWithDefault(memberName, memberValue) {
  17553. switch (memberName) {
  17554. case VERSION$3:
  17555. case POLICY:
  17556. case GEN_TIME:
  17557. case ORDERING:
  17558. return (memberValue === TSTInfo.defaultValues(ORDERING));
  17559. case MESSAGE_IMPRINT$1:
  17560. return ((MessageImprint.compareWithDefault(HASH_ALGORITHM, memberValue.hashAlgorithm)) &&
  17561. (MessageImprint.compareWithDefault(HASHED_MESSAGE, memberValue.hashedMessage)));
  17562. case SERIAL_NUMBER:
  17563. case NONCE$1:
  17564. return (memberValue.isEqual(TSTInfo.defaultValues(NONCE$1)));
  17565. case ACCURACY:
  17566. return ((Accuracy.compareWithDefault(SECONDS, memberValue.seconds)) &&
  17567. (Accuracy.compareWithDefault(MILLIS, memberValue.millis)) &&
  17568. (Accuracy.compareWithDefault(MICROS, memberValue.micros)));
  17569. case TSA:
  17570. return ((GeneralName.compareWithDefault(TYPE$4, memberValue.type)) &&
  17571. (GeneralName.compareWithDefault(VALUE$5, memberValue.value)));
  17572. case EXTENSIONS$1:
  17573. return (memberValue.length === 0);
  17574. default:
  17575. return super.defaultValues(memberName);
  17576. }
  17577. }
  17578. static schema(parameters = {}) {
  17579. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  17580. return (new asn1js__namespace.Sequence({
  17581. name: (names.blockName || TST_INFO),
  17582. value: [
  17583. new asn1js__namespace.Integer({ name: (names.version || TST_INFO_VERSION) }),
  17584. new asn1js__namespace.ObjectIdentifier({ name: (names.policy || TST_INFO_POLICY) }),
  17585. MessageImprint.schema(names.messageImprint || {
  17586. names: {
  17587. blockName: TST_INFO_MESSAGE_IMPRINT
  17588. }
  17589. }),
  17590. new asn1js__namespace.Integer({ name: (names.serialNumber || TST_INFO_SERIAL_NUMBER) }),
  17591. new asn1js__namespace.GeneralizedTime({ name: (names.genTime || TST_INFO_GEN_TIME) }),
  17592. Accuracy.schema(names.accuracy || {
  17593. names: {
  17594. blockName: TST_INFO_ACCURACY
  17595. }
  17596. }),
  17597. new asn1js__namespace.Boolean({
  17598. name: (names.ordering || TST_INFO_ORDERING),
  17599. optional: true
  17600. }),
  17601. new asn1js__namespace.Integer({
  17602. name: (names.nonce || TST_INFO_NONCE),
  17603. optional: true
  17604. }),
  17605. new asn1js__namespace.Constructed({
  17606. optional: true,
  17607. idBlock: {
  17608. tagClass: 3,
  17609. tagNumber: 0
  17610. },
  17611. value: [GeneralName.schema(names.tsa || {
  17612. names: {
  17613. blockName: TST_INFO_TSA
  17614. }
  17615. })]
  17616. }),
  17617. new asn1js__namespace.Constructed({
  17618. optional: true,
  17619. idBlock: {
  17620. tagClass: 3,
  17621. tagNumber: 1
  17622. },
  17623. value: [
  17624. new asn1js__namespace.Repeated({
  17625. name: (names.extensions || TST_INFO_EXTENSIONS),
  17626. value: Extension.schema(names.extension || {})
  17627. })
  17628. ]
  17629. })
  17630. ]
  17631. }));
  17632. }
  17633. fromSchema(schema) {
  17634. pvutils__namespace.clearProps(schema, CLEAR_PROPS$4);
  17635. const asn1 = asn1js__namespace.compareSchema(schema, schema, TSTInfo.schema());
  17636. AsnError.assertSchema(asn1, this.className);
  17637. this.version = asn1.result[TST_INFO_VERSION].valueBlock.valueDec;
  17638. this.policy = asn1.result[TST_INFO_POLICY].valueBlock.toString();
  17639. this.messageImprint = new MessageImprint({ schema: asn1.result[TST_INFO_MESSAGE_IMPRINT] });
  17640. this.serialNumber = asn1.result[TST_INFO_SERIAL_NUMBER];
  17641. this.genTime = asn1.result[TST_INFO_GEN_TIME].toDate();
  17642. if (TST_INFO_ACCURACY in asn1.result)
  17643. this.accuracy = new Accuracy({ schema: asn1.result[TST_INFO_ACCURACY] });
  17644. if (TST_INFO_ORDERING in asn1.result)
  17645. this.ordering = asn1.result[TST_INFO_ORDERING].valueBlock.value;
  17646. if (TST_INFO_NONCE in asn1.result)
  17647. this.nonce = asn1.result[TST_INFO_NONCE];
  17648. if (TST_INFO_TSA in asn1.result)
  17649. this.tsa = new GeneralName({ schema: asn1.result[TST_INFO_TSA] });
  17650. if (TST_INFO_EXTENSIONS in asn1.result)
  17651. this.extensions = Array.from(asn1.result[TST_INFO_EXTENSIONS], element => new Extension({ schema: element }));
  17652. }
  17653. toSchema() {
  17654. const outputArray = [];
  17655. outputArray.push(new asn1js__namespace.Integer({ value: this.version }));
  17656. outputArray.push(new asn1js__namespace.ObjectIdentifier({ value: this.policy }));
  17657. outputArray.push(this.messageImprint.toSchema());
  17658. outputArray.push(this.serialNumber);
  17659. outputArray.push(new asn1js__namespace.GeneralizedTime({ valueDate: this.genTime }));
  17660. if (this.accuracy)
  17661. outputArray.push(this.accuracy.toSchema());
  17662. if (this.ordering !== undefined)
  17663. outputArray.push(new asn1js__namespace.Boolean({ value: this.ordering }));
  17664. if (this.nonce)
  17665. outputArray.push(this.nonce);
  17666. if (this.tsa) {
  17667. outputArray.push(new asn1js__namespace.Constructed({
  17668. optional: true,
  17669. idBlock: {
  17670. tagClass: 3,
  17671. tagNumber: 0
  17672. },
  17673. value: [this.tsa.toSchema()]
  17674. }));
  17675. }
  17676. if (this.extensions) {
  17677. outputArray.push(new asn1js__namespace.Constructed({
  17678. optional: true,
  17679. idBlock: {
  17680. tagClass: 3,
  17681. tagNumber: 1
  17682. },
  17683. value: Array.from(this.extensions, o => o.toSchema())
  17684. }));
  17685. }
  17686. return (new asn1js__namespace.Sequence({
  17687. value: outputArray
  17688. }));
  17689. }
  17690. toJSON() {
  17691. const res = {
  17692. version: this.version,
  17693. policy: this.policy,
  17694. messageImprint: this.messageImprint.toJSON(),
  17695. serialNumber: this.serialNumber.toJSON(),
  17696. genTime: this.genTime
  17697. };
  17698. if (this.accuracy)
  17699. res.accuracy = this.accuracy.toJSON();
  17700. if (this.ordering !== undefined)
  17701. res.ordering = this.ordering;
  17702. if (this.nonce)
  17703. res.nonce = this.nonce.toJSON();
  17704. if (this.tsa)
  17705. res.tsa = this.tsa.toJSON();
  17706. if (this.extensions)
  17707. res.extensions = Array.from(this.extensions, o => o.toJSON());
  17708. return res;
  17709. }
  17710. async verify(params, crypto = getCrypto(true)) {
  17711. if (!params.data) {
  17712. throw new Error("\"data\" is a mandatory attribute for TST_INFO verification");
  17713. }
  17714. const data = params.data;
  17715. if (params.notBefore) {
  17716. if (this.genTime < params.notBefore)
  17717. throw new Error("Generation time for TSTInfo object is less than notBefore value");
  17718. }
  17719. if (params.notAfter) {
  17720. if (this.genTime > params.notAfter)
  17721. throw new Error("Generation time for TSTInfo object is more than notAfter value");
  17722. }
  17723. const shaAlgorithm = crypto.getAlgorithmByOID(this.messageImprint.hashAlgorithm.algorithmId, true, "MessageImprint.hashAlgorithm");
  17724. const hash = await crypto.digest(shaAlgorithm.name, new Uint8Array(data));
  17725. return pvtsutils__namespace.BufferSourceConverter.isEqual(hash, this.messageImprint.hashedMessage.valueBlock.valueHexView);
  17726. }
  17727. }
  17728. TSTInfo.CLASS_NAME = "TSTInfo";
  17729. const VERSION$2 = "version";
  17730. const DIGEST_ALGORITHMS = "digestAlgorithms";
  17731. const ENCAP_CONTENT_INFO = "encapContentInfo";
  17732. const CERTIFICATES = "certificates";
  17733. const CRLS = "crls";
  17734. const SIGNER_INFOS = "signerInfos";
  17735. const OCSPS = "ocsps";
  17736. const SIGNED_DATA = "SignedData";
  17737. const SIGNED_DATA_VERSION = `${SIGNED_DATA}.${VERSION$2}`;
  17738. const SIGNED_DATA_DIGEST_ALGORITHMS = `${SIGNED_DATA}.${DIGEST_ALGORITHMS}`;
  17739. const SIGNED_DATA_ENCAP_CONTENT_INFO = `${SIGNED_DATA}.${ENCAP_CONTENT_INFO}`;
  17740. const SIGNED_DATA_CERTIFICATES = `${SIGNED_DATA}.${CERTIFICATES}`;
  17741. const SIGNED_DATA_CRLS = `${SIGNED_DATA}.${CRLS}`;
  17742. const SIGNED_DATA_SIGNER_INFOS = `${SIGNED_DATA}.${SIGNER_INFOS}`;
  17743. const CLEAR_PROPS$3 = [
  17744. SIGNED_DATA_VERSION,
  17745. SIGNED_DATA_DIGEST_ALGORITHMS,
  17746. SIGNED_DATA_ENCAP_CONTENT_INFO,
  17747. SIGNED_DATA_CERTIFICATES,
  17748. SIGNED_DATA_CRLS,
  17749. SIGNED_DATA_SIGNER_INFOS
  17750. ];
  17751. class SignedDataVerifyError extends Error {
  17752. constructor({ message, code = 0, date = new Date(), signatureVerified = null, signerCertificate = null, signerCertificateVerified = null, timestampSerial = null, certificatePath = [], }) {
  17753. super(message);
  17754. this.name = "SignedDataVerifyError";
  17755. this.date = date;
  17756. this.code = code;
  17757. this.timestampSerial = timestampSerial;
  17758. this.signatureVerified = signatureVerified;
  17759. this.signerCertificate = signerCertificate;
  17760. this.signerCertificateVerified = signerCertificateVerified;
  17761. this.certificatePath = certificatePath;
  17762. }
  17763. }
  17764. class SignedData extends PkiObject {
  17765. constructor(parameters = {}) {
  17766. super();
  17767. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$2, SignedData.defaultValues(VERSION$2));
  17768. this.digestAlgorithms = pvutils__namespace.getParametersValue(parameters, DIGEST_ALGORITHMS, SignedData.defaultValues(DIGEST_ALGORITHMS));
  17769. this.encapContentInfo = pvutils__namespace.getParametersValue(parameters, ENCAP_CONTENT_INFO, SignedData.defaultValues(ENCAP_CONTENT_INFO));
  17770. if (CERTIFICATES in parameters) {
  17771. this.certificates = pvutils__namespace.getParametersValue(parameters, CERTIFICATES, SignedData.defaultValues(CERTIFICATES));
  17772. }
  17773. if (CRLS in parameters) {
  17774. this.crls = pvutils__namespace.getParametersValue(parameters, CRLS, SignedData.defaultValues(CRLS));
  17775. }
  17776. if (OCSPS in parameters) {
  17777. this.ocsps = pvutils__namespace.getParametersValue(parameters, OCSPS, SignedData.defaultValues(OCSPS));
  17778. }
  17779. this.signerInfos = pvutils__namespace.getParametersValue(parameters, SIGNER_INFOS, SignedData.defaultValues(SIGNER_INFOS));
  17780. if (parameters.schema) {
  17781. this.fromSchema(parameters.schema);
  17782. }
  17783. }
  17784. static defaultValues(memberName) {
  17785. switch (memberName) {
  17786. case VERSION$2:
  17787. return 0;
  17788. case DIGEST_ALGORITHMS:
  17789. return [];
  17790. case ENCAP_CONTENT_INFO:
  17791. return new EncapsulatedContentInfo();
  17792. case CERTIFICATES:
  17793. return [];
  17794. case CRLS:
  17795. return [];
  17796. case OCSPS:
  17797. return [];
  17798. case SIGNER_INFOS:
  17799. return [];
  17800. default:
  17801. return super.defaultValues(memberName);
  17802. }
  17803. }
  17804. static compareWithDefault(memberName, memberValue) {
  17805. switch (memberName) {
  17806. case VERSION$2:
  17807. return (memberValue === SignedData.defaultValues(VERSION$2));
  17808. case ENCAP_CONTENT_INFO:
  17809. return EncapsulatedContentInfo.compareWithDefault("eContentType", memberValue.eContentType) &&
  17810. EncapsulatedContentInfo.compareWithDefault("eContent", memberValue.eContent);
  17811. case DIGEST_ALGORITHMS:
  17812. case CERTIFICATES:
  17813. case CRLS:
  17814. case OCSPS:
  17815. case SIGNER_INFOS:
  17816. return (memberValue.length === 0);
  17817. default:
  17818. return super.defaultValues(memberName);
  17819. }
  17820. }
  17821. static schema(parameters = {}) {
  17822. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  17823. if (names.optional === undefined) {
  17824. names.optional = false;
  17825. }
  17826. return (new asn1js__namespace.Sequence({
  17827. name: (names.blockName || SIGNED_DATA),
  17828. optional: names.optional,
  17829. value: [
  17830. new asn1js__namespace.Integer({ name: (names.version || SIGNED_DATA_VERSION) }),
  17831. new asn1js__namespace.Set({
  17832. value: [
  17833. new asn1js__namespace.Repeated({
  17834. name: (names.digestAlgorithms || SIGNED_DATA_DIGEST_ALGORITHMS),
  17835. value: AlgorithmIdentifier.schema()
  17836. })
  17837. ]
  17838. }),
  17839. EncapsulatedContentInfo.schema(names.encapContentInfo || {
  17840. names: {
  17841. blockName: SIGNED_DATA_ENCAP_CONTENT_INFO
  17842. }
  17843. }),
  17844. new asn1js__namespace.Constructed({
  17845. name: (names.certificates || SIGNED_DATA_CERTIFICATES),
  17846. optional: true,
  17847. idBlock: {
  17848. tagClass: 3,
  17849. tagNumber: 0
  17850. },
  17851. value: CertificateSet.schema().valueBlock.value
  17852. }),
  17853. new asn1js__namespace.Constructed({
  17854. optional: true,
  17855. idBlock: {
  17856. tagClass: 3,
  17857. tagNumber: 1
  17858. },
  17859. value: RevocationInfoChoices.schema(names.crls || {
  17860. names: {
  17861. crls: SIGNED_DATA_CRLS
  17862. }
  17863. }).valueBlock.value
  17864. }),
  17865. new asn1js__namespace.Set({
  17866. value: [
  17867. new asn1js__namespace.Repeated({
  17868. name: (names.signerInfos || SIGNED_DATA_SIGNER_INFOS),
  17869. value: SignerInfo.schema()
  17870. })
  17871. ]
  17872. })
  17873. ]
  17874. }));
  17875. }
  17876. fromSchema(schema) {
  17877. pvutils__namespace.clearProps(schema, CLEAR_PROPS$3);
  17878. const asn1 = asn1js__namespace.compareSchema(schema, schema, SignedData.schema());
  17879. AsnError.assertSchema(asn1, this.className);
  17880. this.version = asn1.result[SIGNED_DATA_VERSION].valueBlock.valueDec;
  17881. if (SIGNED_DATA_DIGEST_ALGORITHMS in asn1.result)
  17882. this.digestAlgorithms = Array.from(asn1.result[SIGNED_DATA_DIGEST_ALGORITHMS], algorithm => new AlgorithmIdentifier({ schema: algorithm }));
  17883. this.encapContentInfo = new EncapsulatedContentInfo({ schema: asn1.result[SIGNED_DATA_ENCAP_CONTENT_INFO] });
  17884. if (SIGNED_DATA_CERTIFICATES in asn1.result) {
  17885. const certificateSet = new CertificateSet({
  17886. schema: new asn1js__namespace.Set({
  17887. value: asn1.result[SIGNED_DATA_CERTIFICATES].valueBlock.value
  17888. })
  17889. });
  17890. this.certificates = certificateSet.certificates.slice(0);
  17891. }
  17892. if (SIGNED_DATA_CRLS in asn1.result) {
  17893. this.crls = Array.from(asn1.result[SIGNED_DATA_CRLS], (crl) => {
  17894. if (crl.idBlock.tagClass === 1)
  17895. return new CertificateRevocationList({ schema: crl });
  17896. crl.idBlock.tagClass = 1;
  17897. crl.idBlock.tagNumber = 16;
  17898. return new OtherRevocationInfoFormat({ schema: crl });
  17899. });
  17900. }
  17901. if (SIGNED_DATA_SIGNER_INFOS in asn1.result)
  17902. this.signerInfos = Array.from(asn1.result[SIGNED_DATA_SIGNER_INFOS], signerInfoSchema => new SignerInfo({ schema: signerInfoSchema }));
  17903. }
  17904. toSchema(encodeFlag = false) {
  17905. const outputArray = [];
  17906. if ((this.certificates && this.certificates.length && this.certificates.some(o => o instanceof OtherCertificateFormat))
  17907. || (this.crls && this.crls.length && this.crls.some(o => o instanceof OtherRevocationInfoFormat))) {
  17908. this.version = 5;
  17909. }
  17910. else if (this.certificates && this.certificates.length && this.certificates.some(o => o instanceof AttributeCertificateV2)) {
  17911. this.version = 4;
  17912. }
  17913. else if ((this.certificates && this.certificates.length && this.certificates.some(o => o instanceof AttributeCertificateV1))
  17914. || this.signerInfos.some(o => o.version === 3)
  17915. || this.encapContentInfo.eContentType !== SignedData.ID_DATA) {
  17916. this.version = 3;
  17917. }
  17918. else {
  17919. this.version = 1;
  17920. }
  17921. outputArray.push(new asn1js__namespace.Integer({ value: this.version }));
  17922. outputArray.push(new asn1js__namespace.Set({
  17923. value: Array.from(this.digestAlgorithms, algorithm => algorithm.toSchema())
  17924. }));
  17925. outputArray.push(this.encapContentInfo.toSchema());
  17926. if (this.certificates) {
  17927. const certificateSet = new CertificateSet({ certificates: this.certificates });
  17928. const certificateSetSchema = certificateSet.toSchema();
  17929. outputArray.push(new asn1js__namespace.Constructed({
  17930. idBlock: {
  17931. tagClass: 3,
  17932. tagNumber: 0
  17933. },
  17934. value: certificateSetSchema.valueBlock.value
  17935. }));
  17936. }
  17937. if (this.crls) {
  17938. outputArray.push(new asn1js__namespace.Constructed({
  17939. idBlock: {
  17940. tagClass: 3,
  17941. tagNumber: 1
  17942. },
  17943. value: Array.from(this.crls, crl => {
  17944. if (crl instanceof OtherRevocationInfoFormat) {
  17945. const crlSchema = crl.toSchema();
  17946. crlSchema.idBlock.tagClass = 3;
  17947. crlSchema.idBlock.tagNumber = 1;
  17948. return crlSchema;
  17949. }
  17950. return crl.toSchema(encodeFlag);
  17951. })
  17952. }));
  17953. }
  17954. outputArray.push(new asn1js__namespace.Set({
  17955. value: Array.from(this.signerInfos, signerInfo => signerInfo.toSchema())
  17956. }));
  17957. return (new asn1js__namespace.Sequence({
  17958. value: outputArray
  17959. }));
  17960. }
  17961. toJSON() {
  17962. const res = {
  17963. version: this.version,
  17964. digestAlgorithms: Array.from(this.digestAlgorithms, algorithm => algorithm.toJSON()),
  17965. encapContentInfo: this.encapContentInfo.toJSON(),
  17966. signerInfos: Array.from(this.signerInfos, signerInfo => signerInfo.toJSON()),
  17967. };
  17968. if (this.certificates) {
  17969. res.certificates = Array.from(this.certificates, certificate => certificate.toJSON());
  17970. }
  17971. if (this.crls) {
  17972. res.crls = Array.from(this.crls, crl => crl.toJSON());
  17973. }
  17974. return res;
  17975. }
  17976. async verify({ signer = (-1), data = (EMPTY_BUFFER), trustedCerts = [], checkDate = (new Date()), checkChain = false, passedWhenNotRevValues = false, extendedMode = false, findOrigin = null, findIssuer = null } = {}, crypto = getCrypto(true)) {
  17977. let signerCert = null;
  17978. let timestampSerial = null;
  17979. try {
  17980. let messageDigestValue = EMPTY_BUFFER;
  17981. let shaAlgorithm = EMPTY_STRING;
  17982. let certificatePath = [];
  17983. const signerInfo = this.signerInfos[signer];
  17984. if (!signerInfo) {
  17985. throw new SignedDataVerifyError({
  17986. date: checkDate,
  17987. code: 1,
  17988. message: "Unable to get signer by supplied index",
  17989. });
  17990. }
  17991. if (!this.certificates) {
  17992. throw new SignedDataVerifyError({
  17993. date: checkDate,
  17994. code: 2,
  17995. message: "No certificates attached to this signed data",
  17996. });
  17997. }
  17998. if (signerInfo.sid instanceof IssuerAndSerialNumber) {
  17999. for (const certificate of this.certificates) {
  18000. if (!(certificate instanceof Certificate))
  18001. continue;
  18002. if ((certificate.issuer.isEqual(signerInfo.sid.issuer)) &&
  18003. (certificate.serialNumber.isEqual(signerInfo.sid.serialNumber))) {
  18004. signerCert = certificate;
  18005. break;
  18006. }
  18007. }
  18008. }
  18009. else {
  18010. const sid = signerInfo.sid;
  18011. const keyId = sid.idBlock.isConstructed
  18012. ? sid.valueBlock.value[0].valueBlock.valueHex
  18013. : sid.valueBlock.valueHex;
  18014. for (const certificate of this.certificates) {
  18015. if (!(certificate instanceof Certificate)) {
  18016. continue;
  18017. }
  18018. const digest = await crypto.digest({ name: "sha-1" }, certificate.subjectPublicKeyInfo.subjectPublicKey.valueBlock.valueHexView);
  18019. if (pvutils__namespace.isEqualBuffer(digest, keyId)) {
  18020. signerCert = certificate;
  18021. break;
  18022. }
  18023. }
  18024. }
  18025. if (!signerCert) {
  18026. throw new SignedDataVerifyError({
  18027. date: checkDate,
  18028. code: 3,
  18029. message: "Unable to find signer certificate",
  18030. });
  18031. }
  18032. if (this.encapContentInfo.eContentType === id_eContentType_TSTInfo) {
  18033. if (!this.encapContentInfo.eContent) {
  18034. throw new SignedDataVerifyError({
  18035. date: checkDate,
  18036. code: 15,
  18037. message: "Error during verification: TSTInfo eContent is empty",
  18038. signatureVerified: null,
  18039. signerCertificate: signerCert,
  18040. timestampSerial,
  18041. signerCertificateVerified: true
  18042. });
  18043. }
  18044. let tstInfo;
  18045. try {
  18046. tstInfo = TSTInfo.fromBER(this.encapContentInfo.eContent.valueBlock.valueHexView);
  18047. }
  18048. catch {
  18049. throw new SignedDataVerifyError({
  18050. date: checkDate,
  18051. code: 15,
  18052. message: "Error during verification: TSTInfo wrong ASN.1 schema ",
  18053. signatureVerified: null,
  18054. signerCertificate: signerCert,
  18055. timestampSerial,
  18056. signerCertificateVerified: true
  18057. });
  18058. }
  18059. checkDate = tstInfo.genTime;
  18060. timestampSerial = tstInfo.serialNumber.valueBlock.valueHexView.slice().buffer;
  18061. if (data.byteLength === 0) {
  18062. throw new SignedDataVerifyError({
  18063. date: checkDate,
  18064. code: 4,
  18065. message: "Missed detached data input array",
  18066. });
  18067. }
  18068. if (!(await tstInfo.verify({ data }, crypto))) {
  18069. throw new SignedDataVerifyError({
  18070. date: checkDate,
  18071. code: 15,
  18072. message: "Error during verification: TSTInfo verification is failed",
  18073. signatureVerified: false,
  18074. signerCertificate: signerCert,
  18075. timestampSerial,
  18076. signerCertificateVerified: true
  18077. });
  18078. }
  18079. }
  18080. if (checkChain) {
  18081. const certs = this.certificates.filter(certificate => (certificate instanceof Certificate && !!checkCA(certificate, signerCert)));
  18082. const chainParams = {
  18083. checkDate,
  18084. certs,
  18085. trustedCerts,
  18086. };
  18087. if (findIssuer) {
  18088. chainParams.findIssuer = findIssuer;
  18089. }
  18090. if (findOrigin) {
  18091. chainParams.findOrigin = findOrigin;
  18092. }
  18093. const chainEngine = new CertificateChainValidationEngine(chainParams);
  18094. chainEngine.certs.push(signerCert);
  18095. if (this.crls) {
  18096. for (const crl of this.crls) {
  18097. if ("thisUpdate" in crl)
  18098. chainEngine.crls.push(crl);
  18099. else {
  18100. if (crl.otherRevInfoFormat === id_PKIX_OCSP_Basic)
  18101. chainEngine.ocsps.push(new BasicOCSPResponse({ schema: crl.otherRevInfo }));
  18102. }
  18103. }
  18104. }
  18105. if (this.ocsps) {
  18106. chainEngine.ocsps.push(...(this.ocsps));
  18107. }
  18108. const verificationResult = await chainEngine.verify({ passedWhenNotRevValues }, crypto)
  18109. .catch(e => {
  18110. throw new SignedDataVerifyError({
  18111. date: checkDate,
  18112. code: 5,
  18113. message: `Validation of signer's certificate failed with error: ${((e instanceof Object) ? e.resultMessage : e)}`,
  18114. signerCertificate: signerCert,
  18115. signerCertificateVerified: false
  18116. });
  18117. });
  18118. if (verificationResult.certificatePath) {
  18119. certificatePath = verificationResult.certificatePath;
  18120. }
  18121. if (!verificationResult.result)
  18122. throw new SignedDataVerifyError({
  18123. date: checkDate,
  18124. code: 5,
  18125. message: `Validation of signer's certificate failed: ${verificationResult.resultMessage}`,
  18126. signerCertificate: signerCert,
  18127. signerCertificateVerified: false
  18128. });
  18129. }
  18130. const signerInfoHashAlgorithm = crypto.getAlgorithmByOID(signerInfo.digestAlgorithm.algorithmId);
  18131. if (!("name" in signerInfoHashAlgorithm)) {
  18132. throw new SignedDataVerifyError({
  18133. date: checkDate,
  18134. code: 7,
  18135. message: `Unsupported signature algorithm: ${signerInfo.digestAlgorithm.algorithmId}`,
  18136. signerCertificate: signerCert,
  18137. signerCertificateVerified: true
  18138. });
  18139. }
  18140. shaAlgorithm = signerInfoHashAlgorithm.name;
  18141. const eContent = this.encapContentInfo.eContent;
  18142. if (eContent) {
  18143. if ((eContent.idBlock.tagClass === 1) &&
  18144. (eContent.idBlock.tagNumber === 4)) {
  18145. data = eContent.getValue();
  18146. }
  18147. else
  18148. data = eContent.valueBlock.valueBeforeDecodeView.slice().buffer;
  18149. }
  18150. else {
  18151. if (data.byteLength === 0) {
  18152. throw new SignedDataVerifyError({
  18153. date: checkDate,
  18154. code: 8,
  18155. message: "Missed detached data input array",
  18156. signerCertificate: signerCert,
  18157. signerCertificateVerified: true
  18158. });
  18159. }
  18160. }
  18161. if (signerInfo.signedAttrs) {
  18162. let foundContentType = false;
  18163. let foundMessageDigest = false;
  18164. for (const attribute of signerInfo.signedAttrs.attributes) {
  18165. if (attribute.type === "1.2.840.113549.1.9.3")
  18166. foundContentType = true;
  18167. if (attribute.type === "1.2.840.113549.1.9.4") {
  18168. foundMessageDigest = true;
  18169. messageDigestValue = attribute.values[0].valueBlock.valueHex;
  18170. }
  18171. if (foundContentType && foundMessageDigest)
  18172. break;
  18173. }
  18174. if (foundContentType === false) {
  18175. throw new SignedDataVerifyError({
  18176. date: checkDate,
  18177. code: 9,
  18178. message: "Attribute \"content-type\" is a mandatory attribute for \"signed attributes\"",
  18179. signerCertificate: signerCert,
  18180. signerCertificateVerified: true
  18181. });
  18182. }
  18183. if (foundMessageDigest === false) {
  18184. throw new SignedDataVerifyError({
  18185. date: checkDate,
  18186. code: 10,
  18187. message: "Attribute \"message-digest\" is a mandatory attribute for \"signed attributes\"",
  18188. signatureVerified: null,
  18189. signerCertificate: signerCert,
  18190. signerCertificateVerified: true
  18191. });
  18192. }
  18193. }
  18194. if (signerInfo.signedAttrs) {
  18195. const messageDigest = await crypto.digest(shaAlgorithm, new Uint8Array(data));
  18196. if (!pvutils__namespace.isEqualBuffer(messageDigest, messageDigestValue)) {
  18197. throw new SignedDataVerifyError({
  18198. date: checkDate,
  18199. code: 15,
  18200. message: "Error during verification: Message digest doesn't match",
  18201. signatureVerified: null,
  18202. signerCertificate: signerCert,
  18203. timestampSerial,
  18204. signerCertificateVerified: true
  18205. });
  18206. }
  18207. data = signerInfo.signedAttrs.encodedValue;
  18208. }
  18209. const verifyResult = signerInfo.signatureAlgorithm.algorithmId === "1.2.840.113549.1.1.1"
  18210. ? await crypto.verifyWithPublicKey(data, signerInfo.signature, signerCert.subjectPublicKeyInfo, signerInfo.signatureAlgorithm, shaAlgorithm)
  18211. : await crypto.verifyWithPublicKey(data, signerInfo.signature, signerCert.subjectPublicKeyInfo, signerInfo.signatureAlgorithm);
  18212. if (extendedMode) {
  18213. return {
  18214. date: checkDate,
  18215. code: 14,
  18216. message: EMPTY_STRING,
  18217. signatureVerified: verifyResult,
  18218. signerCertificate: signerCert,
  18219. timestampSerial,
  18220. signerCertificateVerified: true,
  18221. certificatePath
  18222. };
  18223. }
  18224. else {
  18225. return verifyResult;
  18226. }
  18227. }
  18228. catch (e) {
  18229. if (e instanceof SignedDataVerifyError) {
  18230. throw e;
  18231. }
  18232. throw new SignedDataVerifyError({
  18233. date: checkDate,
  18234. code: 15,
  18235. message: `Error during verification: ${e instanceof Error ? e.message : e}`,
  18236. signatureVerified: null,
  18237. signerCertificate: signerCert,
  18238. timestampSerial,
  18239. signerCertificateVerified: true
  18240. });
  18241. }
  18242. }
  18243. async sign(privateKey, signerIndex, hashAlgorithm = "SHA-1", data = (EMPTY_BUFFER), crypto = getCrypto(true)) {
  18244. var _a;
  18245. if (!privateKey)
  18246. throw new Error("Need to provide a private key for signing");
  18247. const signerInfo = this.signerInfos[signerIndex];
  18248. if (!signerInfo) {
  18249. throw new RangeError("SignerInfo index is out of range");
  18250. }
  18251. if (!((_a = signerInfo.signedAttrs) === null || _a === void 0 ? void 0 : _a.attributes.length) && "hash" in privateKey.algorithm && "hash" in privateKey.algorithm && privateKey.algorithm.hash) {
  18252. hashAlgorithm = privateKey.algorithm.hash.name;
  18253. }
  18254. const hashAlgorithmOID = crypto.getOIDByAlgorithm({ name: hashAlgorithm }, true, "hashAlgorithm");
  18255. if ((this.digestAlgorithms.filter(algorithm => algorithm.algorithmId === hashAlgorithmOID)).length === 0) {
  18256. this.digestAlgorithms.push(new AlgorithmIdentifier({
  18257. algorithmId: hashAlgorithmOID,
  18258. algorithmParams: new asn1js__namespace.Null()
  18259. }));
  18260. }
  18261. signerInfo.digestAlgorithm = new AlgorithmIdentifier({
  18262. algorithmId: hashAlgorithmOID,
  18263. algorithmParams: new asn1js__namespace.Null()
  18264. });
  18265. const signatureParams = await crypto.getSignatureParameters(privateKey, hashAlgorithm);
  18266. const parameters = signatureParams.parameters;
  18267. signerInfo.signatureAlgorithm = signatureParams.signatureAlgorithm;
  18268. if (signerInfo.signedAttrs) {
  18269. if (signerInfo.signedAttrs.encodedValue.byteLength !== 0)
  18270. data = signerInfo.signedAttrs.encodedValue;
  18271. else {
  18272. data = signerInfo.signedAttrs.toSchema().toBER();
  18273. const view = pvtsutils__namespace.BufferSourceConverter.toUint8Array(data);
  18274. view[0] = 0x31;
  18275. }
  18276. }
  18277. else {
  18278. const eContent = this.encapContentInfo.eContent;
  18279. if (eContent) {
  18280. if ((eContent.idBlock.tagClass === 1) &&
  18281. (eContent.idBlock.tagNumber === 4)) {
  18282. data = eContent.getValue();
  18283. }
  18284. else
  18285. data = eContent.valueBlock.valueBeforeDecodeView.slice().buffer;
  18286. }
  18287. else {
  18288. if (data.byteLength === 0)
  18289. throw new Error("Missed detached data input array");
  18290. }
  18291. }
  18292. const signature = await crypto.signWithPrivateKey(data, privateKey, parameters);
  18293. signerInfo.signature = new asn1js__namespace.OctetString({ valueHex: signature });
  18294. }
  18295. }
  18296. SignedData.CLASS_NAME = "SignedData";
  18297. SignedData.ID_DATA = id_ContentType_Data;
  18298. const VERSION$1 = "version";
  18299. const AUTH_SAFE = "authSafe";
  18300. const MAC_DATA = "macData";
  18301. const PARSED_VALUE = "parsedValue";
  18302. const CLERA_PROPS = [
  18303. VERSION$1,
  18304. AUTH_SAFE,
  18305. MAC_DATA
  18306. ];
  18307. class PFX extends PkiObject {
  18308. constructor(parameters = {}) {
  18309. super();
  18310. this.version = pvutils__namespace.getParametersValue(parameters, VERSION$1, PFX.defaultValues(VERSION$1));
  18311. this.authSafe = pvutils__namespace.getParametersValue(parameters, AUTH_SAFE, PFX.defaultValues(AUTH_SAFE));
  18312. if (MAC_DATA in parameters) {
  18313. this.macData = pvutils__namespace.getParametersValue(parameters, MAC_DATA, PFX.defaultValues(MAC_DATA));
  18314. }
  18315. if (PARSED_VALUE in parameters) {
  18316. this.parsedValue = pvutils__namespace.getParametersValue(parameters, PARSED_VALUE, PFX.defaultValues(PARSED_VALUE));
  18317. }
  18318. if (parameters.schema) {
  18319. this.fromSchema(parameters.schema);
  18320. }
  18321. }
  18322. static defaultValues(memberName) {
  18323. switch (memberName) {
  18324. case VERSION$1:
  18325. return 3;
  18326. case AUTH_SAFE:
  18327. return (new ContentInfo());
  18328. case MAC_DATA:
  18329. return (new MacData());
  18330. case PARSED_VALUE:
  18331. return {};
  18332. default:
  18333. return super.defaultValues(memberName);
  18334. }
  18335. }
  18336. static compareWithDefault(memberName, memberValue) {
  18337. switch (memberName) {
  18338. case VERSION$1:
  18339. return (memberValue === PFX.defaultValues(memberName));
  18340. case AUTH_SAFE:
  18341. return ((ContentInfo.compareWithDefault("contentType", memberValue.contentType)) &&
  18342. (ContentInfo.compareWithDefault("content", memberValue.content)));
  18343. case MAC_DATA:
  18344. return ((MacData.compareWithDefault("mac", memberValue.mac)) &&
  18345. (MacData.compareWithDefault("macSalt", memberValue.macSalt)) &&
  18346. (MacData.compareWithDefault("iterations", memberValue.iterations)));
  18347. case PARSED_VALUE:
  18348. return ((memberValue instanceof Object) && (Object.keys(memberValue).length === 0));
  18349. default:
  18350. return super.defaultValues(memberName);
  18351. }
  18352. }
  18353. static schema(parameters = {}) {
  18354. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  18355. return (new asn1js__namespace.Sequence({
  18356. name: (names.blockName || EMPTY_STRING),
  18357. value: [
  18358. new asn1js__namespace.Integer({ name: (names.version || VERSION$1) }),
  18359. ContentInfo.schema(names.authSafe || {
  18360. names: {
  18361. blockName: AUTH_SAFE
  18362. }
  18363. }),
  18364. MacData.schema(names.macData || {
  18365. names: {
  18366. blockName: MAC_DATA,
  18367. optional: true
  18368. }
  18369. })
  18370. ]
  18371. }));
  18372. }
  18373. fromSchema(schema) {
  18374. pvutils__namespace.clearProps(schema, CLERA_PROPS);
  18375. const asn1 = asn1js__namespace.compareSchema(schema, schema, PFX.schema({
  18376. names: {
  18377. version: VERSION$1,
  18378. authSafe: {
  18379. names: {
  18380. blockName: AUTH_SAFE
  18381. }
  18382. },
  18383. macData: {
  18384. names: {
  18385. blockName: MAC_DATA
  18386. }
  18387. }
  18388. }
  18389. }));
  18390. AsnError.assertSchema(asn1, this.className);
  18391. this.version = asn1.result.version.valueBlock.valueDec;
  18392. this.authSafe = new ContentInfo({ schema: asn1.result.authSafe });
  18393. if (MAC_DATA in asn1.result)
  18394. this.macData = new MacData({ schema: asn1.result.macData });
  18395. }
  18396. toSchema() {
  18397. const outputArray = [
  18398. new asn1js__namespace.Integer({ value: this.version }),
  18399. this.authSafe.toSchema()
  18400. ];
  18401. if (this.macData) {
  18402. outputArray.push(this.macData.toSchema());
  18403. }
  18404. return (new asn1js__namespace.Sequence({
  18405. value: outputArray
  18406. }));
  18407. }
  18408. toJSON() {
  18409. const output = {
  18410. version: this.version,
  18411. authSafe: this.authSafe.toJSON()
  18412. };
  18413. if (this.macData) {
  18414. output.macData = this.macData.toJSON();
  18415. }
  18416. return output;
  18417. }
  18418. async makeInternalValues(parameters = {}, crypto = getCrypto(true)) {
  18419. ArgumentError.assert(parameters, "parameters", "object");
  18420. if (!this.parsedValue) {
  18421. throw new Error("Please call \"parseValues\" function first in order to make \"parsedValue\" data");
  18422. }
  18423. ParameterError.assertEmpty(this.parsedValue.integrityMode, "integrityMode", "parsedValue");
  18424. ParameterError.assertEmpty(this.parsedValue.authenticatedSafe, "authenticatedSafe", "parsedValue");
  18425. switch (this.parsedValue.integrityMode) {
  18426. case 0:
  18427. {
  18428. if (!("iterations" in parameters))
  18429. throw new ParameterError("iterations");
  18430. ParameterError.assertEmpty(parameters.pbkdf2HashAlgorithm, "pbkdf2HashAlgorithm");
  18431. ParameterError.assertEmpty(parameters.hmacHashAlgorithm, "hmacHashAlgorithm");
  18432. ParameterError.assertEmpty(parameters.password, "password");
  18433. const saltBuffer = new ArrayBuffer(64);
  18434. const saltView = new Uint8Array(saltBuffer);
  18435. crypto.getRandomValues(saltView);
  18436. const data = this.parsedValue.authenticatedSafe.toSchema().toBER(false);
  18437. this.authSafe = new ContentInfo({
  18438. contentType: ContentInfo.DATA,
  18439. content: new asn1js__namespace.OctetString({ valueHex: data })
  18440. });
  18441. const result = await crypto.stampDataWithPassword({
  18442. password: parameters.password,
  18443. hashAlgorithm: parameters.hmacHashAlgorithm,
  18444. salt: saltBuffer,
  18445. iterationCount: parameters.iterations,
  18446. contentToStamp: data
  18447. });
  18448. this.macData = new MacData({
  18449. mac: new DigestInfo({
  18450. digestAlgorithm: new AlgorithmIdentifier({
  18451. algorithmId: crypto.getOIDByAlgorithm({ name: parameters.hmacHashAlgorithm }, true, "hmacHashAlgorithm"),
  18452. }),
  18453. digest: new asn1js__namespace.OctetString({ valueHex: result })
  18454. }),
  18455. macSalt: new asn1js__namespace.OctetString({ valueHex: saltBuffer }),
  18456. iterations: parameters.iterations
  18457. });
  18458. }
  18459. break;
  18460. case 1:
  18461. {
  18462. if (!("signingCertificate" in parameters)) {
  18463. throw new ParameterError("signingCertificate");
  18464. }
  18465. ParameterError.assertEmpty(parameters.privateKey, "privateKey");
  18466. ParameterError.assertEmpty(parameters.hashAlgorithm, "hashAlgorithm");
  18467. const toBeSigned = this.parsedValue.authenticatedSafe.toSchema().toBER(false);
  18468. const cmsSigned = new SignedData({
  18469. version: 1,
  18470. encapContentInfo: new EncapsulatedContentInfo({
  18471. eContentType: "1.2.840.113549.1.7.1",
  18472. eContent: new asn1js__namespace.OctetString({ valueHex: toBeSigned })
  18473. }),
  18474. certificates: [parameters.signingCertificate]
  18475. });
  18476. const result = await crypto.digest({ name: parameters.hashAlgorithm }, new Uint8Array(toBeSigned));
  18477. const signedAttr = [];
  18478. signedAttr.push(new Attribute({
  18479. type: "1.2.840.113549.1.9.3",
  18480. values: [
  18481. new asn1js__namespace.ObjectIdentifier({ value: "1.2.840.113549.1.7.1" })
  18482. ]
  18483. }));
  18484. signedAttr.push(new Attribute({
  18485. type: "1.2.840.113549.1.9.5",
  18486. values: [
  18487. new asn1js__namespace.UTCTime({ valueDate: new Date() })
  18488. ]
  18489. }));
  18490. signedAttr.push(new Attribute({
  18491. type: "1.2.840.113549.1.9.4",
  18492. values: [
  18493. new asn1js__namespace.OctetString({ valueHex: result })
  18494. ]
  18495. }));
  18496. cmsSigned.signerInfos.push(new SignerInfo({
  18497. version: 1,
  18498. sid: new IssuerAndSerialNumber({
  18499. issuer: parameters.signingCertificate.issuer,
  18500. serialNumber: parameters.signingCertificate.serialNumber
  18501. }),
  18502. signedAttrs: new SignedAndUnsignedAttributes({
  18503. type: 0,
  18504. attributes: signedAttr
  18505. })
  18506. }));
  18507. await cmsSigned.sign(parameters.privateKey, 0, parameters.hashAlgorithm, undefined, crypto);
  18508. this.authSafe = new ContentInfo({
  18509. contentType: "1.2.840.113549.1.7.2",
  18510. content: cmsSigned.toSchema(true)
  18511. });
  18512. }
  18513. break;
  18514. default:
  18515. throw new Error(`Parameter "integrityMode" has unknown value: ${this.parsedValue.integrityMode}`);
  18516. }
  18517. }
  18518. async parseInternalValues(parameters, crypto = getCrypto(true)) {
  18519. ArgumentError.assert(parameters, "parameters", "object");
  18520. if (parameters.checkIntegrity === undefined) {
  18521. parameters.checkIntegrity = true;
  18522. }
  18523. this.parsedValue = {};
  18524. switch (this.authSafe.contentType) {
  18525. case ContentInfo.DATA:
  18526. {
  18527. ParameterError.assertEmpty(parameters.password, "password");
  18528. this.parsedValue.integrityMode = 0;
  18529. ArgumentError.assert(this.authSafe.content, "authSafe.content", asn1js__namespace.OctetString);
  18530. const authSafeContent = this.authSafe.content.getValue();
  18531. this.parsedValue.authenticatedSafe = AuthenticatedSafe.fromBER(authSafeContent);
  18532. if (parameters.checkIntegrity) {
  18533. if (!this.macData) {
  18534. throw new Error("Absent \"macData\" value, can not check PKCS#12 data integrity");
  18535. }
  18536. const hashAlgorithm = crypto.getAlgorithmByOID(this.macData.mac.digestAlgorithm.algorithmId, true, "digestAlgorithm");
  18537. const result = await crypto.verifyDataStampedWithPassword({
  18538. password: parameters.password,
  18539. hashAlgorithm: hashAlgorithm.name,
  18540. salt: pvtsutils.BufferSourceConverter.toArrayBuffer(this.macData.macSalt.valueBlock.valueHexView),
  18541. iterationCount: this.macData.iterations || 1,
  18542. contentToVerify: authSafeContent,
  18543. signatureToVerify: pvtsutils.BufferSourceConverter.toArrayBuffer(this.macData.mac.digest.valueBlock.valueHexView),
  18544. });
  18545. if (!result) {
  18546. throw new Error("Integrity for the PKCS#12 data is broken!");
  18547. }
  18548. }
  18549. }
  18550. break;
  18551. case ContentInfo.SIGNED_DATA:
  18552. {
  18553. this.parsedValue.integrityMode = 1;
  18554. const cmsSigned = new SignedData({ schema: this.authSafe.content });
  18555. const eContent = cmsSigned.encapContentInfo.eContent;
  18556. ParameterError.assert(eContent, "eContent", "cmsSigned.encapContentInfo");
  18557. ArgumentError.assert(eContent, "eContent", asn1js__namespace.OctetString);
  18558. const data = eContent.getValue();
  18559. this.parsedValue.authenticatedSafe = AuthenticatedSafe.fromBER(data);
  18560. const ok = await cmsSigned.verify({ signer: 0, checkChain: false }, crypto);
  18561. if (!ok) {
  18562. throw new Error("Integrity for the PKCS#12 data is broken!");
  18563. }
  18564. }
  18565. break;
  18566. default:
  18567. throw new Error(`Incorrect value for "this.authSafe.contentType": ${this.authSafe.contentType}`);
  18568. }
  18569. }
  18570. }
  18571. PFX.CLASS_NAME = "PFX";
  18572. const STATUS$1 = "status";
  18573. const STATUS_STRINGS = "statusStrings";
  18574. const FAIL_INFO = "failInfo";
  18575. const CLEAR_PROPS$2 = [
  18576. STATUS$1,
  18577. STATUS_STRINGS,
  18578. FAIL_INFO
  18579. ];
  18580. exports.PKIStatus = void 0;
  18581. (function (PKIStatus) {
  18582. PKIStatus[PKIStatus["granted"] = 0] = "granted";
  18583. PKIStatus[PKIStatus["grantedWithMods"] = 1] = "grantedWithMods";
  18584. PKIStatus[PKIStatus["rejection"] = 2] = "rejection";
  18585. PKIStatus[PKIStatus["waiting"] = 3] = "waiting";
  18586. PKIStatus[PKIStatus["revocationWarning"] = 4] = "revocationWarning";
  18587. PKIStatus[PKIStatus["revocationNotification"] = 5] = "revocationNotification";
  18588. })(exports.PKIStatus || (exports.PKIStatus = {}));
  18589. class PKIStatusInfo extends PkiObject {
  18590. constructor(parameters = {}) {
  18591. super();
  18592. this.status = pvutils__namespace.getParametersValue(parameters, STATUS$1, PKIStatusInfo.defaultValues(STATUS$1));
  18593. if (STATUS_STRINGS in parameters) {
  18594. this.statusStrings = pvutils__namespace.getParametersValue(parameters, STATUS_STRINGS, PKIStatusInfo.defaultValues(STATUS_STRINGS));
  18595. }
  18596. if (FAIL_INFO in parameters) {
  18597. this.failInfo = pvutils__namespace.getParametersValue(parameters, FAIL_INFO, PKIStatusInfo.defaultValues(FAIL_INFO));
  18598. }
  18599. if (parameters.schema) {
  18600. this.fromSchema(parameters.schema);
  18601. }
  18602. }
  18603. static defaultValues(memberName) {
  18604. switch (memberName) {
  18605. case STATUS$1:
  18606. return 2;
  18607. case STATUS_STRINGS:
  18608. return [];
  18609. case FAIL_INFO:
  18610. return new asn1js__namespace.BitString();
  18611. default:
  18612. return super.defaultValues(memberName);
  18613. }
  18614. }
  18615. static compareWithDefault(memberName, memberValue) {
  18616. switch (memberName) {
  18617. case STATUS$1:
  18618. return (memberValue === PKIStatusInfo.defaultValues(memberName));
  18619. case STATUS_STRINGS:
  18620. return (memberValue.length === 0);
  18621. case FAIL_INFO:
  18622. return (memberValue.isEqual(PKIStatusInfo.defaultValues(memberName)));
  18623. default:
  18624. return super.defaultValues(memberName);
  18625. }
  18626. }
  18627. static schema(parameters = {}) {
  18628. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  18629. return (new asn1js__namespace.Sequence({
  18630. name: (names.blockName || EMPTY_STRING),
  18631. value: [
  18632. new asn1js__namespace.Integer({ name: (names.status || EMPTY_STRING) }),
  18633. new asn1js__namespace.Sequence({
  18634. optional: true,
  18635. value: [
  18636. new asn1js__namespace.Repeated({
  18637. name: (names.statusStrings || EMPTY_STRING),
  18638. value: new asn1js__namespace.Utf8String()
  18639. })
  18640. ]
  18641. }),
  18642. new asn1js__namespace.BitString({
  18643. name: (names.failInfo || EMPTY_STRING),
  18644. optional: true
  18645. })
  18646. ]
  18647. }));
  18648. }
  18649. fromSchema(schema) {
  18650. pvutils__namespace.clearProps(schema, CLEAR_PROPS$2);
  18651. const asn1 = asn1js__namespace.compareSchema(schema, schema, PKIStatusInfo.schema({
  18652. names: {
  18653. status: STATUS$1,
  18654. statusStrings: STATUS_STRINGS,
  18655. failInfo: FAIL_INFO
  18656. }
  18657. }));
  18658. AsnError.assertSchema(asn1, this.className);
  18659. const _status = asn1.result.status;
  18660. if ((_status.valueBlock.isHexOnly === true) ||
  18661. (_status.valueBlock.valueDec < 0) ||
  18662. (_status.valueBlock.valueDec > 5))
  18663. throw new Error("PKIStatusInfo \"status\" has invalid value");
  18664. this.status = _status.valueBlock.valueDec;
  18665. if (STATUS_STRINGS in asn1.result)
  18666. this.statusStrings = asn1.result.statusStrings;
  18667. if (FAIL_INFO in asn1.result)
  18668. this.failInfo = asn1.result.failInfo;
  18669. }
  18670. toSchema() {
  18671. const outputArray = [];
  18672. outputArray.push(new asn1js__namespace.Integer({ value: this.status }));
  18673. if (this.statusStrings) {
  18674. outputArray.push(new asn1js__namespace.Sequence({
  18675. optional: true,
  18676. value: this.statusStrings
  18677. }));
  18678. }
  18679. if (this.failInfo) {
  18680. outputArray.push(this.failInfo);
  18681. }
  18682. return (new asn1js__namespace.Sequence({
  18683. value: outputArray
  18684. }));
  18685. }
  18686. toJSON() {
  18687. const res = {
  18688. status: this.status
  18689. };
  18690. if (this.statusStrings) {
  18691. res.statusStrings = Array.from(this.statusStrings, o => o.toJSON());
  18692. }
  18693. if (this.failInfo) {
  18694. res.failInfo = this.failInfo.toJSON();
  18695. }
  18696. return res;
  18697. }
  18698. }
  18699. PKIStatusInfo.CLASS_NAME = "PKIStatusInfo";
  18700. const VERSION = "version";
  18701. const MESSAGE_IMPRINT = "messageImprint";
  18702. const REQ_POLICY = "reqPolicy";
  18703. const NONCE = "nonce";
  18704. const CERT_REQ = "certReq";
  18705. const EXTENSIONS = "extensions";
  18706. const TIME_STAMP_REQ = "TimeStampReq";
  18707. const TIME_STAMP_REQ_VERSION = `${TIME_STAMP_REQ}.${VERSION}`;
  18708. const TIME_STAMP_REQ_MESSAGE_IMPRINT = `${TIME_STAMP_REQ}.${MESSAGE_IMPRINT}`;
  18709. const TIME_STAMP_REQ_POLICY = `${TIME_STAMP_REQ}.${REQ_POLICY}`;
  18710. const TIME_STAMP_REQ_NONCE = `${TIME_STAMP_REQ}.${NONCE}`;
  18711. const TIME_STAMP_REQ_CERT_REQ = `${TIME_STAMP_REQ}.${CERT_REQ}`;
  18712. const TIME_STAMP_REQ_EXTENSIONS = `${TIME_STAMP_REQ}.${EXTENSIONS}`;
  18713. const CLEAR_PROPS$1 = [
  18714. TIME_STAMP_REQ_VERSION,
  18715. TIME_STAMP_REQ_MESSAGE_IMPRINT,
  18716. TIME_STAMP_REQ_POLICY,
  18717. TIME_STAMP_REQ_NONCE,
  18718. TIME_STAMP_REQ_CERT_REQ,
  18719. TIME_STAMP_REQ_EXTENSIONS,
  18720. ];
  18721. class TimeStampReq extends PkiObject {
  18722. constructor(parameters = {}) {
  18723. super();
  18724. this.version = pvutils__namespace.getParametersValue(parameters, VERSION, TimeStampReq.defaultValues(VERSION));
  18725. this.messageImprint = pvutils__namespace.getParametersValue(parameters, MESSAGE_IMPRINT, TimeStampReq.defaultValues(MESSAGE_IMPRINT));
  18726. if (REQ_POLICY in parameters) {
  18727. this.reqPolicy = pvutils__namespace.getParametersValue(parameters, REQ_POLICY, TimeStampReq.defaultValues(REQ_POLICY));
  18728. }
  18729. if (NONCE in parameters) {
  18730. this.nonce = pvutils__namespace.getParametersValue(parameters, NONCE, TimeStampReq.defaultValues(NONCE));
  18731. }
  18732. if (CERT_REQ in parameters) {
  18733. this.certReq = pvutils__namespace.getParametersValue(parameters, CERT_REQ, TimeStampReq.defaultValues(CERT_REQ));
  18734. }
  18735. if (EXTENSIONS in parameters) {
  18736. this.extensions = pvutils__namespace.getParametersValue(parameters, EXTENSIONS, TimeStampReq.defaultValues(EXTENSIONS));
  18737. }
  18738. if (parameters.schema) {
  18739. this.fromSchema(parameters.schema);
  18740. }
  18741. }
  18742. static defaultValues(memberName) {
  18743. switch (memberName) {
  18744. case VERSION:
  18745. return 0;
  18746. case MESSAGE_IMPRINT:
  18747. return new MessageImprint();
  18748. case REQ_POLICY:
  18749. return EMPTY_STRING;
  18750. case NONCE:
  18751. return new asn1js__namespace.Integer();
  18752. case CERT_REQ:
  18753. return false;
  18754. case EXTENSIONS:
  18755. return [];
  18756. default:
  18757. return super.defaultValues(memberName);
  18758. }
  18759. }
  18760. static compareWithDefault(memberName, memberValue) {
  18761. switch (memberName) {
  18762. case VERSION:
  18763. case REQ_POLICY:
  18764. case CERT_REQ:
  18765. return (memberValue === TimeStampReq.defaultValues(memberName));
  18766. case MESSAGE_IMPRINT:
  18767. return ((MessageImprint.compareWithDefault("hashAlgorithm", memberValue.hashAlgorithm)) &&
  18768. (MessageImprint.compareWithDefault("hashedMessage", memberValue.hashedMessage)));
  18769. case NONCE:
  18770. return (memberValue.isEqual(TimeStampReq.defaultValues(memberName)));
  18771. case EXTENSIONS:
  18772. return (memberValue.length === 0);
  18773. default:
  18774. return super.defaultValues(memberName);
  18775. }
  18776. }
  18777. static schema(parameters = {}) {
  18778. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  18779. return (new asn1js__namespace.Sequence({
  18780. name: (names.blockName || TIME_STAMP_REQ),
  18781. value: [
  18782. new asn1js__namespace.Integer({ name: (names.version || TIME_STAMP_REQ_VERSION) }),
  18783. MessageImprint.schema(names.messageImprint || {
  18784. names: {
  18785. blockName: TIME_STAMP_REQ_MESSAGE_IMPRINT
  18786. }
  18787. }),
  18788. new asn1js__namespace.ObjectIdentifier({
  18789. name: (names.reqPolicy || TIME_STAMP_REQ_POLICY),
  18790. optional: true
  18791. }),
  18792. new asn1js__namespace.Integer({
  18793. name: (names.nonce || TIME_STAMP_REQ_NONCE),
  18794. optional: true
  18795. }),
  18796. new asn1js__namespace.Boolean({
  18797. name: (names.certReq || TIME_STAMP_REQ_CERT_REQ),
  18798. optional: true
  18799. }),
  18800. new asn1js__namespace.Constructed({
  18801. optional: true,
  18802. idBlock: {
  18803. tagClass: 3,
  18804. tagNumber: 0
  18805. },
  18806. value: [new asn1js__namespace.Repeated({
  18807. name: (names.extensions || TIME_STAMP_REQ_EXTENSIONS),
  18808. value: Extension.schema()
  18809. })]
  18810. })
  18811. ]
  18812. }));
  18813. }
  18814. fromSchema(schema) {
  18815. pvutils__namespace.clearProps(schema, CLEAR_PROPS$1);
  18816. const asn1 = asn1js__namespace.compareSchema(schema, schema, TimeStampReq.schema());
  18817. AsnError.assertSchema(asn1, this.className);
  18818. this.version = asn1.result[TIME_STAMP_REQ_VERSION].valueBlock.valueDec;
  18819. this.messageImprint = new MessageImprint({ schema: asn1.result[TIME_STAMP_REQ_MESSAGE_IMPRINT] });
  18820. if (TIME_STAMP_REQ_POLICY in asn1.result)
  18821. this.reqPolicy = asn1.result[TIME_STAMP_REQ_POLICY].valueBlock.toString();
  18822. if (TIME_STAMP_REQ_NONCE in asn1.result)
  18823. this.nonce = asn1.result[TIME_STAMP_REQ_NONCE];
  18824. if (TIME_STAMP_REQ_CERT_REQ in asn1.result)
  18825. this.certReq = asn1.result[TIME_STAMP_REQ_CERT_REQ].valueBlock.value;
  18826. if (TIME_STAMP_REQ_EXTENSIONS in asn1.result)
  18827. this.extensions = Array.from(asn1.result[TIME_STAMP_REQ_EXTENSIONS], element => new Extension({ schema: element }));
  18828. }
  18829. toSchema() {
  18830. const outputArray = [];
  18831. outputArray.push(new asn1js__namespace.Integer({ value: this.version }));
  18832. outputArray.push(this.messageImprint.toSchema());
  18833. if (this.reqPolicy)
  18834. outputArray.push(new asn1js__namespace.ObjectIdentifier({ value: this.reqPolicy }));
  18835. if (this.nonce)
  18836. outputArray.push(this.nonce);
  18837. if ((CERT_REQ in this) && (TimeStampReq.compareWithDefault(CERT_REQ, this.certReq) === false))
  18838. outputArray.push(new asn1js__namespace.Boolean({ value: this.certReq }));
  18839. if (this.extensions) {
  18840. outputArray.push(new asn1js__namespace.Constructed({
  18841. idBlock: {
  18842. tagClass: 3,
  18843. tagNumber: 0
  18844. },
  18845. value: Array.from(this.extensions, o => o.toSchema())
  18846. }));
  18847. }
  18848. return (new asn1js__namespace.Sequence({
  18849. value: outputArray
  18850. }));
  18851. }
  18852. toJSON() {
  18853. const res = {
  18854. version: this.version,
  18855. messageImprint: this.messageImprint.toJSON()
  18856. };
  18857. if (this.reqPolicy !== undefined)
  18858. res.reqPolicy = this.reqPolicy;
  18859. if (this.nonce !== undefined)
  18860. res.nonce = this.nonce.toJSON();
  18861. if ((this.certReq !== undefined) && (TimeStampReq.compareWithDefault(CERT_REQ, this.certReq) === false))
  18862. res.certReq = this.certReq;
  18863. if (this.extensions) {
  18864. res.extensions = Array.from(this.extensions, o => o.toJSON());
  18865. }
  18866. return res;
  18867. }
  18868. }
  18869. TimeStampReq.CLASS_NAME = "TimeStampReq";
  18870. const STATUS = "status";
  18871. const TIME_STAMP_TOKEN = "timeStampToken";
  18872. const TIME_STAMP_RESP = "TimeStampResp";
  18873. const TIME_STAMP_RESP_STATUS = `${TIME_STAMP_RESP}.${STATUS}`;
  18874. const TIME_STAMP_RESP_TOKEN = `${TIME_STAMP_RESP}.${TIME_STAMP_TOKEN}`;
  18875. const CLEAR_PROPS = [
  18876. TIME_STAMP_RESP_STATUS,
  18877. TIME_STAMP_RESP_TOKEN
  18878. ];
  18879. class TimeStampResp extends PkiObject {
  18880. constructor(parameters = {}) {
  18881. super();
  18882. this.status = pvutils__namespace.getParametersValue(parameters, STATUS, TimeStampResp.defaultValues(STATUS));
  18883. if (TIME_STAMP_TOKEN in parameters) {
  18884. this.timeStampToken = pvutils__namespace.getParametersValue(parameters, TIME_STAMP_TOKEN, TimeStampResp.defaultValues(TIME_STAMP_TOKEN));
  18885. }
  18886. if (parameters.schema) {
  18887. this.fromSchema(parameters.schema);
  18888. }
  18889. }
  18890. static defaultValues(memberName) {
  18891. switch (memberName) {
  18892. case STATUS:
  18893. return new PKIStatusInfo();
  18894. case TIME_STAMP_TOKEN:
  18895. return new ContentInfo();
  18896. default:
  18897. return super.defaultValues(memberName);
  18898. }
  18899. }
  18900. static compareWithDefault(memberName, memberValue) {
  18901. switch (memberName) {
  18902. case STATUS:
  18903. return ((PKIStatusInfo.compareWithDefault(STATUS, memberValue.status)) &&
  18904. (("statusStrings" in memberValue) === false) &&
  18905. (("failInfo" in memberValue) === false));
  18906. case TIME_STAMP_TOKEN:
  18907. return ((memberValue.contentType === EMPTY_STRING) &&
  18908. (memberValue.content instanceof asn1js__namespace.Any));
  18909. default:
  18910. return super.defaultValues(memberName);
  18911. }
  18912. }
  18913. static schema(parameters = {}) {
  18914. const names = pvutils__namespace.getParametersValue(parameters, "names", {});
  18915. return (new asn1js__namespace.Sequence({
  18916. name: (names.blockName || TIME_STAMP_RESP),
  18917. value: [
  18918. PKIStatusInfo.schema(names.status || {
  18919. names: {
  18920. blockName: TIME_STAMP_RESP_STATUS
  18921. }
  18922. }),
  18923. ContentInfo.schema(names.timeStampToken || {
  18924. names: {
  18925. blockName: TIME_STAMP_RESP_TOKEN,
  18926. optional: true
  18927. }
  18928. })
  18929. ]
  18930. }));
  18931. }
  18932. fromSchema(schema) {
  18933. pvutils__namespace.clearProps(schema, CLEAR_PROPS);
  18934. const asn1 = asn1js__namespace.compareSchema(schema, schema, TimeStampResp.schema());
  18935. AsnError.assertSchema(asn1, this.className);
  18936. this.status = new PKIStatusInfo({ schema: asn1.result[TIME_STAMP_RESP_STATUS] });
  18937. if (TIME_STAMP_RESP_TOKEN in asn1.result)
  18938. this.timeStampToken = new ContentInfo({ schema: asn1.result[TIME_STAMP_RESP_TOKEN] });
  18939. }
  18940. toSchema() {
  18941. const outputArray = [];
  18942. outputArray.push(this.status.toSchema());
  18943. if (this.timeStampToken) {
  18944. outputArray.push(this.timeStampToken.toSchema());
  18945. }
  18946. return (new asn1js__namespace.Sequence({
  18947. value: outputArray
  18948. }));
  18949. }
  18950. toJSON() {
  18951. const res = {
  18952. status: this.status.toJSON()
  18953. };
  18954. if (this.timeStampToken) {
  18955. res.timeStampToken = this.timeStampToken.toJSON();
  18956. }
  18957. return res;
  18958. }
  18959. async sign(privateKey, hashAlgorithm, crypto = getCrypto(true)) {
  18960. this.assertContentType();
  18961. const signed = new SignedData({ schema: this.timeStampToken.content });
  18962. return signed.sign(privateKey, 0, hashAlgorithm, undefined, crypto);
  18963. }
  18964. async verify(verificationParameters = { signer: 0, trustedCerts: [], data: EMPTY_BUFFER }, crypto = getCrypto(true)) {
  18965. this.assertContentType();
  18966. const signed = new SignedData({ schema: this.timeStampToken.content });
  18967. return signed.verify(verificationParameters, crypto);
  18968. }
  18969. assertContentType() {
  18970. if (!this.timeStampToken) {
  18971. throw new Error("timeStampToken is absent in TSP response");
  18972. }
  18973. if (this.timeStampToken.contentType !== id_ContentType_SignedData) {
  18974. throw new Error(`Wrong format of timeStampToken: ${this.timeStampToken.contentType}`);
  18975. }
  18976. }
  18977. }
  18978. TimeStampResp.CLASS_NAME = "TimeStampResp";
  18979. function initCryptoEngine() {
  18980. if (typeof globalThis !== "undefined" && "crypto" in globalThis) {
  18981. let engineName = "webcrypto";
  18982. if ("webkitSubtle" in globalThis.crypto) {
  18983. engineName = "safari";
  18984. }
  18985. setEngine(engineName, new CryptoEngine({ name: engineName, crypto: globalThis.crypto }));
  18986. }
  18987. else if (typeof crypto !== "undefined" && "webcrypto" in crypto) {
  18988. const name = "NodeJS ^15";
  18989. const nodeCrypto = crypto.webcrypto;
  18990. setEngine(name, new CryptoEngine({ name, crypto: nodeCrypto }));
  18991. }
  18992. }
  18993. initCryptoEngine();
  18994. exports.AbstractCryptoEngine = AbstractCryptoEngine;
  18995. exports.AccessDescription = AccessDescription;
  18996. exports.Accuracy = Accuracy;
  18997. exports.AlgorithmIdentifier = AlgorithmIdentifier;
  18998. exports.AltName = AltName;
  18999. exports.ArgumentError = ArgumentError;
  19000. exports.AsnError = AsnError;
  19001. exports.AttCertValidityPeriod = AttCertValidityPeriod;
  19002. exports.Attribute = Attribute;
  19003. exports.AttributeCertificateInfoV1 = AttributeCertificateInfoV1;
  19004. exports.AttributeCertificateInfoV2 = AttributeCertificateInfoV2;
  19005. exports.AttributeCertificateV1 = AttributeCertificateV1;
  19006. exports.AttributeCertificateV2 = AttributeCertificateV2;
  19007. exports.AttributeTypeAndValue = AttributeTypeAndValue;
  19008. exports.AuthenticatedSafe = AuthenticatedSafe;
  19009. exports.AuthorityKeyIdentifier = AuthorityKeyIdentifier;
  19010. exports.BasicConstraints = BasicConstraints;
  19011. exports.BasicOCSPResponse = BasicOCSPResponse;
  19012. exports.CAVersion = CAVersion;
  19013. exports.CRLBag = CRLBag;
  19014. exports.CRLDistributionPoints = CRLDistributionPoints;
  19015. exports.CertBag = CertBag;
  19016. exports.CertID = CertID;
  19017. exports.Certificate = Certificate;
  19018. exports.CertificateChainValidationEngine = CertificateChainValidationEngine;
  19019. exports.CertificatePolicies = CertificatePolicies;
  19020. exports.CertificateRevocationList = CertificateRevocationList;
  19021. exports.CertificateSet = CertificateSet;
  19022. exports.CertificateTemplate = CertificateTemplate;
  19023. exports.CertificationRequest = CertificationRequest;
  19024. exports.ChainValidationError = ChainValidationError;
  19025. exports.ContentInfo = ContentInfo;
  19026. exports.CryptoEngine = CryptoEngine;
  19027. exports.DigestInfo = DigestInfo;
  19028. exports.DistributionPoint = DistributionPoint;
  19029. exports.ECCCMSSharedInfo = ECCCMSSharedInfo;
  19030. exports.ECNamedCurves = ECNamedCurves;
  19031. exports.ECPrivateKey = ECPrivateKey;
  19032. exports.ECPublicKey = ECPublicKey;
  19033. exports.EncapsulatedContentInfo = EncapsulatedContentInfo;
  19034. exports.EncryptedContentInfo = EncryptedContentInfo;
  19035. exports.EncryptedData = EncryptedData;
  19036. exports.EnvelopedData = EnvelopedData;
  19037. exports.ExtKeyUsage = ExtKeyUsage;
  19038. exports.Extension = Extension;
  19039. exports.ExtensionValueFactory = ExtensionValueFactory;
  19040. exports.Extensions = Extensions;
  19041. exports.GeneralName = GeneralName;
  19042. exports.GeneralNames = GeneralNames;
  19043. exports.GeneralSubtree = GeneralSubtree;
  19044. exports.HASHED_MESSAGE = HASHED_MESSAGE;
  19045. exports.HASH_ALGORITHM = HASH_ALGORITHM;
  19046. exports.Holder = Holder;
  19047. exports.InfoAccess = InfoAccess;
  19048. exports.IssuerAndSerialNumber = IssuerAndSerialNumber;
  19049. exports.IssuerSerial = IssuerSerial;
  19050. exports.IssuingDistributionPoint = IssuingDistributionPoint;
  19051. exports.KEKIdentifier = KEKIdentifier;
  19052. exports.KEKRecipientInfo = KEKRecipientInfo;
  19053. exports.KeyAgreeRecipientIdentifier = KeyAgreeRecipientIdentifier;
  19054. exports.KeyAgreeRecipientInfo = KeyAgreeRecipientInfo;
  19055. exports.KeyBag = KeyBag;
  19056. exports.KeyTransRecipientInfo = KeyTransRecipientInfo;
  19057. exports.MICROS = MICROS;
  19058. exports.MILLIS = MILLIS;
  19059. exports.MacData = MacData;
  19060. exports.MessageImprint = MessageImprint;
  19061. exports.NameConstraints = NameConstraints;
  19062. exports.OCSPRequest = OCSPRequest;
  19063. exports.OCSPResponse = OCSPResponse;
  19064. exports.ObjectDigestInfo = ObjectDigestInfo;
  19065. exports.OriginatorIdentifierOrKey = OriginatorIdentifierOrKey;
  19066. exports.OriginatorInfo = OriginatorInfo;
  19067. exports.OriginatorPublicKey = OriginatorPublicKey;
  19068. exports.OtherCertificateFormat = OtherCertificateFormat;
  19069. exports.OtherKeyAttribute = OtherKeyAttribute;
  19070. exports.OtherPrimeInfo = OtherPrimeInfo;
  19071. exports.OtherRecipientInfo = OtherRecipientInfo;
  19072. exports.OtherRevocationInfoFormat = OtherRevocationInfoFormat;
  19073. exports.PBES2Params = PBES2Params;
  19074. exports.PBKDF2Params = PBKDF2Params;
  19075. exports.PFX = PFX;
  19076. exports.PKCS8ShroudedKeyBag = PKCS8ShroudedKeyBag;
  19077. exports.PKIStatusInfo = PKIStatusInfo;
  19078. exports.POLICY_IDENTIFIER = POLICY_IDENTIFIER;
  19079. exports.POLICY_QUALIFIERS = POLICY_QUALIFIERS;
  19080. exports.ParameterError = ParameterError;
  19081. exports.PasswordRecipientinfo = PasswordRecipientinfo;
  19082. exports.PkiObject = PkiObject;
  19083. exports.PolicyConstraints = PolicyConstraints;
  19084. exports.PolicyInformation = PolicyInformation;
  19085. exports.PolicyMapping = PolicyMapping;
  19086. exports.PolicyMappings = PolicyMappings;
  19087. exports.PolicyQualifierInfo = PolicyQualifierInfo;
  19088. exports.PrivateKeyInfo = PrivateKeyInfo;
  19089. exports.PrivateKeyUsagePeriod = PrivateKeyUsagePeriod;
  19090. exports.PublicKeyInfo = PublicKeyInfo;
  19091. exports.QCStatement = QCStatement;
  19092. exports.QCStatements = QCStatements;
  19093. exports.RDN = RDN;
  19094. exports.RSAESOAEPParams = RSAESOAEPParams;
  19095. exports.RSAPrivateKey = RSAPrivateKey;
  19096. exports.RSAPublicKey = RSAPublicKey;
  19097. exports.RSASSAPSSParams = RSASSAPSSParams;
  19098. exports.RecipientEncryptedKey = RecipientEncryptedKey;
  19099. exports.RecipientEncryptedKeys = RecipientEncryptedKeys;
  19100. exports.RecipientIdentifier = RecipientIdentifier;
  19101. exports.RecipientInfo = RecipientInfo;
  19102. exports.RecipientKeyIdentifier = RecipientKeyIdentifier;
  19103. exports.RelativeDistinguishedNames = RelativeDistinguishedNames;
  19104. exports.Request = Request;
  19105. exports.ResponseBytes = ResponseBytes;
  19106. exports.ResponseData = ResponseData;
  19107. exports.RevocationInfoChoices = RevocationInfoChoices;
  19108. exports.RevokedCertificate = RevokedCertificate;
  19109. exports.SECONDS = SECONDS;
  19110. exports.SafeBag = SafeBag;
  19111. exports.SafeBagValueFactory = SafeBagValueFactory;
  19112. exports.SafeContents = SafeContents;
  19113. exports.SecretBag = SecretBag;
  19114. exports.Signature = Signature;
  19115. exports.SignedAndUnsignedAttributes = SignedAndUnsignedAttributes;
  19116. exports.SignedCertificateTimestamp = SignedCertificateTimestamp;
  19117. exports.SignedCertificateTimestampList = SignedCertificateTimestampList;
  19118. exports.SignedData = SignedData;
  19119. exports.SignedDataVerifyError = SignedDataVerifyError;
  19120. exports.SignerInfo = SignerInfo;
  19121. exports.SingleResponse = SingleResponse;
  19122. exports.SubjectDirectoryAttributes = SubjectDirectoryAttributes;
  19123. exports.TBSRequest = TBSRequest;
  19124. exports.TSTInfo = TSTInfo;
  19125. exports.TYPE = TYPE$4;
  19126. exports.TYPE_AND_VALUES = TYPE_AND_VALUES;
  19127. exports.Time = Time;
  19128. exports.TimeStampReq = TimeStampReq;
  19129. exports.TimeStampResp = TimeStampResp;
  19130. exports.V2Form = V2Form;
  19131. exports.VALUE = VALUE$5;
  19132. exports.VALUE_BEFORE_DECODE = VALUE_BEFORE_DECODE;
  19133. exports.checkCA = checkCA;
  19134. exports.createCMSECDSASignature = createCMSECDSASignature;
  19135. exports.createECDSASignatureFromCMS = createECDSASignatureFromCMS;
  19136. exports.getAlgorithmByOID = getAlgorithmByOID;
  19137. exports.getAlgorithmParameters = getAlgorithmParameters;
  19138. exports.getCrypto = getCrypto;
  19139. exports.getEngine = getEngine;
  19140. exports.getHashAlgorithm = getHashAlgorithm;
  19141. exports.getOIDByAlgorithm = getOIDByAlgorithm;
  19142. exports.getRandomValues = getRandomValues;
  19143. exports.id_AnyPolicy = id_AnyPolicy;
  19144. exports.id_AuthorityInfoAccess = id_AuthorityInfoAccess;
  19145. exports.id_AuthorityKeyIdentifier = id_AuthorityKeyIdentifier;
  19146. exports.id_BaseCRLNumber = id_BaseCRLNumber;
  19147. exports.id_BasicConstraints = id_BasicConstraints;
  19148. exports.id_CRLBag_X509CRL = id_CRLBag_X509CRL;
  19149. exports.id_CRLDistributionPoints = id_CRLDistributionPoints;
  19150. exports.id_CRLNumber = id_CRLNumber;
  19151. exports.id_CRLReason = id_CRLReason;
  19152. exports.id_CertBag_AttributeCertificate = id_CertBag_AttributeCertificate;
  19153. exports.id_CertBag_SDSICertificate = id_CertBag_SDSICertificate;
  19154. exports.id_CertBag_X509Certificate = id_CertBag_X509Certificate;
  19155. exports.id_CertificateIssuer = id_CertificateIssuer;
  19156. exports.id_CertificatePolicies = id_CertificatePolicies;
  19157. exports.id_ContentType_Data = id_ContentType_Data;
  19158. exports.id_ContentType_EncryptedData = id_ContentType_EncryptedData;
  19159. exports.id_ContentType_EnvelopedData = id_ContentType_EnvelopedData;
  19160. exports.id_ContentType_SignedData = id_ContentType_SignedData;
  19161. exports.id_ExtKeyUsage = id_ExtKeyUsage;
  19162. exports.id_FreshestCRL = id_FreshestCRL;
  19163. exports.id_InhibitAnyPolicy = id_InhibitAnyPolicy;
  19164. exports.id_InvalidityDate = id_InvalidityDate;
  19165. exports.id_IssuerAltName = id_IssuerAltName;
  19166. exports.id_IssuingDistributionPoint = id_IssuingDistributionPoint;
  19167. exports.id_KeyUsage = id_KeyUsage;
  19168. exports.id_MicrosoftAppPolicies = id_MicrosoftAppPolicies;
  19169. exports.id_MicrosoftCaVersion = id_MicrosoftCaVersion;
  19170. exports.id_MicrosoftCertTemplateV1 = id_MicrosoftCertTemplateV1;
  19171. exports.id_MicrosoftCertTemplateV2 = id_MicrosoftCertTemplateV2;
  19172. exports.id_MicrosoftPrevCaCertHash = id_MicrosoftPrevCaCertHash;
  19173. exports.id_NameConstraints = id_NameConstraints;
  19174. exports.id_PKIX_OCSP_Basic = id_PKIX_OCSP_Basic;
  19175. exports.id_PolicyConstraints = id_PolicyConstraints;
  19176. exports.id_PolicyMappings = id_PolicyMappings;
  19177. exports.id_PrivateKeyUsagePeriod = id_PrivateKeyUsagePeriod;
  19178. exports.id_QCStatements = id_QCStatements;
  19179. exports.id_SignedCertificateTimestampList = id_SignedCertificateTimestampList;
  19180. exports.id_SubjectAltName = id_SubjectAltName;
  19181. exports.id_SubjectDirectoryAttributes = id_SubjectDirectoryAttributes;
  19182. exports.id_SubjectInfoAccess = id_SubjectInfoAccess;
  19183. exports.id_SubjectKeyIdentifier = id_SubjectKeyIdentifier;
  19184. exports.id_ad = id_ad;
  19185. exports.id_ad_caIssuers = id_ad_caIssuers;
  19186. exports.id_ad_ocsp = id_ad_ocsp;
  19187. exports.id_eContentType_TSTInfo = id_eContentType_TSTInfo;
  19188. exports.id_pkix = id_pkix;
  19189. exports.id_sha1 = id_sha1;
  19190. exports.id_sha256 = id_sha256;
  19191. exports.id_sha384 = id_sha384;
  19192. exports.id_sha512 = id_sha512;
  19193. exports.kdf = kdf;
  19194. exports.setEngine = setEngine;
  19195. exports.stringPrep = stringPrep;
  19196. exports.verifySCTsForCertificate = verifySCTsForCertificate;