fernetBrowser.js 280 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868
  1. (function(e){if("function"==typeof bootstrap)bootstrap("fernet",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeFernet=e}else"undefined"!=typeof window?window.fernet=e():global.fernet=e()})(function(){var define,ses,bootstrap,module,exports;
  2. return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  3. var Buffer=require("__browserify_Buffer").Buffer;var CryptoJS = require('crypto-js/core');
  4. var AES = require('crypto-js/aes');
  5. var Utf8 = require('crypto-js/enc-utf8');
  6. var Latin1 = require('crypto-js/enc-latin1');
  7. var Hex = require('crypto-js/enc-hex');
  8. var Base64 = require('crypto-js/enc-base64');
  9. var HmacSHA256 = require('crypto-js/hmac-sha256');
  10. var URLBase64 = require('urlsafe-base64');
  11. var crypto = require('crypto');
  12. //lpad a string for some hex conversions
  13. String.prototype.lpad = function (padString, length) {
  14. var str = this;
  15. while (str.length < length) str = padString + str;
  16. return str;
  17. }
  18. //Makes a Base64 string a url-safe base64 string
  19. var urlsafe = function urlsafe(string) {
  20. return string.replace(/\+/g, '-').replace(/\//g, '_') //.replace(/=+$/, '')
  21. }
  22. // parse a Hex string to an Int
  23. var parseHex = function parseHex(hexString) {
  24. return parseInt('0x' + hexString);
  25. }
  26. // turn bits into number of chars in a hex string
  27. var hexBits = function hexBits(bits) {
  28. return bits / 8 * 2;
  29. }
  30. // convert base64 string to hex string
  31. var decode64toHex = function decode64(string) {
  32. var s = URLBase64.decode(string.replace(/=+$/, ''));
  33. return (new Buffer(s)).toString('hex');
  34. }
  35. // convert array to hex string
  36. var ArrayToHex = function ArrayToHex(array) {
  37. var hex = '';
  38. for (var _byte in array) {
  39. hex += Number(_byte).toString(16).lpad('0', 2);
  40. }
  41. return hex;
  42. }
  43. var randomHex = function (size) {
  44. return crypto.randomBytes(128 / 8).toString('hex')
  45. }
  46. var setIV = function setIV(iv_array) {
  47. if (iv_array) {
  48. this.ivHex = ArrayToHex(iv_array);
  49. } else {
  50. this.ivHex = randomHex(128 / 8);
  51. }
  52. this.iv = Hex.parse(this.ivHex);
  53. return this.ivHex;
  54. }
  55. //convert Time object or now into WordArray
  56. var timeBytes = function timeBytes(time) {
  57. if (time) {
  58. time = (time / 1000)
  59. } else {
  60. time = (Math.round(new Date() / 1000))
  61. }
  62. var hexTime = time.toString(16).lpad('0', '16')
  63. return Hex.parse(hexTime);
  64. }
  65. var fernet = function fernet(opts) {
  66. this.Hex = Hex;
  67. this.Base64 = Base64;
  68. this.parseHex = parseHex;
  69. this.decode64toHex = decode64toHex;
  70. this.hexBits = hexBits;
  71. this.urlsafe = urlsafe;
  72. //Sets the secret from base64 encoded value
  73. this.setSecret = function setSecret(secret64) {
  74. this.secret = new this.Secret(secret64);
  75. return this.secret;
  76. }
  77. this.ArrayToHex = ArrayToHex;
  78. this.setIV = setIV;
  79. this.encryptMessage = function (message, encryptionKey, iv) {
  80. var encrypted = AES.encrypt(message, encryptionKey, { iv: iv });
  81. return encrypted.ciphertext;
  82. }
  83. this.decryptMessage = function (cipherText, encryptionKey, iv) {
  84. var encrypted = {};
  85. encrypted.key = encryptionKey;
  86. encrypted.iv = iv;
  87. encrypted.ciphertext = cipherText;
  88. var decrypted = AES.decrypt(encrypted, encryptionKey, { iv: iv });
  89. return decrypted.toString(Utf8);
  90. }
  91. this.timeBytes = timeBytes;
  92. this.createToken = function (signingKey, time, iv, cipherText) {
  93. var hmac = this.createHmac(signingKey, time, iv, cipherText);
  94. var tokenWords = Hex.parse(this.versionHex);
  95. tokenWords = tokenWords.concat(time);
  96. tokenWords = tokenWords.concat(iv);
  97. tokenWords = tokenWords.concat(cipherText);
  98. tokenWords = tokenWords.concat(hmac);
  99. return urlsafe(tokenWords.toString(Base64));
  100. }
  101. this.createHmac = function createHmac(signingKey, time, iv, cipherText) {
  102. var hmacWords = Hex.parse(this.versionHex);
  103. hmacWords = hmacWords.concat(time);
  104. hmacWords = hmacWords.concat(iv);
  105. hmacWords = hmacWords.concat(cipherText);
  106. return HmacSHA256(hmacWords, signingKey);
  107. }
  108. this.Secret = require('./lib/secret');
  109. this.Token = require('./lib/token')(this);
  110. opts = opts || {};
  111. this.ttl = opts.ttl || 60;
  112. // because (0 || x) always equals x
  113. if (opts.ttl === 0) this.ttl = 0;
  114. this.versionHex = '80';
  115. this.setIV(opts.iv);
  116. if (opts.secret) { this.setSecret(opts.secret) }
  117. }
  118. exports = module.exports = fernet;
  119. fernet.call(exports)
  120. },{"./lib/secret":2,"./lib/token":3,"__browserify_Buffer":29,"crypto":11,"crypto-js/aes":16,"crypto-js/core":18,"crypto-js/enc-base64":19,"crypto-js/enc-hex":20,"crypto-js/enc-latin1":21,"crypto-js/enc-utf8":22,"crypto-js/hmac-sha256":24,"urlsafe-base64":31}],2:[function(require,module,exports){
  121. var f = require('../fernet');
  122. var Secret = function (secret64) {
  123. var secret = f.decode64toHex(secret64);
  124. if (secret.length !== f.hexBits(256)) {
  125. throw new Error('Secret must be 32 url-safe base64-encoded bytes.');
  126. }
  127. this.signingKeyHex = secret.slice(0, f.hexBits(128));
  128. this.signingKey = f.Hex.parse(this.signingKeyHex);
  129. this.encryptionKeyHex = secret.slice(f.hexBits(128));
  130. this.encryptionKey = f.Hex.parse(this.encryptionKeyHex);
  131. }
  132. exports = module.exports = Secret;
  133. },{"../fernet":1}],3:[function(require,module,exports){
  134. var fernet = require('../fernet');
  135. //TokenFoctory
  136. module = module.exports = function (parent) {
  137. var Token = function Token(opts) {
  138. opts = opts || {};
  139. this.secret = opts.secret || parent.secret;
  140. this.ttl = opts.ttl || parent.ttl;
  141. if (opts.ttl === 0) this.ttl = 0;
  142. this.message = opts.message;
  143. this.cipherText = opts.cipherText;
  144. this.token = opts.token;
  145. this.version = opts.version || fernet.parseHex(parent.versionHex);
  146. this.optsIV = opts.iv;
  147. this.maxClockSkew = 60;
  148. if (opts.time) this.setTime(Date.parse(opts.time));
  149. else this.setTime();
  150. }
  151. Token.prototype = {
  152. setIV: fernet.setIV,
  153. setTime: function tokenSetTime(time) {
  154. this.time = fernet.timeBytes(time);
  155. },
  156. toString: function tokenToString() {
  157. if (this.encoded) {
  158. return this.token
  159. } else {
  160. return this.message
  161. }
  162. },
  163. encode: function encodeToken(message) {
  164. if (!this.secret) throw (new Error("Secret not set"));
  165. this.encoded = true;
  166. this.setIV(this.optsIV); //if null will always be a fresh IV
  167. this.message = message || this.message;
  168. this.cipherText = fernet.encryptMessage(this.message, this.secret.encryptionKey, this.iv);
  169. this.token = fernet.createToken(this.secret.signingKey, this.time, this.iv, this.cipherText)
  170. return this.token;
  171. },
  172. decode: function decodeToken(token) {
  173. if (!this.secret) throw (new Error("Secret not set"));
  174. this.encoded = false;
  175. this.token = token || this.token;
  176. var tokenString = fernet.decode64toHex(this.token);
  177. var versionOffset = fernet.hexBits(8);
  178. var timeOffset = versionOffset + fernet.hexBits(64);
  179. var ivOffset = timeOffset + fernet.hexBits(128);
  180. var hmacOffset = tokenString.length - fernet.hexBits(256);
  181. var timeInt = fernet.parseHex(tokenString.slice(versionOffset, timeOffset));
  182. this.version = fernet.parseHex(tokenString.slice(0, versionOffset));
  183. if (this.version != 128) {
  184. throw new Error("Invalid version");
  185. }
  186. this.time = new Date(timeInt * 1000);
  187. var currentTime = new Date()
  188. var timeDiff = (currentTime - this.time) / 1000;
  189. if (this.ttl > 0) {
  190. if (timeDiff > this.ttl) {
  191. throw new Error("Invalid Token: TTL");
  192. }
  193. if (((currentTime / 1000) + this.maxClockSkew) < timeInt) {
  194. throw new Error("far-future timestamp");
  195. }
  196. }
  197. this.ivHex = tokenString.slice(timeOffset, ivOffset);
  198. this.iv = fernet.Hex.parse(this.ivHex);
  199. this.cipherTextHex = tokenString.slice(ivOffset, hmacOffset);
  200. this.cipherText = fernet.Hex.parse(this.cipherTextHex);
  201. this.hmacHex = tokenString.slice(hmacOffset);
  202. var decodedHmac = fernet.createHmac(this.secret.signingKey, fernet.timeBytes(this.time), this.iv, this.cipherText);
  203. var decodedHmacHex = decodedHmac.toString(fernet.Hex);
  204. var accum = 0
  205. for (var i = 0; i < 64; i++) {
  206. accum += decodedHmacHex.charCodeAt(i) ^ this.hmacHex.charCodeAt(i)
  207. }
  208. if (accum != 0) throw new Error("Invalid Token: HMAC");
  209. this.message = fernet.decryptMessage(this.cipherText, this.secret.encryptionKey, this.iv)
  210. return this.message;
  211. }
  212. }
  213. return Token;
  214. }
  215. //exports = module.exports = Token;
  216. },{"../fernet":1}],4:[function(require,module,exports){
  217. (function (exports) {
  218. 'use strict';
  219. var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  220. function b64ToByteArray(b64) {
  221. var i, j, l, tmp, placeHolders, arr;
  222. if (b64.length % 4 > 0) {
  223. throw 'Invalid string. Length must be a multiple of 4';
  224. }
  225. // the number of equal signs (place holders)
  226. // if there are two placeholders, than the two characters before it
  227. // represent one byte
  228. // if there is only one, then the three characters before it represent 2 bytes
  229. // this is just a cheap hack to not do indexOf twice
  230. placeHolders = b64.indexOf('=');
  231. placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0;
  232. // base64 is 4/3 + up to two characters of the original data
  233. arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders);
  234. // if there are placeholders, only get up to the last complete 4 chars
  235. l = placeHolders > 0 ? b64.length - 4 : b64.length;
  236. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  237. tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]);
  238. arr.push((tmp & 0xFF0000) >> 16);
  239. arr.push((tmp & 0xFF00) >> 8);
  240. arr.push(tmp & 0xFF);
  241. }
  242. if (placeHolders === 2) {
  243. tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4);
  244. arr.push(tmp & 0xFF);
  245. } else if (placeHolders === 1) {
  246. tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2);
  247. arr.push((tmp >> 8) & 0xFF);
  248. arr.push(tmp & 0xFF);
  249. }
  250. return arr;
  251. }
  252. function uint8ToBase64(uint8) {
  253. var i,
  254. extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
  255. output = "",
  256. temp, length;
  257. function tripletToBase64 (num) {
  258. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
  259. };
  260. // go through the array every three bytes, we'll deal with trailing stuff later
  261. for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
  262. temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
  263. output += tripletToBase64(temp);
  264. }
  265. // pad the end with zeros, but make sure to not forget the extra bytes
  266. switch (extraBytes) {
  267. case 1:
  268. temp = uint8[uint8.length - 1];
  269. output += lookup[temp >> 2];
  270. output += lookup[(temp << 4) & 0x3F];
  271. output += '==';
  272. break;
  273. case 2:
  274. temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]);
  275. output += lookup[temp >> 10];
  276. output += lookup[(temp >> 4) & 0x3F];
  277. output += lookup[(temp << 2) & 0x3F];
  278. output += '=';
  279. break;
  280. }
  281. return output;
  282. }
  283. module.exports.toByteArray = b64ToByteArray;
  284. module.exports.fromByteArray = uint8ToBase64;
  285. }());
  286. },{}],5:[function(require,module,exports){
  287. // UTILITY
  288. var util = require('util');
  289. var Buffer = require("buffer").Buffer;
  290. var pSlice = Array.prototype.slice;
  291. function objectKeys(object) {
  292. if (Object.keys) return Object.keys(object);
  293. var result = [];
  294. for (var name in object) {
  295. if (Object.prototype.hasOwnProperty.call(object, name)) {
  296. result.push(name);
  297. }
  298. }
  299. return result;
  300. }
  301. // 1. The assert module provides functions that throw
  302. // AssertionError's when particular conditions are not met. The
  303. // assert module must conform to the following interface.
  304. var assert = module.exports = ok;
  305. // 2. The AssertionError is defined in assert.
  306. // new assert.AssertionError({ message: message,
  307. // actual: actual,
  308. // expected: expected })
  309. assert.AssertionError = function AssertionError(options) {
  310. this.name = 'AssertionError';
  311. this.message = options.message;
  312. this.actual = options.actual;
  313. this.expected = options.expected;
  314. this.operator = options.operator;
  315. var stackStartFunction = options.stackStartFunction || fail;
  316. if (Error.captureStackTrace) {
  317. Error.captureStackTrace(this, stackStartFunction);
  318. }
  319. };
  320. // assert.AssertionError instanceof Error
  321. util.inherits(assert.AssertionError, Error);
  322. function replacer(key, value) {
  323. if (value === undefined) {
  324. return '' + value;
  325. }
  326. if (typeof value === 'number' && (isNaN(value) || !isFinite(value))) {
  327. return value.toString();
  328. }
  329. if (typeof value === 'function' || value instanceof RegExp) {
  330. return value.toString();
  331. }
  332. return value;
  333. }
  334. function truncate(s, n) {
  335. if (typeof s == 'string') {
  336. return s.length < n ? s : s.slice(0, n);
  337. } else {
  338. return s;
  339. }
  340. }
  341. assert.AssertionError.prototype.toString = function() {
  342. if (this.message) {
  343. return [this.name + ':', this.message].join(' ');
  344. } else {
  345. return [
  346. this.name + ':',
  347. truncate(JSON.stringify(this.actual, replacer), 128),
  348. this.operator,
  349. truncate(JSON.stringify(this.expected, replacer), 128)
  350. ].join(' ');
  351. }
  352. };
  353. // At present only the three keys mentioned above are used and
  354. // understood by the spec. Implementations or sub modules can pass
  355. // other keys to the AssertionError's constructor - they will be
  356. // ignored.
  357. // 3. All of the following functions must throw an AssertionError
  358. // when a corresponding condition is not met, with a message that
  359. // may be undefined if not provided. All assertion methods provide
  360. // both the actual and expected values to the assertion error for
  361. // display purposes.
  362. function fail(actual, expected, message, operator, stackStartFunction) {
  363. throw new assert.AssertionError({
  364. message: message,
  365. actual: actual,
  366. expected: expected,
  367. operator: operator,
  368. stackStartFunction: stackStartFunction
  369. });
  370. }
  371. // EXTENSION! allows for well behaved errors defined elsewhere.
  372. assert.fail = fail;
  373. // 4. Pure assertion tests whether a value is truthy, as determined
  374. // by !!guard.
  375. // assert.ok(guard, message_opt);
  376. // This statement is equivalent to assert.equal(true, guard,
  377. // message_opt);. To test strictly for the value true, use
  378. // assert.strictEqual(true, guard, message_opt);.
  379. function ok(value, message) {
  380. if (!!!value) fail(value, true, message, '==', assert.ok);
  381. }
  382. assert.ok = ok;
  383. // 5. The equality assertion tests shallow, coercive equality with
  384. // ==.
  385. // assert.equal(actual, expected, message_opt);
  386. assert.equal = function equal(actual, expected, message) {
  387. if (actual != expected) fail(actual, expected, message, '==', assert.equal);
  388. };
  389. // 6. The non-equality assertion tests for whether two objects are not equal
  390. // with != assert.notEqual(actual, expected, message_opt);
  391. assert.notEqual = function notEqual(actual, expected, message) {
  392. if (actual == expected) {
  393. fail(actual, expected, message, '!=', assert.notEqual);
  394. }
  395. };
  396. // 7. The equivalence assertion tests a deep equality relation.
  397. // assert.deepEqual(actual, expected, message_opt);
  398. assert.deepEqual = function deepEqual(actual, expected, message) {
  399. if (!_deepEqual(actual, expected)) {
  400. fail(actual, expected, message, 'deepEqual', assert.deepEqual);
  401. }
  402. };
  403. function _deepEqual(actual, expected) {
  404. // 7.1. All identical values are equivalent, as determined by ===.
  405. if (actual === expected) {
  406. return true;
  407. } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
  408. if (actual.length != expected.length) return false;
  409. for (var i = 0; i < actual.length; i++) {
  410. if (actual[i] !== expected[i]) return false;
  411. }
  412. return true;
  413. // 7.2. If the expected value is a Date object, the actual value is
  414. // equivalent if it is also a Date object that refers to the same time.
  415. } else if (actual instanceof Date && expected instanceof Date) {
  416. return actual.getTime() === expected.getTime();
  417. // 7.3. Other pairs that do not both pass typeof value == 'object',
  418. // equivalence is determined by ==.
  419. } else if (typeof actual != 'object' && typeof expected != 'object') {
  420. return actual == expected;
  421. // 7.4. For all other Object pairs, including Array objects, equivalence is
  422. // determined by having the same number of owned properties (as verified
  423. // with Object.prototype.hasOwnProperty.call), the same set of keys
  424. // (although not necessarily the same order), equivalent values for every
  425. // corresponding key, and an identical 'prototype' property. Note: this
  426. // accounts for both named and indexed properties on Arrays.
  427. } else {
  428. return objEquiv(actual, expected);
  429. }
  430. }
  431. function isUndefinedOrNull(value) {
  432. return value === null || value === undefined;
  433. }
  434. function isArguments(object) {
  435. return Object.prototype.toString.call(object) == '[object Arguments]';
  436. }
  437. function objEquiv(a, b) {
  438. if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
  439. return false;
  440. // an identical 'prototype' property.
  441. if (a.prototype !== b.prototype) return false;
  442. //~~~I've managed to break Object.keys through screwy arguments passing.
  443. // Converting to array solves the problem.
  444. if (isArguments(a)) {
  445. if (!isArguments(b)) {
  446. return false;
  447. }
  448. a = pSlice.call(a);
  449. b = pSlice.call(b);
  450. return _deepEqual(a, b);
  451. }
  452. try {
  453. var ka = objectKeys(a),
  454. kb = objectKeys(b),
  455. key, i;
  456. } catch (e) {//happens when one is a string literal and the other isn't
  457. return false;
  458. }
  459. // having the same number of owned properties (keys incorporates
  460. // hasOwnProperty)
  461. if (ka.length != kb.length)
  462. return false;
  463. //the same set of keys (although not necessarily the same order),
  464. ka.sort();
  465. kb.sort();
  466. //~~~cheap key test
  467. for (i = ka.length - 1; i >= 0; i--) {
  468. if (ka[i] != kb[i])
  469. return false;
  470. }
  471. //equivalent values for every corresponding key, and
  472. //~~~possibly expensive deep test
  473. for (i = ka.length - 1; i >= 0; i--) {
  474. key = ka[i];
  475. if (!_deepEqual(a[key], b[key])) return false;
  476. }
  477. return true;
  478. }
  479. // 8. The non-equivalence assertion tests for any deep inequality.
  480. // assert.notDeepEqual(actual, expected, message_opt);
  481. assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
  482. if (_deepEqual(actual, expected)) {
  483. fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
  484. }
  485. };
  486. // 9. The strict equality assertion tests strict equality, as determined by ===.
  487. // assert.strictEqual(actual, expected, message_opt);
  488. assert.strictEqual = function strictEqual(actual, expected, message) {
  489. if (actual !== expected) {
  490. fail(actual, expected, message, '===', assert.strictEqual);
  491. }
  492. };
  493. // 10. The strict non-equality assertion tests for strict inequality, as
  494. // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
  495. assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
  496. if (actual === expected) {
  497. fail(actual, expected, message, '!==', assert.notStrictEqual);
  498. }
  499. };
  500. function expectedException(actual, expected) {
  501. if (!actual || !expected) {
  502. return false;
  503. }
  504. if (expected instanceof RegExp) {
  505. return expected.test(actual);
  506. } else if (actual instanceof expected) {
  507. return true;
  508. } else if (expected.call({}, actual) === true) {
  509. return true;
  510. }
  511. return false;
  512. }
  513. function _throws(shouldThrow, block, expected, message) {
  514. var actual;
  515. if (typeof expected === 'string') {
  516. message = expected;
  517. expected = null;
  518. }
  519. try {
  520. block();
  521. } catch (e) {
  522. actual = e;
  523. }
  524. message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
  525. (message ? ' ' + message : '.');
  526. if (shouldThrow && !actual) {
  527. fail('Missing expected exception' + message);
  528. }
  529. if (!shouldThrow && expectedException(actual, expected)) {
  530. fail('Got unwanted exception' + message);
  531. }
  532. if ((shouldThrow && actual && expected &&
  533. !expectedException(actual, expected)) || (!shouldThrow && actual)) {
  534. throw actual;
  535. }
  536. }
  537. // 11. Expected to throw an error:
  538. // assert.throws(block, Error_opt, message_opt);
  539. assert.throws = function(block, /*optional*/error, /*optional*/message) {
  540. _throws.apply(this, [true].concat(pSlice.call(arguments)));
  541. };
  542. // EXTENSION! This is annoying to write outside this module.
  543. assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
  544. _throws.apply(this, [false].concat(pSlice.call(arguments)));
  545. };
  546. assert.ifError = function(err) { if (err) {throw err;}};
  547. },{"buffer":9,"util":7}],6:[function(require,module,exports){
  548. var process=require("__browserify_process");if (!process.EventEmitter) process.EventEmitter = function () {};
  549. var EventEmitter = exports.EventEmitter = process.EventEmitter;
  550. var isArray = typeof Array.isArray === 'function'
  551. ? Array.isArray
  552. : function (xs) {
  553. return Object.prototype.toString.call(xs) === '[object Array]'
  554. }
  555. ;
  556. function indexOf (xs, x) {
  557. if (xs.indexOf) return xs.indexOf(x);
  558. for (var i = 0; i < xs.length; i++) {
  559. if (x === xs[i]) return i;
  560. }
  561. return -1;
  562. }
  563. // By default EventEmitters will print a warning if more than
  564. // 10 listeners are added to it. This is a useful default which
  565. // helps finding memory leaks.
  566. //
  567. // Obviously not all Emitters should be limited to 10. This function allows
  568. // that to be increased. Set to zero for unlimited.
  569. var defaultMaxListeners = 10;
  570. EventEmitter.prototype.setMaxListeners = function(n) {
  571. if (!this._events) this._events = {};
  572. this._events.maxListeners = n;
  573. };
  574. EventEmitter.prototype.emit = function(type) {
  575. // If there is no 'error' event listener then throw.
  576. if (type === 'error') {
  577. if (!this._events || !this._events.error ||
  578. (isArray(this._events.error) && !this._events.error.length))
  579. {
  580. if (arguments[1] instanceof Error) {
  581. throw arguments[1]; // Unhandled 'error' event
  582. } else {
  583. throw new Error("Uncaught, unspecified 'error' event.");
  584. }
  585. return false;
  586. }
  587. }
  588. if (!this._events) return false;
  589. var handler = this._events[type];
  590. if (!handler) return false;
  591. if (typeof handler == 'function') {
  592. switch (arguments.length) {
  593. // fast cases
  594. case 1:
  595. handler.call(this);
  596. break;
  597. case 2:
  598. handler.call(this, arguments[1]);
  599. break;
  600. case 3:
  601. handler.call(this, arguments[1], arguments[2]);
  602. break;
  603. // slower
  604. default:
  605. var args = Array.prototype.slice.call(arguments, 1);
  606. handler.apply(this, args);
  607. }
  608. return true;
  609. } else if (isArray(handler)) {
  610. var args = Array.prototype.slice.call(arguments, 1);
  611. var listeners = handler.slice();
  612. for (var i = 0, l = listeners.length; i < l; i++) {
  613. listeners[i].apply(this, args);
  614. }
  615. return true;
  616. } else {
  617. return false;
  618. }
  619. };
  620. // EventEmitter is defined in src/node_events.cc
  621. // EventEmitter.prototype.emit() is also defined there.
  622. EventEmitter.prototype.addListener = function(type, listener) {
  623. if ('function' !== typeof listener) {
  624. throw new Error('addListener only takes instances of Function');
  625. }
  626. if (!this._events) this._events = {};
  627. // To avoid recursion in the case that type == "newListeners"! Before
  628. // adding it to the listeners, first emit "newListeners".
  629. this.emit('newListener', type, listener);
  630. if (!this._events[type]) {
  631. // Optimize the case of one listener. Don't need the extra array object.
  632. this._events[type] = listener;
  633. } else if (isArray(this._events[type])) {
  634. // Check for listener leak
  635. if (!this._events[type].warned) {
  636. var m;
  637. if (this._events.maxListeners !== undefined) {
  638. m = this._events.maxListeners;
  639. } else {
  640. m = defaultMaxListeners;
  641. }
  642. if (m && m > 0 && this._events[type].length > m) {
  643. this._events[type].warned = true;
  644. console.error('(node) warning: possible EventEmitter memory ' +
  645. 'leak detected. %d listeners added. ' +
  646. 'Use emitter.setMaxListeners() to increase limit.',
  647. this._events[type].length);
  648. console.trace();
  649. }
  650. }
  651. // If we've already got an array, just append.
  652. this._events[type].push(listener);
  653. } else {
  654. // Adding the second element, need to change to array.
  655. this._events[type] = [this._events[type], listener];
  656. }
  657. return this;
  658. };
  659. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  660. EventEmitter.prototype.once = function(type, listener) {
  661. var self = this;
  662. self.on(type, function g() {
  663. self.removeListener(type, g);
  664. listener.apply(this, arguments);
  665. });
  666. return this;
  667. };
  668. EventEmitter.prototype.removeListener = function(type, listener) {
  669. if ('function' !== typeof listener) {
  670. throw new Error('removeListener only takes instances of Function');
  671. }
  672. // does not use listeners(), so no side effect of creating _events[type]
  673. if (!this._events || !this._events[type]) return this;
  674. var list = this._events[type];
  675. if (isArray(list)) {
  676. var i = indexOf(list, listener);
  677. if (i < 0) return this;
  678. list.splice(i, 1);
  679. if (list.length == 0)
  680. delete this._events[type];
  681. } else if (this._events[type] === listener) {
  682. delete this._events[type];
  683. }
  684. return this;
  685. };
  686. EventEmitter.prototype.removeAllListeners = function(type) {
  687. if (arguments.length === 0) {
  688. this._events = {};
  689. return this;
  690. }
  691. // does not use listeners(), so no side effect of creating _events[type]
  692. if (type && this._events && this._events[type]) this._events[type] = null;
  693. return this;
  694. };
  695. EventEmitter.prototype.listeners = function(type) {
  696. if (!this._events) this._events = {};
  697. if (!this._events[type]) this._events[type] = [];
  698. if (!isArray(this._events[type])) {
  699. this._events[type] = [this._events[type]];
  700. }
  701. return this._events[type];
  702. };
  703. EventEmitter.listenerCount = function(emitter, type) {
  704. var ret;
  705. if (!emitter._events || !emitter._events[type])
  706. ret = 0;
  707. else if (typeof emitter._events[type] === 'function')
  708. ret = 1;
  709. else
  710. ret = emitter._events[type].length;
  711. return ret;
  712. };
  713. },{"__browserify_process":30}],7:[function(require,module,exports){
  714. var events = require('events');
  715. exports.isArray = isArray;
  716. exports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'};
  717. exports.isRegExp = function(obj){return Object.prototype.toString.call(obj) === '[object RegExp]'};
  718. exports.print = function () {};
  719. exports.puts = function () {};
  720. exports.debug = function() {};
  721. exports.inspect = function(obj, showHidden, depth, colors) {
  722. var seen = [];
  723. var stylize = function(str, styleType) {
  724. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  725. var styles =
  726. { 'bold' : [1, 22],
  727. 'italic' : [3, 23],
  728. 'underline' : [4, 24],
  729. 'inverse' : [7, 27],
  730. 'white' : [37, 39],
  731. 'grey' : [90, 39],
  732. 'black' : [30, 39],
  733. 'blue' : [34, 39],
  734. 'cyan' : [36, 39],
  735. 'green' : [32, 39],
  736. 'magenta' : [35, 39],
  737. 'red' : [31, 39],
  738. 'yellow' : [33, 39] };
  739. var style =
  740. { 'special': 'cyan',
  741. 'number': 'blue',
  742. 'boolean': 'yellow',
  743. 'undefined': 'grey',
  744. 'null': 'bold',
  745. 'string': 'green',
  746. 'date': 'magenta',
  747. // "name": intentionally not styling
  748. 'regexp': 'red' }[styleType];
  749. if (style) {
  750. return '\u001b[' + styles[style][0] + 'm' + str +
  751. '\u001b[' + styles[style][1] + 'm';
  752. } else {
  753. return str;
  754. }
  755. };
  756. if (! colors) {
  757. stylize = function(str, styleType) { return str; };
  758. }
  759. function format(value, recurseTimes) {
  760. // Provide a hook for user-specified inspect functions.
  761. // Check that value is an object with an inspect function on it
  762. if (value && typeof value.inspect === 'function' &&
  763. // Filter out the util module, it's inspect function is special
  764. value !== exports &&
  765. // Also filter out any prototype objects using the circular check.
  766. !(value.constructor && value.constructor.prototype === value)) {
  767. return value.inspect(recurseTimes);
  768. }
  769. // Primitive types cannot have properties
  770. switch (typeof value) {
  771. case 'undefined':
  772. return stylize('undefined', 'undefined');
  773. case 'string':
  774. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  775. .replace(/'/g, "\\'")
  776. .replace(/\\"/g, '"') + '\'';
  777. return stylize(simple, 'string');
  778. case 'number':
  779. return stylize('' + value, 'number');
  780. case 'boolean':
  781. return stylize('' + value, 'boolean');
  782. }
  783. // For some reason typeof null is "object", so special case here.
  784. if (value === null) {
  785. return stylize('null', 'null');
  786. }
  787. // Look up the keys of the object.
  788. var visible_keys = Object_keys(value);
  789. var keys = showHidden ? Object_getOwnPropertyNames(value) : visible_keys;
  790. // Functions without properties can be shortcutted.
  791. if (typeof value === 'function' && keys.length === 0) {
  792. if (isRegExp(value)) {
  793. return stylize('' + value, 'regexp');
  794. } else {
  795. var name = value.name ? ': ' + value.name : '';
  796. return stylize('[Function' + name + ']', 'special');
  797. }
  798. }
  799. // Dates without properties can be shortcutted
  800. if (isDate(value) && keys.length === 0) {
  801. return stylize(value.toUTCString(), 'date');
  802. }
  803. var base, type, braces;
  804. // Determine the object type
  805. if (isArray(value)) {
  806. type = 'Array';
  807. braces = ['[', ']'];
  808. } else {
  809. type = 'Object';
  810. braces = ['{', '}'];
  811. }
  812. // Make functions say that they are functions
  813. if (typeof value === 'function') {
  814. var n = value.name ? ': ' + value.name : '';
  815. base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']';
  816. } else {
  817. base = '';
  818. }
  819. // Make dates with properties first say the date
  820. if (isDate(value)) {
  821. base = ' ' + value.toUTCString();
  822. }
  823. if (keys.length === 0) {
  824. return braces[0] + base + braces[1];
  825. }
  826. if (recurseTimes < 0) {
  827. if (isRegExp(value)) {
  828. return stylize('' + value, 'regexp');
  829. } else {
  830. return stylize('[Object]', 'special');
  831. }
  832. }
  833. seen.push(value);
  834. var output = keys.map(function(key) {
  835. var name, str;
  836. if (value.__lookupGetter__) {
  837. if (value.__lookupGetter__(key)) {
  838. if (value.__lookupSetter__(key)) {
  839. str = stylize('[Getter/Setter]', 'special');
  840. } else {
  841. str = stylize('[Getter]', 'special');
  842. }
  843. } else {
  844. if (value.__lookupSetter__(key)) {
  845. str = stylize('[Setter]', 'special');
  846. }
  847. }
  848. }
  849. if (visible_keys.indexOf(key) < 0) {
  850. name = '[' + key + ']';
  851. }
  852. if (!str) {
  853. if (seen.indexOf(value[key]) < 0) {
  854. if (recurseTimes === null) {
  855. str = format(value[key]);
  856. } else {
  857. str = format(value[key], recurseTimes - 1);
  858. }
  859. if (str.indexOf('\n') > -1) {
  860. if (isArray(value)) {
  861. str = str.split('\n').map(function(line) {
  862. return ' ' + line;
  863. }).join('\n').substr(2);
  864. } else {
  865. str = '\n' + str.split('\n').map(function(line) {
  866. return ' ' + line;
  867. }).join('\n');
  868. }
  869. }
  870. } else {
  871. str = stylize('[Circular]', 'special');
  872. }
  873. }
  874. if (typeof name === 'undefined') {
  875. if (type === 'Array' && key.match(/^\d+$/)) {
  876. return str;
  877. }
  878. name = JSON.stringify('' + key);
  879. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  880. name = name.substr(1, name.length - 2);
  881. name = stylize(name, 'name');
  882. } else {
  883. name = name.replace(/'/g, "\\'")
  884. .replace(/\\"/g, '"')
  885. .replace(/(^"|"$)/g, "'");
  886. name = stylize(name, 'string');
  887. }
  888. }
  889. return name + ': ' + str;
  890. });
  891. seen.pop();
  892. var numLinesEst = 0;
  893. var length = output.reduce(function(prev, cur) {
  894. numLinesEst++;
  895. if (cur.indexOf('\n') >= 0) numLinesEst++;
  896. return prev + cur.length + 1;
  897. }, 0);
  898. if (length > 50) {
  899. output = braces[0] +
  900. (base === '' ? '' : base + '\n ') +
  901. ' ' +
  902. output.join(',\n ') +
  903. ' ' +
  904. braces[1];
  905. } else {
  906. output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  907. }
  908. return output;
  909. }
  910. return format(obj, (typeof depth === 'undefined' ? 2 : depth));
  911. };
  912. function isArray(ar) {
  913. return Array.isArray(ar) ||
  914. (typeof ar === 'object' && Object.prototype.toString.call(ar) === '[object Array]');
  915. }
  916. function isRegExp(re) {
  917. typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]';
  918. }
  919. function isDate(d) {
  920. return typeof d === 'object' && Object.prototype.toString.call(d) === '[object Date]';
  921. }
  922. function pad(n) {
  923. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  924. }
  925. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  926. 'Oct', 'Nov', 'Dec'];
  927. // 26 Feb 16:19:34
  928. function timestamp() {
  929. var d = new Date();
  930. var time = [pad(d.getHours()),
  931. pad(d.getMinutes()),
  932. pad(d.getSeconds())].join(':');
  933. return [d.getDate(), months[d.getMonth()], time].join(' ');
  934. }
  935. exports.log = function (msg) {};
  936. exports.pump = null;
  937. var Object_keys = Object.keys || function (obj) {
  938. var res = [];
  939. for (var key in obj) res.push(key);
  940. return res;
  941. };
  942. var Object_getOwnPropertyNames = Object.getOwnPropertyNames || function (obj) {
  943. var res = [];
  944. for (var key in obj) {
  945. if (Object.hasOwnProperty.call(obj, key)) res.push(key);
  946. }
  947. return res;
  948. };
  949. var Object_create = Object.create || function (prototype, properties) {
  950. // from es5-shim
  951. var object;
  952. if (prototype === null) {
  953. object = { '__proto__' : null };
  954. }
  955. else {
  956. if (typeof prototype !== 'object') {
  957. throw new TypeError(
  958. 'typeof prototype[' + (typeof prototype) + '] != \'object\''
  959. );
  960. }
  961. var Type = function () {};
  962. Type.prototype = prototype;
  963. object = new Type();
  964. object.__proto__ = prototype;
  965. }
  966. if (typeof properties !== 'undefined' && Object.defineProperties) {
  967. Object.defineProperties(object, properties);
  968. }
  969. return object;
  970. };
  971. exports.inherits = function(ctor, superCtor) {
  972. ctor.super_ = superCtor;
  973. ctor.prototype = Object_create(superCtor.prototype, {
  974. constructor: {
  975. value: ctor,
  976. enumerable: false,
  977. writable: true,
  978. configurable: true
  979. }
  980. });
  981. };
  982. var formatRegExp = /%[sdj%]/g;
  983. exports.format = function(f) {
  984. if (typeof f !== 'string') {
  985. var objects = [];
  986. for (var i = 0; i < arguments.length; i++) {
  987. objects.push(exports.inspect(arguments[i]));
  988. }
  989. return objects.join(' ');
  990. }
  991. var i = 1;
  992. var args = arguments;
  993. var len = args.length;
  994. var str = String(f).replace(formatRegExp, function(x) {
  995. if (x === '%%') return '%';
  996. if (i >= len) return x;
  997. switch (x) {
  998. case '%s': return String(args[i++]);
  999. case '%d': return Number(args[i++]);
  1000. case '%j': return JSON.stringify(args[i++]);
  1001. default:
  1002. return x;
  1003. }
  1004. });
  1005. for(var x = args[i]; i < len; x = args[++i]){
  1006. if (x === null || typeof x !== 'object') {
  1007. str += ' ' + x;
  1008. } else {
  1009. str += ' ' + exports.inspect(x);
  1010. }
  1011. }
  1012. return str;
  1013. };
  1014. },{"events":6}],8:[function(require,module,exports){
  1015. exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) {
  1016. var e, m,
  1017. eLen = nBytes * 8 - mLen - 1,
  1018. eMax = (1 << eLen) - 1,
  1019. eBias = eMax >> 1,
  1020. nBits = -7,
  1021. i = isBE ? 0 : (nBytes - 1),
  1022. d = isBE ? 1 : -1,
  1023. s = buffer[offset + i];
  1024. i += d;
  1025. e = s & ((1 << (-nBits)) - 1);
  1026. s >>= (-nBits);
  1027. nBits += eLen;
  1028. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
  1029. m = e & ((1 << (-nBits)) - 1);
  1030. e >>= (-nBits);
  1031. nBits += mLen;
  1032. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
  1033. if (e === 0) {
  1034. e = 1 - eBias;
  1035. } else if (e === eMax) {
  1036. return m ? NaN : ((s ? -1 : 1) * Infinity);
  1037. } else {
  1038. m = m + Math.pow(2, mLen);
  1039. e = e - eBias;
  1040. }
  1041. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  1042. };
  1043. exports.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) {
  1044. var e, m, c,
  1045. eLen = nBytes * 8 - mLen - 1,
  1046. eMax = (1 << eLen) - 1,
  1047. eBias = eMax >> 1,
  1048. rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
  1049. i = isBE ? (nBytes - 1) : 0,
  1050. d = isBE ? -1 : 1,
  1051. s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  1052. value = Math.abs(value);
  1053. if (isNaN(value) || value === Infinity) {
  1054. m = isNaN(value) ? 1 : 0;
  1055. e = eMax;
  1056. } else {
  1057. e = Math.floor(Math.log(value) / Math.LN2);
  1058. if (value * (c = Math.pow(2, -e)) < 1) {
  1059. e--;
  1060. c *= 2;
  1061. }
  1062. if (e + eBias >= 1) {
  1063. value += rt / c;
  1064. } else {
  1065. value += rt * Math.pow(2, 1 - eBias);
  1066. }
  1067. if (value * c >= 2) {
  1068. e++;
  1069. c /= 2;
  1070. }
  1071. if (e + eBias >= eMax) {
  1072. m = 0;
  1073. e = eMax;
  1074. } else if (e + eBias >= 1) {
  1075. m = (value * c - 1) * Math.pow(2, mLen);
  1076. e = e + eBias;
  1077. } else {
  1078. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  1079. e = 0;
  1080. }
  1081. }
  1082. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
  1083. e = (e << mLen) | m;
  1084. eLen += mLen;
  1085. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
  1086. buffer[offset + i - d] |= s * 128;
  1087. };
  1088. },{}],9:[function(require,module,exports){
  1089. var assert = require('assert');
  1090. exports.Buffer = Buffer;
  1091. exports.SlowBuffer = Buffer;
  1092. Buffer.poolSize = 8192;
  1093. exports.INSPECT_MAX_BYTES = 50;
  1094. function Buffer(subject, encoding, offset) {
  1095. if (!(this instanceof Buffer)) {
  1096. return new Buffer(subject, encoding, offset);
  1097. }
  1098. this.parent = this;
  1099. this.offset = 0;
  1100. var type;
  1101. // Are we slicing?
  1102. if (typeof offset === 'number') {
  1103. this.length = coerce(encoding);
  1104. this.offset = offset;
  1105. } else {
  1106. // Find the length
  1107. switch (type = typeof subject) {
  1108. case 'number':
  1109. this.length = coerce(subject);
  1110. break;
  1111. case 'string':
  1112. this.length = Buffer.byteLength(subject, encoding);
  1113. break;
  1114. case 'object': // Assume object is an array
  1115. this.length = coerce(subject.length);
  1116. break;
  1117. default:
  1118. throw new Error('First argument needs to be a number, ' +
  1119. 'array or string.');
  1120. }
  1121. // Treat array-ish objects as a byte array.
  1122. if (isArrayIsh(subject)) {
  1123. for (var i = 0; i < this.length; i++) {
  1124. if (subject instanceof Buffer) {
  1125. this[i] = subject.readUInt8(i);
  1126. }
  1127. else {
  1128. this[i] = subject[i];
  1129. }
  1130. }
  1131. } else if (type == 'string') {
  1132. // We are a string
  1133. this.length = this.write(subject, 0, encoding);
  1134. } else if (type === 'number') {
  1135. for (var i = 0; i < this.length; i++) {
  1136. this[i] = 0;
  1137. }
  1138. }
  1139. }
  1140. }
  1141. Buffer.prototype.get = function get(i) {
  1142. if (i < 0 || i >= this.length) throw new Error('oob');
  1143. return this[i];
  1144. };
  1145. Buffer.prototype.set = function set(i, v) {
  1146. if (i < 0 || i >= this.length) throw new Error('oob');
  1147. return this[i] = v;
  1148. };
  1149. Buffer.byteLength = function (str, encoding) {
  1150. switch (encoding || "utf8") {
  1151. case 'hex':
  1152. return str.length / 2;
  1153. case 'utf8':
  1154. case 'utf-8':
  1155. return utf8ToBytes(str).length;
  1156. case 'ascii':
  1157. case 'binary':
  1158. return str.length;
  1159. case 'base64':
  1160. return base64ToBytes(str).length;
  1161. default:
  1162. throw new Error('Unknown encoding');
  1163. }
  1164. };
  1165. Buffer.prototype.utf8Write = function (string, offset, length) {
  1166. var bytes, pos;
  1167. return Buffer._charsWritten = blitBuffer(utf8ToBytes(string), this, offset, length);
  1168. };
  1169. Buffer.prototype.asciiWrite = function (string, offset, length) {
  1170. var bytes, pos;
  1171. return Buffer._charsWritten = blitBuffer(asciiToBytes(string), this, offset, length);
  1172. };
  1173. Buffer.prototype.binaryWrite = Buffer.prototype.asciiWrite;
  1174. Buffer.prototype.base64Write = function (string, offset, length) {
  1175. var bytes, pos;
  1176. return Buffer._charsWritten = blitBuffer(base64ToBytes(string), this, offset, length);
  1177. };
  1178. Buffer.prototype.base64Slice = function (start, end) {
  1179. var bytes = Array.prototype.slice.apply(this, arguments)
  1180. return require("base64-js").fromByteArray(bytes);
  1181. };
  1182. Buffer.prototype.utf8Slice = function () {
  1183. var bytes = Array.prototype.slice.apply(this, arguments);
  1184. var res = "";
  1185. var tmp = "";
  1186. var i = 0;
  1187. while (i < bytes.length) {
  1188. if (bytes[i] <= 0x7F) {
  1189. res += decodeUtf8Char(tmp) + String.fromCharCode(bytes[i]);
  1190. tmp = "";
  1191. } else
  1192. tmp += "%" + bytes[i].toString(16);
  1193. i++;
  1194. }
  1195. return res + decodeUtf8Char(tmp);
  1196. }
  1197. Buffer.prototype.asciiSlice = function () {
  1198. var bytes = Array.prototype.slice.apply(this, arguments);
  1199. var ret = "";
  1200. for (var i = 0; i < bytes.length; i++)
  1201. ret += String.fromCharCode(bytes[i]);
  1202. return ret;
  1203. }
  1204. Buffer.prototype.binarySlice = Buffer.prototype.asciiSlice;
  1205. Buffer.prototype.inspect = function() {
  1206. var out = [],
  1207. len = this.length;
  1208. for (var i = 0; i < len; i++) {
  1209. out[i] = toHex(this[i]);
  1210. if (i == exports.INSPECT_MAX_BYTES) {
  1211. out[i + 1] = '...';
  1212. break;
  1213. }
  1214. }
  1215. return '<Buffer ' + out.join(' ') + '>';
  1216. };
  1217. Buffer.prototype.hexSlice = function(start, end) {
  1218. var len = this.length;
  1219. if (!start || start < 0) start = 0;
  1220. if (!end || end < 0 || end > len) end = len;
  1221. var out = '';
  1222. for (var i = start; i < end; i++) {
  1223. out += toHex(this[i]);
  1224. }
  1225. return out;
  1226. };
  1227. Buffer.prototype.toString = function(encoding, start, end) {
  1228. encoding = String(encoding || 'utf8').toLowerCase();
  1229. start = +start || 0;
  1230. if (typeof end == 'undefined') end = this.length;
  1231. // Fastpath empty strings
  1232. if (+end == start) {
  1233. return '';
  1234. }
  1235. switch (encoding) {
  1236. case 'hex':
  1237. return this.hexSlice(start, end);
  1238. case 'utf8':
  1239. case 'utf-8':
  1240. return this.utf8Slice(start, end);
  1241. case 'ascii':
  1242. return this.asciiSlice(start, end);
  1243. case 'binary':
  1244. return this.binarySlice(start, end);
  1245. case 'base64':
  1246. return this.base64Slice(start, end);
  1247. case 'ucs2':
  1248. case 'ucs-2':
  1249. return this.ucs2Slice(start, end);
  1250. default:
  1251. throw new Error('Unknown encoding');
  1252. }
  1253. };
  1254. Buffer.prototype.hexWrite = function(string, offset, length) {
  1255. offset = +offset || 0;
  1256. var remaining = this.length - offset;
  1257. if (!length) {
  1258. length = remaining;
  1259. } else {
  1260. length = +length;
  1261. if (length > remaining) {
  1262. length = remaining;
  1263. }
  1264. }
  1265. // must be an even number of digits
  1266. var strLen = string.length;
  1267. if (strLen % 2) {
  1268. throw new Error('Invalid hex string');
  1269. }
  1270. if (length > strLen / 2) {
  1271. length = strLen / 2;
  1272. }
  1273. for (var i = 0; i < length; i++) {
  1274. var byte = parseInt(string.substr(i * 2, 2), 16);
  1275. if (isNaN(byte)) throw new Error('Invalid hex string');
  1276. this[offset + i] = byte;
  1277. }
  1278. Buffer._charsWritten = i * 2;
  1279. return i;
  1280. };
  1281. Buffer.prototype.write = function(string, offset, length, encoding) {
  1282. // Support both (string, offset, length, encoding)
  1283. // and the legacy (string, encoding, offset, length)
  1284. if (isFinite(offset)) {
  1285. if (!isFinite(length)) {
  1286. encoding = length;
  1287. length = undefined;
  1288. }
  1289. } else { // legacy
  1290. var swap = encoding;
  1291. encoding = offset;
  1292. offset = length;
  1293. length = swap;
  1294. }
  1295. offset = +offset || 0;
  1296. var remaining = this.length - offset;
  1297. if (!length) {
  1298. length = remaining;
  1299. } else {
  1300. length = +length;
  1301. if (length > remaining) {
  1302. length = remaining;
  1303. }
  1304. }
  1305. encoding = String(encoding || 'utf8').toLowerCase();
  1306. switch (encoding) {
  1307. case 'hex':
  1308. return this.hexWrite(string, offset, length);
  1309. case 'utf8':
  1310. case 'utf-8':
  1311. return this.utf8Write(string, offset, length);
  1312. case 'ascii':
  1313. return this.asciiWrite(string, offset, length);
  1314. case 'binary':
  1315. return this.binaryWrite(string, offset, length);
  1316. case 'base64':
  1317. return this.base64Write(string, offset, length);
  1318. case 'ucs2':
  1319. case 'ucs-2':
  1320. return this.ucs2Write(string, offset, length);
  1321. default:
  1322. throw new Error('Unknown encoding');
  1323. }
  1324. };
  1325. // slice(start, end)
  1326. Buffer.prototype.slice = function(start, end) {
  1327. if (end === undefined) end = this.length;
  1328. if (end > this.length) {
  1329. throw new Error('oob');
  1330. }
  1331. if (start > end) {
  1332. throw new Error('oob');
  1333. }
  1334. return new Buffer(this, end - start, +start);
  1335. };
  1336. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  1337. Buffer.prototype.copy = function(target, target_start, start, end) {
  1338. var source = this;
  1339. start || (start = 0);
  1340. if (end === undefined || isNaN(end)) {
  1341. end = this.length;
  1342. }
  1343. target_start || (target_start = 0);
  1344. if (end < start) throw new Error('sourceEnd < sourceStart');
  1345. // Copy 0 bytes; we're done
  1346. if (end === start) return 0;
  1347. if (target.length == 0 || source.length == 0) return 0;
  1348. if (target_start < 0 || target_start >= target.length) {
  1349. throw new Error('targetStart out of bounds');
  1350. }
  1351. if (start < 0 || start >= source.length) {
  1352. throw new Error('sourceStart out of bounds');
  1353. }
  1354. if (end < 0 || end > source.length) {
  1355. throw new Error('sourceEnd out of bounds');
  1356. }
  1357. // Are we oob?
  1358. if (end > this.length) {
  1359. end = this.length;
  1360. }
  1361. if (target.length - target_start < end - start) {
  1362. end = target.length - target_start + start;
  1363. }
  1364. var temp = [];
  1365. for (var i=start; i<end; i++) {
  1366. assert.ok(typeof this[i] !== 'undefined', "copying undefined buffer bytes!");
  1367. temp.push(this[i]);
  1368. }
  1369. for (var i=target_start; i<target_start+temp.length; i++) {
  1370. target[i] = temp[i-target_start];
  1371. }
  1372. };
  1373. // fill(value, start=0, end=buffer.length)
  1374. Buffer.prototype.fill = function fill(value, start, end) {
  1375. value || (value = 0);
  1376. start || (start = 0);
  1377. end || (end = this.length);
  1378. if (typeof value === 'string') {
  1379. value = value.charCodeAt(0);
  1380. }
  1381. if (!(typeof value === 'number') || isNaN(value)) {
  1382. throw new Error('value is not a number');
  1383. }
  1384. if (end < start) throw new Error('end < start');
  1385. // Fill 0 bytes; we're done
  1386. if (end === start) return 0;
  1387. if (this.length == 0) return 0;
  1388. if (start < 0 || start >= this.length) {
  1389. throw new Error('start out of bounds');
  1390. }
  1391. if (end < 0 || end > this.length) {
  1392. throw new Error('end out of bounds');
  1393. }
  1394. for (var i = start; i < end; i++) {
  1395. this[i] = value;
  1396. }
  1397. }
  1398. // Static methods
  1399. Buffer.isBuffer = function isBuffer(b) {
  1400. return b instanceof Buffer || b instanceof Buffer;
  1401. };
  1402. Buffer.concat = function (list, totalLength) {
  1403. if (!isArray(list)) {
  1404. throw new Error("Usage: Buffer.concat(list, [totalLength])\n \
  1405. list should be an Array.");
  1406. }
  1407. if (list.length === 0) {
  1408. return new Buffer(0);
  1409. } else if (list.length === 1) {
  1410. return list[0];
  1411. }
  1412. if (typeof totalLength !== 'number') {
  1413. totalLength = 0;
  1414. for (var i = 0; i < list.length; i++) {
  1415. var buf = list[i];
  1416. totalLength += buf.length;
  1417. }
  1418. }
  1419. var buffer = new Buffer(totalLength);
  1420. var pos = 0;
  1421. for (var i = 0; i < list.length; i++) {
  1422. var buf = list[i];
  1423. buf.copy(buffer, pos);
  1424. pos += buf.length;
  1425. }
  1426. return buffer;
  1427. };
  1428. // helpers
  1429. function coerce(length) {
  1430. // Coerce length to a number (possibly NaN), round up
  1431. // in case it's fractional (e.g. 123.456) then do a
  1432. // double negate to coerce a NaN to 0. Easy, right?
  1433. length = ~~Math.ceil(+length);
  1434. return length < 0 ? 0 : length;
  1435. }
  1436. function isArray(subject) {
  1437. return (Array.isArray ||
  1438. function(subject){
  1439. return {}.toString.apply(subject) == '[object Array]'
  1440. })
  1441. (subject)
  1442. }
  1443. function isArrayIsh(subject) {
  1444. return isArray(subject) || Buffer.isBuffer(subject) ||
  1445. subject && typeof subject === 'object' &&
  1446. typeof subject.length === 'number';
  1447. }
  1448. function toHex(n) {
  1449. if (n < 16) return '0' + n.toString(16);
  1450. return n.toString(16);
  1451. }
  1452. function utf8ToBytes(str) {
  1453. var byteArray = [];
  1454. for (var i = 0; i < str.length; i++)
  1455. if (str.charCodeAt(i) <= 0x7F)
  1456. byteArray.push(str.charCodeAt(i));
  1457. else {
  1458. var h = encodeURIComponent(str.charAt(i)).substr(1).split('%');
  1459. for (var j = 0; j < h.length; j++)
  1460. byteArray.push(parseInt(h[j], 16));
  1461. }
  1462. return byteArray;
  1463. }
  1464. function asciiToBytes(str) {
  1465. var byteArray = []
  1466. for (var i = 0; i < str.length; i++ )
  1467. // Node's code seems to be doing this and not & 0x7F..
  1468. byteArray.push( str.charCodeAt(i) & 0xFF );
  1469. return byteArray;
  1470. }
  1471. function base64ToBytes(str) {
  1472. return require("base64-js").toByteArray(str);
  1473. }
  1474. function blitBuffer(src, dst, offset, length) {
  1475. var pos, i = 0;
  1476. while (i < length) {
  1477. if ((i+offset >= dst.length) || (i >= src.length))
  1478. break;
  1479. dst[i + offset] = src[i];
  1480. i++;
  1481. }
  1482. return i;
  1483. }
  1484. function decodeUtf8Char(str) {
  1485. try {
  1486. return decodeURIComponent(str);
  1487. } catch (err) {
  1488. return String.fromCharCode(0xFFFD); // UTF 8 invalid char
  1489. }
  1490. }
  1491. // read/write bit-twiddling
  1492. Buffer.prototype.readUInt8 = function(offset, noAssert) {
  1493. var buffer = this;
  1494. if (!noAssert) {
  1495. assert.ok(offset !== undefined && offset !== null,
  1496. 'missing offset');
  1497. assert.ok(offset < buffer.length,
  1498. 'Trying to read beyond buffer length');
  1499. }
  1500. if (offset >= buffer.length) return;
  1501. return buffer[offset];
  1502. };
  1503. function readUInt16(buffer, offset, isBigEndian, noAssert) {
  1504. var val = 0;
  1505. if (!noAssert) {
  1506. assert.ok(typeof (isBigEndian) === 'boolean',
  1507. 'missing or invalid endian');
  1508. assert.ok(offset !== undefined && offset !== null,
  1509. 'missing offset');
  1510. assert.ok(offset + 1 < buffer.length,
  1511. 'Trying to read beyond buffer length');
  1512. }
  1513. if (offset >= buffer.length) return 0;
  1514. if (isBigEndian) {
  1515. val = buffer[offset] << 8;
  1516. if (offset + 1 < buffer.length) {
  1517. val |= buffer[offset + 1];
  1518. }
  1519. } else {
  1520. val = buffer[offset];
  1521. if (offset + 1 < buffer.length) {
  1522. val |= buffer[offset + 1] << 8;
  1523. }
  1524. }
  1525. return val;
  1526. }
  1527. Buffer.prototype.readUInt16LE = function(offset, noAssert) {
  1528. return readUInt16(this, offset, false, noAssert);
  1529. };
  1530. Buffer.prototype.readUInt16BE = function(offset, noAssert) {
  1531. return readUInt16(this, offset, true, noAssert);
  1532. };
  1533. function readUInt32(buffer, offset, isBigEndian, noAssert) {
  1534. var val = 0;
  1535. if (!noAssert) {
  1536. assert.ok(typeof (isBigEndian) === 'boolean',
  1537. 'missing or invalid endian');
  1538. assert.ok(offset !== undefined && offset !== null,
  1539. 'missing offset');
  1540. assert.ok(offset + 3 < buffer.length,
  1541. 'Trying to read beyond buffer length');
  1542. }
  1543. if (offset >= buffer.length) return 0;
  1544. if (isBigEndian) {
  1545. if (offset + 1 < buffer.length)
  1546. val = buffer[offset + 1] << 16;
  1547. if (offset + 2 < buffer.length)
  1548. val |= buffer[offset + 2] << 8;
  1549. if (offset + 3 < buffer.length)
  1550. val |= buffer[offset + 3];
  1551. val = val + (buffer[offset] << 24 >>> 0);
  1552. } else {
  1553. if (offset + 2 < buffer.length)
  1554. val = buffer[offset + 2] << 16;
  1555. if (offset + 1 < buffer.length)
  1556. val |= buffer[offset + 1] << 8;
  1557. val |= buffer[offset];
  1558. if (offset + 3 < buffer.length)
  1559. val = val + (buffer[offset + 3] << 24 >>> 0);
  1560. }
  1561. return val;
  1562. }
  1563. Buffer.prototype.readUInt32LE = function(offset, noAssert) {
  1564. return readUInt32(this, offset, false, noAssert);
  1565. };
  1566. Buffer.prototype.readUInt32BE = function(offset, noAssert) {
  1567. return readUInt32(this, offset, true, noAssert);
  1568. };
  1569. /*
  1570. * Signed integer types, yay team! A reminder on how two's complement actually
  1571. * works. The first bit is the signed bit, i.e. tells us whether or not the
  1572. * number should be positive or negative. If the two's complement value is
  1573. * positive, then we're done, as it's equivalent to the unsigned representation.
  1574. *
  1575. * Now if the number is positive, you're pretty much done, you can just leverage
  1576. * the unsigned translations and return those. Unfortunately, negative numbers
  1577. * aren't quite that straightforward.
  1578. *
  1579. * At first glance, one might be inclined to use the traditional formula to
  1580. * translate binary numbers between the positive and negative values in two's
  1581. * complement. (Though it doesn't quite work for the most negative value)
  1582. * Mainly:
  1583. * - invert all the bits
  1584. * - add one to the result
  1585. *
  1586. * Of course, this doesn't quite work in Javascript. Take for example the value
  1587. * of -128. This could be represented in 16 bits (big-endian) as 0xff80. But of
  1588. * course, Javascript will do the following:
  1589. *
  1590. * > ~0xff80
  1591. * -65409
  1592. *
  1593. * Whoh there, Javascript, that's not quite right. But wait, according to
  1594. * Javascript that's perfectly correct. When Javascript ends up seeing the
  1595. * constant 0xff80, it has no notion that it is actually a signed number. It
  1596. * assumes that we've input the unsigned value 0xff80. Thus, when it does the
  1597. * binary negation, it casts it into a signed value, (positive 0xff80). Then
  1598. * when you perform binary negation on that, it turns it into a negative number.
  1599. *
  1600. * Instead, we're going to have to use the following general formula, that works
  1601. * in a rather Javascript friendly way. I'm glad we don't support this kind of
  1602. * weird numbering scheme in the kernel.
  1603. *
  1604. * (BIT-MAX - (unsigned)val + 1) * -1
  1605. *
  1606. * The astute observer, may think that this doesn't make sense for 8-bit numbers
  1607. * (really it isn't necessary for them). However, when you get 16-bit numbers,
  1608. * you do. Let's go back to our prior example and see how this will look:
  1609. *
  1610. * (0xffff - 0xff80 + 1) * -1
  1611. * (0x007f + 1) * -1
  1612. * (0x0080) * -1
  1613. */
  1614. Buffer.prototype.readInt8 = function(offset, noAssert) {
  1615. var buffer = this;
  1616. var neg;
  1617. if (!noAssert) {
  1618. assert.ok(offset !== undefined && offset !== null,
  1619. 'missing offset');
  1620. assert.ok(offset < buffer.length,
  1621. 'Trying to read beyond buffer length');
  1622. }
  1623. if (offset >= buffer.length) return;
  1624. neg = buffer[offset] & 0x80;
  1625. if (!neg) {
  1626. return (buffer[offset]);
  1627. }
  1628. return ((0xff - buffer[offset] + 1) * -1);
  1629. };
  1630. function readInt16(buffer, offset, isBigEndian, noAssert) {
  1631. var neg, val;
  1632. if (!noAssert) {
  1633. assert.ok(typeof (isBigEndian) === 'boolean',
  1634. 'missing or invalid endian');
  1635. assert.ok(offset !== undefined && offset !== null,
  1636. 'missing offset');
  1637. assert.ok(offset + 1 < buffer.length,
  1638. 'Trying to read beyond buffer length');
  1639. }
  1640. val = readUInt16(buffer, offset, isBigEndian, noAssert);
  1641. neg = val & 0x8000;
  1642. if (!neg) {
  1643. return val;
  1644. }
  1645. return (0xffff - val + 1) * -1;
  1646. }
  1647. Buffer.prototype.readInt16LE = function(offset, noAssert) {
  1648. return readInt16(this, offset, false, noAssert);
  1649. };
  1650. Buffer.prototype.readInt16BE = function(offset, noAssert) {
  1651. return readInt16(this, offset, true, noAssert);
  1652. };
  1653. function readInt32(buffer, offset, isBigEndian, noAssert) {
  1654. var neg, val;
  1655. if (!noAssert) {
  1656. assert.ok(typeof (isBigEndian) === 'boolean',
  1657. 'missing or invalid endian');
  1658. assert.ok(offset !== undefined && offset !== null,
  1659. 'missing offset');
  1660. assert.ok(offset + 3 < buffer.length,
  1661. 'Trying to read beyond buffer length');
  1662. }
  1663. val = readUInt32(buffer, offset, isBigEndian, noAssert);
  1664. neg = val & 0x80000000;
  1665. if (!neg) {
  1666. return (val);
  1667. }
  1668. return (0xffffffff - val + 1) * -1;
  1669. }
  1670. Buffer.prototype.readInt32LE = function(offset, noAssert) {
  1671. return readInt32(this, offset, false, noAssert);
  1672. };
  1673. Buffer.prototype.readInt32BE = function(offset, noAssert) {
  1674. return readInt32(this, offset, true, noAssert);
  1675. };
  1676. function readFloat(buffer, offset, isBigEndian, noAssert) {
  1677. if (!noAssert) {
  1678. assert.ok(typeof (isBigEndian) === 'boolean',
  1679. 'missing or invalid endian');
  1680. assert.ok(offset + 3 < buffer.length,
  1681. 'Trying to read beyond buffer length');
  1682. }
  1683. return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
  1684. 23, 4);
  1685. }
  1686. Buffer.prototype.readFloatLE = function(offset, noAssert) {
  1687. return readFloat(this, offset, false, noAssert);
  1688. };
  1689. Buffer.prototype.readFloatBE = function(offset, noAssert) {
  1690. return readFloat(this, offset, true, noAssert);
  1691. };
  1692. function readDouble(buffer, offset, isBigEndian, noAssert) {
  1693. if (!noAssert) {
  1694. assert.ok(typeof (isBigEndian) === 'boolean',
  1695. 'missing or invalid endian');
  1696. assert.ok(offset + 7 < buffer.length,
  1697. 'Trying to read beyond buffer length');
  1698. }
  1699. return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
  1700. 52, 8);
  1701. }
  1702. Buffer.prototype.readDoubleLE = function(offset, noAssert) {
  1703. return readDouble(this, offset, false, noAssert);
  1704. };
  1705. Buffer.prototype.readDoubleBE = function(offset, noAssert) {
  1706. return readDouble(this, offset, true, noAssert);
  1707. };
  1708. /*
  1709. * We have to make sure that the value is a valid integer. This means that it is
  1710. * non-negative. It has no fractional component and that it does not exceed the
  1711. * maximum allowed value.
  1712. *
  1713. * value The number to check for validity
  1714. *
  1715. * max The maximum value
  1716. */
  1717. function verifuint(value, max) {
  1718. assert.ok(typeof (value) == 'number',
  1719. 'cannot write a non-number as a number');
  1720. assert.ok(value >= 0,
  1721. 'specified a negative value for writing an unsigned value');
  1722. assert.ok(value <= max, 'value is larger than maximum value for type');
  1723. assert.ok(Math.floor(value) === value, 'value has a fractional component');
  1724. }
  1725. Buffer.prototype.writeUInt8 = function(value, offset, noAssert) {
  1726. var buffer = this;
  1727. if (!noAssert) {
  1728. assert.ok(value !== undefined && value !== null,
  1729. 'missing value');
  1730. assert.ok(offset !== undefined && offset !== null,
  1731. 'missing offset');
  1732. assert.ok(offset < buffer.length,
  1733. 'trying to write beyond buffer length');
  1734. verifuint(value, 0xff);
  1735. }
  1736. if (offset < buffer.length) {
  1737. buffer[offset] = value;
  1738. }
  1739. };
  1740. function writeUInt16(buffer, value, offset, isBigEndian, noAssert) {
  1741. if (!noAssert) {
  1742. assert.ok(value !== undefined && value !== null,
  1743. 'missing value');
  1744. assert.ok(typeof (isBigEndian) === 'boolean',
  1745. 'missing or invalid endian');
  1746. assert.ok(offset !== undefined && offset !== null,
  1747. 'missing offset');
  1748. assert.ok(offset + 1 < buffer.length,
  1749. 'trying to write beyond buffer length');
  1750. verifuint(value, 0xffff);
  1751. }
  1752. for (var i = 0; i < Math.min(buffer.length - offset, 2); i++) {
  1753. buffer[offset + i] =
  1754. (value & (0xff << (8 * (isBigEndian ? 1 - i : i)))) >>>
  1755. (isBigEndian ? 1 - i : i) * 8;
  1756. }
  1757. }
  1758. Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) {
  1759. writeUInt16(this, value, offset, false, noAssert);
  1760. };
  1761. Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) {
  1762. writeUInt16(this, value, offset, true, noAssert);
  1763. };
  1764. function writeUInt32(buffer, value, offset, isBigEndian, noAssert) {
  1765. if (!noAssert) {
  1766. assert.ok(value !== undefined && value !== null,
  1767. 'missing value');
  1768. assert.ok(typeof (isBigEndian) === 'boolean',
  1769. 'missing or invalid endian');
  1770. assert.ok(offset !== undefined && offset !== null,
  1771. 'missing offset');
  1772. assert.ok(offset + 3 < buffer.length,
  1773. 'trying to write beyond buffer length');
  1774. verifuint(value, 0xffffffff);
  1775. }
  1776. for (var i = 0; i < Math.min(buffer.length - offset, 4); i++) {
  1777. buffer[offset + i] =
  1778. (value >>> (isBigEndian ? 3 - i : i) * 8) & 0xff;
  1779. }
  1780. }
  1781. Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) {
  1782. writeUInt32(this, value, offset, false, noAssert);
  1783. };
  1784. Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) {
  1785. writeUInt32(this, value, offset, true, noAssert);
  1786. };
  1787. /*
  1788. * We now move onto our friends in the signed number category. Unlike unsigned
  1789. * numbers, we're going to have to worry a bit more about how we put values into
  1790. * arrays. Since we are only worrying about signed 32-bit values, we're in
  1791. * slightly better shape. Unfortunately, we really can't do our favorite binary
  1792. * & in this system. It really seems to do the wrong thing. For example:
  1793. *
  1794. * > -32 & 0xff
  1795. * 224
  1796. *
  1797. * What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of
  1798. * this aren't treated as a signed number. Ultimately a bad thing.
  1799. *
  1800. * What we're going to want to do is basically create the unsigned equivalent of
  1801. * our representation and pass that off to the wuint* functions. To do that
  1802. * we're going to do the following:
  1803. *
  1804. * - if the value is positive
  1805. * we can pass it directly off to the equivalent wuint
  1806. * - if the value is negative
  1807. * we do the following computation:
  1808. * mb + val + 1, where
  1809. * mb is the maximum unsigned value in that byte size
  1810. * val is the Javascript negative integer
  1811. *
  1812. *
  1813. * As a concrete value, take -128. In signed 16 bits this would be 0xff80. If
  1814. * you do out the computations:
  1815. *
  1816. * 0xffff - 128 + 1
  1817. * 0xffff - 127
  1818. * 0xff80
  1819. *
  1820. * You can then encode this value as the signed version. This is really rather
  1821. * hacky, but it should work and get the job done which is our goal here.
  1822. */
  1823. /*
  1824. * A series of checks to make sure we actually have a signed 32-bit number
  1825. */
  1826. function verifsint(value, max, min) {
  1827. assert.ok(typeof (value) == 'number',
  1828. 'cannot write a non-number as a number');
  1829. assert.ok(value <= max, 'value larger than maximum allowed value');
  1830. assert.ok(value >= min, 'value smaller than minimum allowed value');
  1831. assert.ok(Math.floor(value) === value, 'value has a fractional component');
  1832. }
  1833. function verifIEEE754(value, max, min) {
  1834. assert.ok(typeof (value) == 'number',
  1835. 'cannot write a non-number as a number');
  1836. assert.ok(value <= max, 'value larger than maximum allowed value');
  1837. assert.ok(value >= min, 'value smaller than minimum allowed value');
  1838. }
  1839. Buffer.prototype.writeInt8 = function(value, offset, noAssert) {
  1840. var buffer = this;
  1841. if (!noAssert) {
  1842. assert.ok(value !== undefined && value !== null,
  1843. 'missing value');
  1844. assert.ok(offset !== undefined && offset !== null,
  1845. 'missing offset');
  1846. assert.ok(offset < buffer.length,
  1847. 'Trying to write beyond buffer length');
  1848. verifsint(value, 0x7f, -0x80);
  1849. }
  1850. if (value >= 0) {
  1851. buffer.writeUInt8(value, offset, noAssert);
  1852. } else {
  1853. buffer.writeUInt8(0xff + value + 1, offset, noAssert);
  1854. }
  1855. };
  1856. function writeInt16(buffer, value, offset, isBigEndian, noAssert) {
  1857. if (!noAssert) {
  1858. assert.ok(value !== undefined && value !== null,
  1859. 'missing value');
  1860. assert.ok(typeof (isBigEndian) === 'boolean',
  1861. 'missing or invalid endian');
  1862. assert.ok(offset !== undefined && offset !== null,
  1863. 'missing offset');
  1864. assert.ok(offset + 1 < buffer.length,
  1865. 'Trying to write beyond buffer length');
  1866. verifsint(value, 0x7fff, -0x8000);
  1867. }
  1868. if (value >= 0) {
  1869. writeUInt16(buffer, value, offset, isBigEndian, noAssert);
  1870. } else {
  1871. writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert);
  1872. }
  1873. }
  1874. Buffer.prototype.writeInt16LE = function(value, offset, noAssert) {
  1875. writeInt16(this, value, offset, false, noAssert);
  1876. };
  1877. Buffer.prototype.writeInt16BE = function(value, offset, noAssert) {
  1878. writeInt16(this, value, offset, true, noAssert);
  1879. };
  1880. function writeInt32(buffer, value, offset, isBigEndian, noAssert) {
  1881. if (!noAssert) {
  1882. assert.ok(value !== undefined && value !== null,
  1883. 'missing value');
  1884. assert.ok(typeof (isBigEndian) === 'boolean',
  1885. 'missing or invalid endian');
  1886. assert.ok(offset !== undefined && offset !== null,
  1887. 'missing offset');
  1888. assert.ok(offset + 3 < buffer.length,
  1889. 'Trying to write beyond buffer length');
  1890. verifsint(value, 0x7fffffff, -0x80000000);
  1891. }
  1892. if (value >= 0) {
  1893. writeUInt32(buffer, value, offset, isBigEndian, noAssert);
  1894. } else {
  1895. writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert);
  1896. }
  1897. }
  1898. Buffer.prototype.writeInt32LE = function(value, offset, noAssert) {
  1899. writeInt32(this, value, offset, false, noAssert);
  1900. };
  1901. Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {
  1902. writeInt32(this, value, offset, true, noAssert);
  1903. };
  1904. function writeFloat(buffer, value, offset, isBigEndian, noAssert) {
  1905. if (!noAssert) {
  1906. assert.ok(value !== undefined && value !== null,
  1907. 'missing value');
  1908. assert.ok(typeof (isBigEndian) === 'boolean',
  1909. 'missing or invalid endian');
  1910. assert.ok(offset !== undefined && offset !== null,
  1911. 'missing offset');
  1912. assert.ok(offset + 3 < buffer.length,
  1913. 'Trying to write beyond buffer length');
  1914. verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38);
  1915. }
  1916. require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
  1917. 23, 4);
  1918. }
  1919. Buffer.prototype.writeFloatLE = function(value, offset, noAssert) {
  1920. writeFloat(this, value, offset, false, noAssert);
  1921. };
  1922. Buffer.prototype.writeFloatBE = function(value, offset, noAssert) {
  1923. writeFloat(this, value, offset, true, noAssert);
  1924. };
  1925. function writeDouble(buffer, value, offset, isBigEndian, noAssert) {
  1926. if (!noAssert) {
  1927. assert.ok(value !== undefined && value !== null,
  1928. 'missing value');
  1929. assert.ok(typeof (isBigEndian) === 'boolean',
  1930. 'missing or invalid endian');
  1931. assert.ok(offset !== undefined && offset !== null,
  1932. 'missing offset');
  1933. assert.ok(offset + 7 < buffer.length,
  1934. 'Trying to write beyond buffer length');
  1935. verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308);
  1936. }
  1937. require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
  1938. 52, 8);
  1939. }
  1940. Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) {
  1941. writeDouble(this, value, offset, false, noAssert);
  1942. };
  1943. Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) {
  1944. writeDouble(this, value, offset, true, noAssert);
  1945. };
  1946. },{"./buffer_ieee754":8,"assert":5,"base64-js":4}],10:[function(require,module,exports){
  1947. var Buffer = require('buffer').Buffer;
  1948. var intSize = 4;
  1949. var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0);
  1950. var chrsz = 8;
  1951. function toArray(buf, bigEndian) {
  1952. if ((buf.length % intSize) !== 0) {
  1953. var len = buf.length + (intSize - (buf.length % intSize));
  1954. buf = Buffer.concat([buf, zeroBuffer], len);
  1955. }
  1956. var arr = [];
  1957. var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE;
  1958. for (var i = 0; i < buf.length; i += intSize) {
  1959. arr.push(fn.call(buf, i));
  1960. }
  1961. return arr;
  1962. }
  1963. function toBuffer(arr, size, bigEndian) {
  1964. var buf = new Buffer(size);
  1965. var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE;
  1966. for (var i = 0; i < arr.length; i++) {
  1967. fn.call(buf, arr[i], i * 4, true);
  1968. }
  1969. return buf;
  1970. }
  1971. function hash(buf, fn, hashSize, bigEndian) {
  1972. if (!Buffer.isBuffer(buf)) buf = new Buffer(buf);
  1973. var arr = fn(toArray(buf, bigEndian), buf.length * chrsz);
  1974. return toBuffer(arr, hashSize, bigEndian);
  1975. }
  1976. module.exports = { hash: hash };
  1977. },{"buffer":9}],11:[function(require,module,exports){
  1978. var Buffer = require('buffer').Buffer
  1979. var sha = require('./sha')
  1980. var sha256 = require('./sha256')
  1981. var rng = require('./rng')
  1982. var md5 = require('./md5')
  1983. var algorithms = {
  1984. sha1: sha,
  1985. sha256: sha256,
  1986. md5: md5
  1987. }
  1988. var blocksize = 64
  1989. var zeroBuffer = new Buffer(blocksize); zeroBuffer.fill(0)
  1990. function hmac(fn, key, data) {
  1991. if(!Buffer.isBuffer(key)) key = new Buffer(key)
  1992. if(!Buffer.isBuffer(data)) data = new Buffer(data)
  1993. if(key.length > blocksize) {
  1994. key = fn(key)
  1995. } else if(key.length < blocksize) {
  1996. key = Buffer.concat([key, zeroBuffer], blocksize)
  1997. }
  1998. var ipad = new Buffer(blocksize), opad = new Buffer(blocksize)
  1999. for(var i = 0; i < blocksize; i++) {
  2000. ipad[i] = key[i] ^ 0x36
  2001. opad[i] = key[i] ^ 0x5C
  2002. }
  2003. var hash = fn(Buffer.concat([ipad, data]))
  2004. return fn(Buffer.concat([opad, hash]))
  2005. }
  2006. function hash(alg, key) {
  2007. alg = alg || 'sha1'
  2008. var fn = algorithms[alg]
  2009. var bufs = []
  2010. var length = 0
  2011. if(!fn) error('algorithm:', alg, 'is not yet supported')
  2012. return {
  2013. update: function (data) {
  2014. if(!Buffer.isBuffer(data)) data = new Buffer(data)
  2015. bufs.push(data)
  2016. length += data.length
  2017. return this
  2018. },
  2019. digest: function (enc) {
  2020. var buf = Buffer.concat(bufs)
  2021. var r = key ? hmac(fn, key, buf) : fn(buf)
  2022. bufs = null
  2023. return enc ? r.toString(enc) : r
  2024. }
  2025. }
  2026. }
  2027. function error () {
  2028. var m = [].slice.call(arguments).join(' ')
  2029. throw new Error([
  2030. m,
  2031. 'we accept pull requests',
  2032. 'http://github.com/dominictarr/crypto-browserify'
  2033. ].join('\n'))
  2034. }
  2035. exports.createHash = function (alg) { return hash(alg) }
  2036. exports.createHmac = function (alg, key) { return hash(alg, key) }
  2037. exports.randomBytes = function(size, callback) {
  2038. if (callback && callback.call) {
  2039. try {
  2040. callback.call(this, undefined, new Buffer(rng(size)))
  2041. } catch (err) { callback(err) }
  2042. } else {
  2043. return new Buffer(rng(size))
  2044. }
  2045. }
  2046. function each(a, f) {
  2047. for(var i in a)
  2048. f(a[i], i)
  2049. }
  2050. // the least I can do is make error messages for the rest of the node.js/crypto api.
  2051. each(['createCredentials'
  2052. , 'createCipher'
  2053. , 'createCipheriv'
  2054. , 'createDecipher'
  2055. , 'createDecipheriv'
  2056. , 'createSign'
  2057. , 'createVerify'
  2058. , 'createDiffieHellman'
  2059. , 'pbkdf2'], function (name) {
  2060. exports[name] = function () {
  2061. error('sorry,', name, 'is not implemented yet')
  2062. }
  2063. })
  2064. },{"./md5":12,"./rng":13,"./sha":14,"./sha256":15,"buffer":9}],12:[function(require,module,exports){
  2065. /*
  2066. * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
  2067. * Digest Algorithm, as defined in RFC 1321.
  2068. * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
  2069. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  2070. * Distributed under the BSD License
  2071. * See http://pajhome.org.uk/crypt/md5 for more info.
  2072. */
  2073. var helpers = require('./helpers');
  2074. /*
  2075. * Perform a simple self-test to see if the VM is working
  2076. */
  2077. function md5_vm_test()
  2078. {
  2079. return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
  2080. }
  2081. /*
  2082. * Calculate the MD5 of an array of little-endian words, and a bit length
  2083. */
  2084. function core_md5(x, len)
  2085. {
  2086. /* append padding */
  2087. x[len >> 5] |= 0x80 << ((len) % 32);
  2088. x[(((len + 64) >>> 9) << 4) + 14] = len;
  2089. var a = 1732584193;
  2090. var b = -271733879;
  2091. var c = -1732584194;
  2092. var d = 271733878;
  2093. for(var i = 0; i < x.length; i += 16)
  2094. {
  2095. var olda = a;
  2096. var oldb = b;
  2097. var oldc = c;
  2098. var oldd = d;
  2099. a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
  2100. d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
  2101. c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
  2102. b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
  2103. a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
  2104. d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
  2105. c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
  2106. b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
  2107. a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
  2108. d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
  2109. c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
  2110. b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
  2111. a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
  2112. d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
  2113. c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
  2114. b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
  2115. a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
  2116. d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
  2117. c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
  2118. b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
  2119. a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
  2120. d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
  2121. c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
  2122. b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
  2123. a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
  2124. d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
  2125. c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
  2126. b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
  2127. a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
  2128. d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
  2129. c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
  2130. b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
  2131. a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
  2132. d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
  2133. c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
  2134. b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
  2135. a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
  2136. d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
  2137. c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
  2138. b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
  2139. a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
  2140. d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
  2141. c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
  2142. b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
  2143. a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
  2144. d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
  2145. c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
  2146. b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
  2147. a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
  2148. d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
  2149. c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
  2150. b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
  2151. a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
  2152. d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
  2153. c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
  2154. b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
  2155. a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
  2156. d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
  2157. c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
  2158. b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
  2159. a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
  2160. d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
  2161. c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
  2162. b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
  2163. a = safe_add(a, olda);
  2164. b = safe_add(b, oldb);
  2165. c = safe_add(c, oldc);
  2166. d = safe_add(d, oldd);
  2167. }
  2168. return Array(a, b, c, d);
  2169. }
  2170. /*
  2171. * These functions implement the four basic operations the algorithm uses.
  2172. */
  2173. function md5_cmn(q, a, b, x, s, t)
  2174. {
  2175. return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
  2176. }
  2177. function md5_ff(a, b, c, d, x, s, t)
  2178. {
  2179. return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
  2180. }
  2181. function md5_gg(a, b, c, d, x, s, t)
  2182. {
  2183. return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
  2184. }
  2185. function md5_hh(a, b, c, d, x, s, t)
  2186. {
  2187. return md5_cmn(b ^ c ^ d, a, b, x, s, t);
  2188. }
  2189. function md5_ii(a, b, c, d, x, s, t)
  2190. {
  2191. return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
  2192. }
  2193. /*
  2194. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  2195. * to work around bugs in some JS interpreters.
  2196. */
  2197. function safe_add(x, y)
  2198. {
  2199. var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  2200. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  2201. return (msw << 16) | (lsw & 0xFFFF);
  2202. }
  2203. /*
  2204. * Bitwise rotate a 32-bit number to the left.
  2205. */
  2206. function bit_rol(num, cnt)
  2207. {
  2208. return (num << cnt) | (num >>> (32 - cnt));
  2209. }
  2210. module.exports = function md5(buf) {
  2211. return helpers.hash(buf, core_md5, 16);
  2212. };
  2213. },{"./helpers":10}],13:[function(require,module,exports){
  2214. // Original code adapted from Robert Kieffer.
  2215. // details at https://github.com/broofa/node-uuid
  2216. (function() {
  2217. var _global = this;
  2218. var mathRNG, whatwgRNG;
  2219. // NOTE: Math.random() does not guarantee "cryptographic quality"
  2220. mathRNG = function(size) {
  2221. var bytes = new Array(size);
  2222. var r;
  2223. for (var i = 0, r; i < size; i++) {
  2224. if ((i & 0x03) == 0) r = Math.random() * 0x100000000;
  2225. bytes[i] = r >>> ((i & 0x03) << 3) & 0xff;
  2226. }
  2227. return bytes;
  2228. }
  2229. if (_global.crypto && crypto.getRandomValues) {
  2230. whatwgRNG = function(size) {
  2231. var bytes = new Uint8Array(size);
  2232. crypto.getRandomValues(bytes);
  2233. return bytes;
  2234. }
  2235. }
  2236. module.exports = whatwgRNG || mathRNG;
  2237. }())
  2238. },{}],14:[function(require,module,exports){
  2239. /*
  2240. * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
  2241. * in FIPS PUB 180-1
  2242. * Version 2.1a Copyright Paul Johnston 2000 - 2002.
  2243. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  2244. * Distributed under the BSD License
  2245. * See http://pajhome.org.uk/crypt/md5 for details.
  2246. */
  2247. var helpers = require('./helpers');
  2248. /*
  2249. * Calculate the SHA-1 of an array of big-endian words, and a bit length
  2250. */
  2251. function core_sha1(x, len)
  2252. {
  2253. /* append padding */
  2254. x[len >> 5] |= 0x80 << (24 - len % 32);
  2255. x[((len + 64 >> 9) << 4) + 15] = len;
  2256. var w = Array(80);
  2257. var a = 1732584193;
  2258. var b = -271733879;
  2259. var c = -1732584194;
  2260. var d = 271733878;
  2261. var e = -1009589776;
  2262. for(var i = 0; i < x.length; i += 16)
  2263. {
  2264. var olda = a;
  2265. var oldb = b;
  2266. var oldc = c;
  2267. var oldd = d;
  2268. var olde = e;
  2269. for(var j = 0; j < 80; j++)
  2270. {
  2271. if(j < 16) w[j] = x[i + j];
  2272. else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
  2273. var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
  2274. safe_add(safe_add(e, w[j]), sha1_kt(j)));
  2275. e = d;
  2276. d = c;
  2277. c = rol(b, 30);
  2278. b = a;
  2279. a = t;
  2280. }
  2281. a = safe_add(a, olda);
  2282. b = safe_add(b, oldb);
  2283. c = safe_add(c, oldc);
  2284. d = safe_add(d, oldd);
  2285. e = safe_add(e, olde);
  2286. }
  2287. return Array(a, b, c, d, e);
  2288. }
  2289. /*
  2290. * Perform the appropriate triplet combination function for the current
  2291. * iteration
  2292. */
  2293. function sha1_ft(t, b, c, d)
  2294. {
  2295. if(t < 20) return (b & c) | ((~b) & d);
  2296. if(t < 40) return b ^ c ^ d;
  2297. if(t < 60) return (b & c) | (b & d) | (c & d);
  2298. return b ^ c ^ d;
  2299. }
  2300. /*
  2301. * Determine the appropriate additive constant for the current iteration
  2302. */
  2303. function sha1_kt(t)
  2304. {
  2305. return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
  2306. (t < 60) ? -1894007588 : -899497514;
  2307. }
  2308. /*
  2309. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  2310. * to work around bugs in some JS interpreters.
  2311. */
  2312. function safe_add(x, y)
  2313. {
  2314. var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  2315. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  2316. return (msw << 16) | (lsw & 0xFFFF);
  2317. }
  2318. /*
  2319. * Bitwise rotate a 32-bit number to the left.
  2320. */
  2321. function rol(num, cnt)
  2322. {
  2323. return (num << cnt) | (num >>> (32 - cnt));
  2324. }
  2325. module.exports = function sha1(buf) {
  2326. return helpers.hash(buf, core_sha1, 20, true);
  2327. };
  2328. },{"./helpers":10}],15:[function(require,module,exports){
  2329. /**
  2330. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  2331. * in FIPS 180-2
  2332. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  2333. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  2334. *
  2335. */
  2336. var helpers = require('./helpers');
  2337. var safe_add = function(x, y) {
  2338. var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  2339. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  2340. return (msw << 16) | (lsw & 0xFFFF);
  2341. };
  2342. var S = function(X, n) {
  2343. return (X >>> n) | (X << (32 - n));
  2344. };
  2345. var R = function(X, n) {
  2346. return (X >>> n);
  2347. };
  2348. var Ch = function(x, y, z) {
  2349. return ((x & y) ^ ((~x) & z));
  2350. };
  2351. var Maj = function(x, y, z) {
  2352. return ((x & y) ^ (x & z) ^ (y & z));
  2353. };
  2354. var Sigma0256 = function(x) {
  2355. return (S(x, 2) ^ S(x, 13) ^ S(x, 22));
  2356. };
  2357. var Sigma1256 = function(x) {
  2358. return (S(x, 6) ^ S(x, 11) ^ S(x, 25));
  2359. };
  2360. var Gamma0256 = function(x) {
  2361. return (S(x, 7) ^ S(x, 18) ^ R(x, 3));
  2362. };
  2363. var Gamma1256 = function(x) {
  2364. return (S(x, 17) ^ S(x, 19) ^ R(x, 10));
  2365. };
  2366. var core_sha256 = function(m, l) {
  2367. var K = new Array(0x428A2F98,0x71374491,0xB5C0FBCF,0xE9B5DBA5,0x3956C25B,0x59F111F1,0x923F82A4,0xAB1C5ED5,0xD807AA98,0x12835B01,0x243185BE,0x550C7DC3,0x72BE5D74,0x80DEB1FE,0x9BDC06A7,0xC19BF174,0xE49B69C1,0xEFBE4786,0xFC19DC6,0x240CA1CC,0x2DE92C6F,0x4A7484AA,0x5CB0A9DC,0x76F988DA,0x983E5152,0xA831C66D,0xB00327C8,0xBF597FC7,0xC6E00BF3,0xD5A79147,0x6CA6351,0x14292967,0x27B70A85,0x2E1B2138,0x4D2C6DFC,0x53380D13,0x650A7354,0x766A0ABB,0x81C2C92E,0x92722C85,0xA2BFE8A1,0xA81A664B,0xC24B8B70,0xC76C51A3,0xD192E819,0xD6990624,0xF40E3585,0x106AA070,0x19A4C116,0x1E376C08,0x2748774C,0x34B0BCB5,0x391C0CB3,0x4ED8AA4A,0x5B9CCA4F,0x682E6FF3,0x748F82EE,0x78A5636F,0x84C87814,0x8CC70208,0x90BEFFFA,0xA4506CEB,0xBEF9A3F7,0xC67178F2);
  2368. var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19);
  2369. var W = new Array(64);
  2370. var a, b, c, d, e, f, g, h, i, j;
  2371. var T1, T2;
  2372. /* append padding */
  2373. m[l >> 5] |= 0x80 << (24 - l % 32);
  2374. m[((l + 64 >> 9) << 4) + 15] = l;
  2375. for (var i = 0; i < m.length; i += 16) {
  2376. a = HASH[0]; b = HASH[1]; c = HASH[2]; d = HASH[3]; e = HASH[4]; f = HASH[5]; g = HASH[6]; h = HASH[7];
  2377. for (var j = 0; j < 64; j++) {
  2378. if (j < 16) {
  2379. W[j] = m[j + i];
  2380. } else {
  2381. W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);
  2382. }
  2383. T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);
  2384. T2 = safe_add(Sigma0256(a), Maj(a, b, c));
  2385. h = g; g = f; f = e; e = safe_add(d, T1); d = c; c = b; b = a; a = safe_add(T1, T2);
  2386. }
  2387. HASH[0] = safe_add(a, HASH[0]); HASH[1] = safe_add(b, HASH[1]); HASH[2] = safe_add(c, HASH[2]); HASH[3] = safe_add(d, HASH[3]);
  2388. HASH[4] = safe_add(e, HASH[4]); HASH[5] = safe_add(f, HASH[5]); HASH[6] = safe_add(g, HASH[6]); HASH[7] = safe_add(h, HASH[7]);
  2389. }
  2390. return HASH;
  2391. };
  2392. module.exports = function sha256(buf) {
  2393. return helpers.hash(buf, core_sha256, 32, true);
  2394. };
  2395. },{"./helpers":10}],16:[function(require,module,exports){
  2396. ;(function (root, factory, undef) {
  2397. if (typeof exports === "object") {
  2398. // CommonJS
  2399. module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
  2400. }
  2401. else if (typeof define === "function" && define.amd) {
  2402. // AMD
  2403. define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
  2404. }
  2405. else {
  2406. // Global (browser)
  2407. factory(root.CryptoJS);
  2408. }
  2409. }(this, function (CryptoJS) {
  2410. (function () {
  2411. // Shortcuts
  2412. var C = CryptoJS;
  2413. var C_lib = C.lib;
  2414. var BlockCipher = C_lib.BlockCipher;
  2415. var C_algo = C.algo;
  2416. // Lookup tables
  2417. var SBOX = [];
  2418. var INV_SBOX = [];
  2419. var SUB_MIX_0 = [];
  2420. var SUB_MIX_1 = [];
  2421. var SUB_MIX_2 = [];
  2422. var SUB_MIX_3 = [];
  2423. var INV_SUB_MIX_0 = [];
  2424. var INV_SUB_MIX_1 = [];
  2425. var INV_SUB_MIX_2 = [];
  2426. var INV_SUB_MIX_3 = [];
  2427. // Compute lookup tables
  2428. (function () {
  2429. // Compute double table
  2430. var d = [];
  2431. for (var i = 0; i < 256; i++) {
  2432. if (i < 128) {
  2433. d[i] = i << 1;
  2434. } else {
  2435. d[i] = (i << 1) ^ 0x11b;
  2436. }
  2437. }
  2438. // Walk GF(2^8)
  2439. var x = 0;
  2440. var xi = 0;
  2441. for (var i = 0; i < 256; i++) {
  2442. // Compute sbox
  2443. var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
  2444. sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
  2445. SBOX[x] = sx;
  2446. INV_SBOX[sx] = x;
  2447. // Compute multiplication
  2448. var x2 = d[x];
  2449. var x4 = d[x2];
  2450. var x8 = d[x4];
  2451. // Compute sub bytes, mix columns tables
  2452. var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
  2453. SUB_MIX_0[x] = (t << 24) | (t >>> 8);
  2454. SUB_MIX_1[x] = (t << 16) | (t >>> 16);
  2455. SUB_MIX_2[x] = (t << 8) | (t >>> 24);
  2456. SUB_MIX_3[x] = t;
  2457. // Compute inv sub bytes, inv mix columns tables
  2458. var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
  2459. INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
  2460. INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
  2461. INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
  2462. INV_SUB_MIX_3[sx] = t;
  2463. // Compute next counter
  2464. if (!x) {
  2465. x = xi = 1;
  2466. } else {
  2467. x = x2 ^ d[d[d[x8 ^ x2]]];
  2468. xi ^= d[d[xi]];
  2469. }
  2470. }
  2471. }());
  2472. // Precomputed Rcon lookup
  2473. var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
  2474. /**
  2475. * AES block cipher algorithm.
  2476. */
  2477. var AES = C_algo.AES = BlockCipher.extend({
  2478. _doReset: function () {
  2479. // Skip reset of nRounds has been set before and key did not change
  2480. if (this._nRounds && this._keyPriorReset === this._key) {
  2481. return;
  2482. }
  2483. // Shortcuts
  2484. var key = this._keyPriorReset = this._key;
  2485. var keyWords = key.words;
  2486. var keySize = key.sigBytes / 4;
  2487. // Compute number of rounds
  2488. var nRounds = this._nRounds = keySize + 6;
  2489. // Compute number of key schedule rows
  2490. var ksRows = (nRounds + 1) * 4;
  2491. // Compute key schedule
  2492. var keySchedule = this._keySchedule = [];
  2493. for (var ksRow = 0; ksRow < ksRows; ksRow++) {
  2494. if (ksRow < keySize) {
  2495. keySchedule[ksRow] = keyWords[ksRow];
  2496. } else {
  2497. var t = keySchedule[ksRow - 1];
  2498. if (!(ksRow % keySize)) {
  2499. // Rot word
  2500. t = (t << 8) | (t >>> 24);
  2501. // Sub word
  2502. t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  2503. // Mix Rcon
  2504. t ^= RCON[(ksRow / keySize) | 0] << 24;
  2505. } else if (keySize > 6 && ksRow % keySize == 4) {
  2506. // Sub word
  2507. t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
  2508. }
  2509. keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
  2510. }
  2511. }
  2512. // Compute inv key schedule
  2513. var invKeySchedule = this._invKeySchedule = [];
  2514. for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
  2515. var ksRow = ksRows - invKsRow;
  2516. if (invKsRow % 4) {
  2517. var t = keySchedule[ksRow];
  2518. } else {
  2519. var t = keySchedule[ksRow - 4];
  2520. }
  2521. if (invKsRow < 4 || ksRow <= 4) {
  2522. invKeySchedule[invKsRow] = t;
  2523. } else {
  2524. invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
  2525. INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
  2526. }
  2527. }
  2528. },
  2529. encryptBlock: function (M, offset) {
  2530. this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
  2531. },
  2532. decryptBlock: function (M, offset) {
  2533. // Swap 2nd and 4th rows
  2534. var t = M[offset + 1];
  2535. M[offset + 1] = M[offset + 3];
  2536. M[offset + 3] = t;
  2537. this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
  2538. // Inv swap 2nd and 4th rows
  2539. var t = M[offset + 1];
  2540. M[offset + 1] = M[offset + 3];
  2541. M[offset + 3] = t;
  2542. },
  2543. _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
  2544. // Shortcut
  2545. var nRounds = this._nRounds;
  2546. // Get input, add round key
  2547. var s0 = M[offset] ^ keySchedule[0];
  2548. var s1 = M[offset + 1] ^ keySchedule[1];
  2549. var s2 = M[offset + 2] ^ keySchedule[2];
  2550. var s3 = M[offset + 3] ^ keySchedule[3];
  2551. // Key schedule row counter
  2552. var ksRow = 4;
  2553. // Rounds
  2554. for (var round = 1; round < nRounds; round++) {
  2555. // Shift rows, sub bytes, mix columns, add round key
  2556. var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++];
  2557. var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++];
  2558. var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++];
  2559. var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++];
  2560. // Update state
  2561. s0 = t0;
  2562. s1 = t1;
  2563. s2 = t2;
  2564. s3 = t3;
  2565. }
  2566. // Shift rows, sub bytes, add round key
  2567. var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
  2568. var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
  2569. var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
  2570. var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
  2571. // Set output
  2572. M[offset] = t0;
  2573. M[offset + 1] = t1;
  2574. M[offset + 2] = t2;
  2575. M[offset + 3] = t3;
  2576. },
  2577. keySize: 256/32
  2578. });
  2579. /**
  2580. * Shortcut functions to the cipher's object interface.
  2581. *
  2582. * @example
  2583. *
  2584. * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
  2585. * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
  2586. */
  2587. C.AES = BlockCipher._createHelper(AES);
  2588. }());
  2589. return CryptoJS.AES;
  2590. }));
  2591. },{"./cipher-core":17,"./core":18,"./enc-base64":19,"./evpkdf":23,"./md5":26}],17:[function(require,module,exports){
  2592. ;(function (root, factory) {
  2593. if (typeof exports === "object") {
  2594. // CommonJS
  2595. module.exports = exports = factory(require("./core"));
  2596. }
  2597. else if (typeof define === "function" && define.amd) {
  2598. // AMD
  2599. define(["./core"], factory);
  2600. }
  2601. else {
  2602. // Global (browser)
  2603. factory(root.CryptoJS);
  2604. }
  2605. }(this, function (CryptoJS) {
  2606. /**
  2607. * Cipher core components.
  2608. */
  2609. CryptoJS.lib.Cipher || (function (undefined) {
  2610. // Shortcuts
  2611. var C = CryptoJS;
  2612. var C_lib = C.lib;
  2613. var Base = C_lib.Base;
  2614. var WordArray = C_lib.WordArray;
  2615. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
  2616. var C_enc = C.enc;
  2617. var Utf8 = C_enc.Utf8;
  2618. var Base64 = C_enc.Base64;
  2619. var C_algo = C.algo;
  2620. var EvpKDF = C_algo.EvpKDF;
  2621. /**
  2622. * Abstract base cipher template.
  2623. *
  2624. * @property {number} keySize This cipher's key size. Default: 4 (128 bits)
  2625. * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
  2626. * @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
  2627. * @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
  2628. */
  2629. var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
  2630. /**
  2631. * Configuration options.
  2632. *
  2633. * @property {WordArray} iv The IV to use for this operation.
  2634. */
  2635. cfg: Base.extend(),
  2636. /**
  2637. * Creates this cipher in encryption mode.
  2638. *
  2639. * @param {WordArray} key The key.
  2640. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  2641. *
  2642. * @return {Cipher} A cipher instance.
  2643. *
  2644. * @static
  2645. *
  2646. * @example
  2647. *
  2648. * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
  2649. */
  2650. createEncryptor: function (key, cfg) {
  2651. return this.create(this._ENC_XFORM_MODE, key, cfg);
  2652. },
  2653. /**
  2654. * Creates this cipher in decryption mode.
  2655. *
  2656. * @param {WordArray} key The key.
  2657. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  2658. *
  2659. * @return {Cipher} A cipher instance.
  2660. *
  2661. * @static
  2662. *
  2663. * @example
  2664. *
  2665. * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
  2666. */
  2667. createDecryptor: function (key, cfg) {
  2668. return this.create(this._DEC_XFORM_MODE, key, cfg);
  2669. },
  2670. /**
  2671. * Initializes a newly created cipher.
  2672. *
  2673. * @param {number} xformMode Either the encryption or decryption transormation mode constant.
  2674. * @param {WordArray} key The key.
  2675. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  2676. *
  2677. * @example
  2678. *
  2679. * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
  2680. */
  2681. init: function (xformMode, key, cfg) {
  2682. // Apply config defaults
  2683. this.cfg = this.cfg.extend(cfg);
  2684. // Store transform mode and key
  2685. this._xformMode = xformMode;
  2686. this._key = key;
  2687. // Set initial values
  2688. this.reset();
  2689. },
  2690. /**
  2691. * Resets this cipher to its initial state.
  2692. *
  2693. * @example
  2694. *
  2695. * cipher.reset();
  2696. */
  2697. reset: function () {
  2698. // Reset data buffer
  2699. BufferedBlockAlgorithm.reset.call(this);
  2700. // Perform concrete-cipher logic
  2701. this._doReset();
  2702. },
  2703. /**
  2704. * Adds data to be encrypted or decrypted.
  2705. *
  2706. * @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
  2707. *
  2708. * @return {WordArray} The data after processing.
  2709. *
  2710. * @example
  2711. *
  2712. * var encrypted = cipher.process('data');
  2713. * var encrypted = cipher.process(wordArray);
  2714. */
  2715. process: function (dataUpdate) {
  2716. // Append
  2717. this._append(dataUpdate);
  2718. // Process available blocks
  2719. return this._process();
  2720. },
  2721. /**
  2722. * Finalizes the encryption or decryption process.
  2723. * Note that the finalize operation is effectively a destructive, read-once operation.
  2724. *
  2725. * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
  2726. *
  2727. * @return {WordArray} The data after final processing.
  2728. *
  2729. * @example
  2730. *
  2731. * var encrypted = cipher.finalize();
  2732. * var encrypted = cipher.finalize('data');
  2733. * var encrypted = cipher.finalize(wordArray);
  2734. */
  2735. finalize: function (dataUpdate) {
  2736. // Final data update
  2737. if (dataUpdate) {
  2738. this._append(dataUpdate);
  2739. }
  2740. // Perform concrete-cipher logic
  2741. var finalProcessedData = this._doFinalize();
  2742. return finalProcessedData;
  2743. },
  2744. keySize: 128/32,
  2745. ivSize: 128/32,
  2746. _ENC_XFORM_MODE: 1,
  2747. _DEC_XFORM_MODE: 2,
  2748. /**
  2749. * Creates shortcut functions to a cipher's object interface.
  2750. *
  2751. * @param {Cipher} cipher The cipher to create a helper for.
  2752. *
  2753. * @return {Object} An object with encrypt and decrypt shortcut functions.
  2754. *
  2755. * @static
  2756. *
  2757. * @example
  2758. *
  2759. * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
  2760. */
  2761. _createHelper: (function () {
  2762. function selectCipherStrategy(key) {
  2763. if (typeof key == 'string') {
  2764. return PasswordBasedCipher;
  2765. } else {
  2766. return SerializableCipher;
  2767. }
  2768. }
  2769. return function (cipher) {
  2770. return {
  2771. encrypt: function (message, key, cfg) {
  2772. return selectCipherStrategy(key).encrypt(cipher, message, key, cfg);
  2773. },
  2774. decrypt: function (ciphertext, key, cfg) {
  2775. return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg);
  2776. }
  2777. };
  2778. };
  2779. }())
  2780. });
  2781. /**
  2782. * Abstract base stream cipher template.
  2783. *
  2784. * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
  2785. */
  2786. var StreamCipher = C_lib.StreamCipher = Cipher.extend({
  2787. _doFinalize: function () {
  2788. // Process partial blocks
  2789. var finalProcessedBlocks = this._process(!!'flush');
  2790. return finalProcessedBlocks;
  2791. },
  2792. blockSize: 1
  2793. });
  2794. /**
  2795. * Mode namespace.
  2796. */
  2797. var C_mode = C.mode = {};
  2798. /**
  2799. * Abstract base block cipher mode template.
  2800. */
  2801. var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({
  2802. /**
  2803. * Creates this mode for encryption.
  2804. *
  2805. * @param {Cipher} cipher A block cipher instance.
  2806. * @param {Array} iv The IV words.
  2807. *
  2808. * @static
  2809. *
  2810. * @example
  2811. *
  2812. * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
  2813. */
  2814. createEncryptor: function (cipher, iv) {
  2815. return this.Encryptor.create(cipher, iv);
  2816. },
  2817. /**
  2818. * Creates this mode for decryption.
  2819. *
  2820. * @param {Cipher} cipher A block cipher instance.
  2821. * @param {Array} iv The IV words.
  2822. *
  2823. * @static
  2824. *
  2825. * @example
  2826. *
  2827. * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
  2828. */
  2829. createDecryptor: function (cipher, iv) {
  2830. return this.Decryptor.create(cipher, iv);
  2831. },
  2832. /**
  2833. * Initializes a newly created mode.
  2834. *
  2835. * @param {Cipher} cipher A block cipher instance.
  2836. * @param {Array} iv The IV words.
  2837. *
  2838. * @example
  2839. *
  2840. * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
  2841. */
  2842. init: function (cipher, iv) {
  2843. this._cipher = cipher;
  2844. this._iv = iv;
  2845. }
  2846. });
  2847. /**
  2848. * Cipher Block Chaining mode.
  2849. */
  2850. var CBC = C_mode.CBC = (function () {
  2851. /**
  2852. * Abstract base CBC mode.
  2853. */
  2854. var CBC = BlockCipherMode.extend();
  2855. /**
  2856. * CBC encryptor.
  2857. */
  2858. CBC.Encryptor = CBC.extend({
  2859. /**
  2860. * Processes the data block at offset.
  2861. *
  2862. * @param {Array} words The data words to operate on.
  2863. * @param {number} offset The offset where the block starts.
  2864. *
  2865. * @example
  2866. *
  2867. * mode.processBlock(data.words, offset);
  2868. */
  2869. processBlock: function (words, offset) {
  2870. // Shortcuts
  2871. var cipher = this._cipher;
  2872. var blockSize = cipher.blockSize;
  2873. // XOR and encrypt
  2874. xorBlock.call(this, words, offset, blockSize);
  2875. cipher.encryptBlock(words, offset);
  2876. // Remember this block to use with next block
  2877. this._prevBlock = words.slice(offset, offset + blockSize);
  2878. }
  2879. });
  2880. /**
  2881. * CBC decryptor.
  2882. */
  2883. CBC.Decryptor = CBC.extend({
  2884. /**
  2885. * Processes the data block at offset.
  2886. *
  2887. * @param {Array} words The data words to operate on.
  2888. * @param {number} offset The offset where the block starts.
  2889. *
  2890. * @example
  2891. *
  2892. * mode.processBlock(data.words, offset);
  2893. */
  2894. processBlock: function (words, offset) {
  2895. // Shortcuts
  2896. var cipher = this._cipher;
  2897. var blockSize = cipher.blockSize;
  2898. // Remember this block to use with next block
  2899. var thisBlock = words.slice(offset, offset + blockSize);
  2900. // Decrypt and XOR
  2901. cipher.decryptBlock(words, offset);
  2902. xorBlock.call(this, words, offset, blockSize);
  2903. // This block becomes the previous block
  2904. this._prevBlock = thisBlock;
  2905. }
  2906. });
  2907. function xorBlock(words, offset, blockSize) {
  2908. // Shortcut
  2909. var iv = this._iv;
  2910. // Choose mixing block
  2911. if (iv) {
  2912. var block = iv;
  2913. // Remove IV for subsequent blocks
  2914. this._iv = undefined;
  2915. } else {
  2916. var block = this._prevBlock;
  2917. }
  2918. // XOR blocks
  2919. for (var i = 0; i < blockSize; i++) {
  2920. words[offset + i] ^= block[i];
  2921. }
  2922. }
  2923. return CBC;
  2924. }());
  2925. /**
  2926. * Padding namespace.
  2927. */
  2928. var C_pad = C.pad = {};
  2929. /**
  2930. * PKCS #5/7 padding strategy.
  2931. */
  2932. var Pkcs7 = C_pad.Pkcs7 = {
  2933. /**
  2934. * Pads data using the algorithm defined in PKCS #5/7.
  2935. *
  2936. * @param {WordArray} data The data to pad.
  2937. * @param {number} blockSize The multiple that the data should be padded to.
  2938. *
  2939. * @static
  2940. *
  2941. * @example
  2942. *
  2943. * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
  2944. */
  2945. pad: function (data, blockSize) {
  2946. // Shortcut
  2947. var blockSizeBytes = blockSize * 4;
  2948. // Count padding bytes
  2949. var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  2950. // Create padding word
  2951. var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes;
  2952. // Create padding
  2953. var paddingWords = [];
  2954. for (var i = 0; i < nPaddingBytes; i += 4) {
  2955. paddingWords.push(paddingWord);
  2956. }
  2957. var padding = WordArray.create(paddingWords, nPaddingBytes);
  2958. // Add padding
  2959. data.concat(padding);
  2960. },
  2961. /**
  2962. * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
  2963. *
  2964. * @param {WordArray} data The data to unpad.
  2965. *
  2966. * @static
  2967. *
  2968. * @example
  2969. *
  2970. * CryptoJS.pad.Pkcs7.unpad(wordArray);
  2971. */
  2972. unpad: function (data) {
  2973. // Get number of padding bytes from last byte
  2974. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  2975. // Remove padding
  2976. data.sigBytes -= nPaddingBytes;
  2977. }
  2978. };
  2979. /**
  2980. * Abstract base block cipher template.
  2981. *
  2982. * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
  2983. */
  2984. var BlockCipher = C_lib.BlockCipher = Cipher.extend({
  2985. /**
  2986. * Configuration options.
  2987. *
  2988. * @property {Mode} mode The block mode to use. Default: CBC
  2989. * @property {Padding} padding The padding strategy to use. Default: Pkcs7
  2990. */
  2991. cfg: Cipher.cfg.extend({
  2992. mode: CBC,
  2993. padding: Pkcs7
  2994. }),
  2995. reset: function () {
  2996. // Reset cipher
  2997. Cipher.reset.call(this);
  2998. // Shortcuts
  2999. var cfg = this.cfg;
  3000. var iv = cfg.iv;
  3001. var mode = cfg.mode;
  3002. // Reset block mode
  3003. if (this._xformMode == this._ENC_XFORM_MODE) {
  3004. var modeCreator = mode.createEncryptor;
  3005. } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  3006. var modeCreator = mode.createDecryptor;
  3007. // Keep at least one block in the buffer for unpadding
  3008. this._minBufferSize = 1;
  3009. }
  3010. this._mode = modeCreator.call(mode, this, iv && iv.words);
  3011. },
  3012. _doProcessBlock: function (words, offset) {
  3013. this._mode.processBlock(words, offset);
  3014. },
  3015. _doFinalize: function () {
  3016. // Shortcut
  3017. var padding = this.cfg.padding;
  3018. // Finalize
  3019. if (this._xformMode == this._ENC_XFORM_MODE) {
  3020. // Pad data
  3021. padding.pad(this._data, this.blockSize);
  3022. // Process final blocks
  3023. var finalProcessedBlocks = this._process(!!'flush');
  3024. } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
  3025. // Process final blocks
  3026. var finalProcessedBlocks = this._process(!!'flush');
  3027. // Unpad data
  3028. padding.unpad(finalProcessedBlocks);
  3029. }
  3030. return finalProcessedBlocks;
  3031. },
  3032. blockSize: 128/32
  3033. });
  3034. /**
  3035. * A collection of cipher parameters.
  3036. *
  3037. * @property {WordArray} ciphertext The raw ciphertext.
  3038. * @property {WordArray} key The key to this ciphertext.
  3039. * @property {WordArray} iv The IV used in the ciphering operation.
  3040. * @property {WordArray} salt The salt used with a key derivation function.
  3041. * @property {Cipher} algorithm The cipher algorithm.
  3042. * @property {Mode} mode The block mode used in the ciphering operation.
  3043. * @property {Padding} padding The padding scheme used in the ciphering operation.
  3044. * @property {number} blockSize The block size of the cipher.
  3045. * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
  3046. */
  3047. var CipherParams = C_lib.CipherParams = Base.extend({
  3048. /**
  3049. * Initializes a newly created cipher params object.
  3050. *
  3051. * @param {Object} cipherParams An object with any of the possible cipher parameters.
  3052. *
  3053. * @example
  3054. *
  3055. * var cipherParams = CryptoJS.lib.CipherParams.create({
  3056. * ciphertext: ciphertextWordArray,
  3057. * key: keyWordArray,
  3058. * iv: ivWordArray,
  3059. * salt: saltWordArray,
  3060. * algorithm: CryptoJS.algo.AES,
  3061. * mode: CryptoJS.mode.CBC,
  3062. * padding: CryptoJS.pad.PKCS7,
  3063. * blockSize: 4,
  3064. * formatter: CryptoJS.format.OpenSSL
  3065. * });
  3066. */
  3067. init: function (cipherParams) {
  3068. this.mixIn(cipherParams);
  3069. },
  3070. /**
  3071. * Converts this cipher params object to a string.
  3072. *
  3073. * @param {Format} formatter (Optional) The formatting strategy to use.
  3074. *
  3075. * @return {string} The stringified cipher params.
  3076. *
  3077. * @throws Error If neither the formatter nor the default formatter is set.
  3078. *
  3079. * @example
  3080. *
  3081. * var string = cipherParams + '';
  3082. * var string = cipherParams.toString();
  3083. * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
  3084. */
  3085. toString: function (formatter) {
  3086. return (formatter || this.formatter).stringify(this);
  3087. }
  3088. });
  3089. /**
  3090. * Format namespace.
  3091. */
  3092. var C_format = C.format = {};
  3093. /**
  3094. * OpenSSL formatting strategy.
  3095. */
  3096. var OpenSSLFormatter = C_format.OpenSSL = {
  3097. /**
  3098. * Converts a cipher params object to an OpenSSL-compatible string.
  3099. *
  3100. * @param {CipherParams} cipherParams The cipher params object.
  3101. *
  3102. * @return {string} The OpenSSL-compatible string.
  3103. *
  3104. * @static
  3105. *
  3106. * @example
  3107. *
  3108. * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
  3109. */
  3110. stringify: function (cipherParams) {
  3111. // Shortcuts
  3112. var ciphertext = cipherParams.ciphertext;
  3113. var salt = cipherParams.salt;
  3114. // Format
  3115. if (salt) {
  3116. var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
  3117. } else {
  3118. var wordArray = ciphertext;
  3119. }
  3120. return wordArray.toString(Base64);
  3121. },
  3122. /**
  3123. * Converts an OpenSSL-compatible string to a cipher params object.
  3124. *
  3125. * @param {string} openSSLStr The OpenSSL-compatible string.
  3126. *
  3127. * @return {CipherParams} The cipher params object.
  3128. *
  3129. * @static
  3130. *
  3131. * @example
  3132. *
  3133. * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
  3134. */
  3135. parse: function (openSSLStr) {
  3136. // Parse base64
  3137. var ciphertext = Base64.parse(openSSLStr);
  3138. // Shortcut
  3139. var ciphertextWords = ciphertext.words;
  3140. // Test for salt
  3141. if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) {
  3142. // Extract salt
  3143. var salt = WordArray.create(ciphertextWords.slice(2, 4));
  3144. // Remove salt from ciphertext
  3145. ciphertextWords.splice(0, 4);
  3146. ciphertext.sigBytes -= 16;
  3147. }
  3148. return CipherParams.create({ ciphertext: ciphertext, salt: salt });
  3149. }
  3150. };
  3151. /**
  3152. * A cipher wrapper that returns ciphertext as a serializable cipher params object.
  3153. */
  3154. var SerializableCipher = C_lib.SerializableCipher = Base.extend({
  3155. /**
  3156. * Configuration options.
  3157. *
  3158. * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
  3159. */
  3160. cfg: Base.extend({
  3161. format: OpenSSLFormatter
  3162. }),
  3163. /**
  3164. * Encrypts a message.
  3165. *
  3166. * @param {Cipher} cipher The cipher algorithm to use.
  3167. * @param {WordArray|string} message The message to encrypt.
  3168. * @param {WordArray} key The key.
  3169. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3170. *
  3171. * @return {CipherParams} A cipher params object.
  3172. *
  3173. * @static
  3174. *
  3175. * @example
  3176. *
  3177. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
  3178. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
  3179. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  3180. */
  3181. encrypt: function (cipher, message, key, cfg) {
  3182. // Apply config defaults
  3183. cfg = this.cfg.extend(cfg);
  3184. // Encrypt
  3185. var encryptor = cipher.createEncryptor(key, cfg);
  3186. var ciphertext = encryptor.finalize(message);
  3187. // Shortcut
  3188. var cipherCfg = encryptor.cfg;
  3189. // Create and return serializable cipher params
  3190. return CipherParams.create({
  3191. ciphertext: ciphertext,
  3192. key: key,
  3193. iv: cipherCfg.iv,
  3194. algorithm: cipher,
  3195. mode: cipherCfg.mode,
  3196. padding: cipherCfg.padding,
  3197. blockSize: cipher.blockSize,
  3198. formatter: cfg.format
  3199. });
  3200. },
  3201. /**
  3202. * Decrypts serialized ciphertext.
  3203. *
  3204. * @param {Cipher} cipher The cipher algorithm to use.
  3205. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  3206. * @param {WordArray} key The key.
  3207. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3208. *
  3209. * @return {WordArray} The plaintext.
  3210. *
  3211. * @static
  3212. *
  3213. * @example
  3214. *
  3215. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  3216. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  3217. */
  3218. decrypt: function (cipher, ciphertext, key, cfg) {
  3219. // Apply config defaults
  3220. cfg = this.cfg.extend(cfg);
  3221. // Convert string to CipherParams
  3222. ciphertext = this._parse(ciphertext, cfg.format);
  3223. // Decrypt
  3224. var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
  3225. return plaintext;
  3226. },
  3227. /**
  3228. * Converts serialized ciphertext to CipherParams,
  3229. * else assumed CipherParams already and returns ciphertext unchanged.
  3230. *
  3231. * @param {CipherParams|string} ciphertext The ciphertext.
  3232. * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
  3233. *
  3234. * @return {CipherParams} The unserialized ciphertext.
  3235. *
  3236. * @static
  3237. *
  3238. * @example
  3239. *
  3240. * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
  3241. */
  3242. _parse: function (ciphertext, format) {
  3243. if (typeof ciphertext == 'string') {
  3244. return format.parse(ciphertext, this);
  3245. } else {
  3246. return ciphertext;
  3247. }
  3248. }
  3249. });
  3250. /**
  3251. * Key derivation function namespace.
  3252. */
  3253. var C_kdf = C.kdf = {};
  3254. /**
  3255. * OpenSSL key derivation function.
  3256. */
  3257. var OpenSSLKdf = C_kdf.OpenSSL = {
  3258. /**
  3259. * Derives a key and IV from a password.
  3260. *
  3261. * @param {string} password The password to derive from.
  3262. * @param {number} keySize The size in words of the key to generate.
  3263. * @param {number} ivSize The size in words of the IV to generate.
  3264. * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
  3265. *
  3266. * @return {CipherParams} A cipher params object with the key, IV, and salt.
  3267. *
  3268. * @static
  3269. *
  3270. * @example
  3271. *
  3272. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
  3273. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
  3274. */
  3275. execute: function (password, keySize, ivSize, salt) {
  3276. // Generate random salt
  3277. if (!salt) {
  3278. salt = WordArray.random(64/8);
  3279. }
  3280. // Derive key and IV
  3281. var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
  3282. // Separate key and IV
  3283. var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
  3284. key.sigBytes = keySize * 4;
  3285. // Return params
  3286. return CipherParams.create({ key: key, iv: iv, salt: salt });
  3287. }
  3288. };
  3289. /**
  3290. * A serializable cipher wrapper that derives the key from a password,
  3291. * and returns ciphertext as a serializable cipher params object.
  3292. */
  3293. var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
  3294. /**
  3295. * Configuration options.
  3296. *
  3297. * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
  3298. */
  3299. cfg: SerializableCipher.cfg.extend({
  3300. kdf: OpenSSLKdf
  3301. }),
  3302. /**
  3303. * Encrypts a message using a password.
  3304. *
  3305. * @param {Cipher} cipher The cipher algorithm to use.
  3306. * @param {WordArray|string} message The message to encrypt.
  3307. * @param {string} password The password.
  3308. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3309. *
  3310. * @return {CipherParams} A cipher params object.
  3311. *
  3312. * @static
  3313. *
  3314. * @example
  3315. *
  3316. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
  3317. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
  3318. */
  3319. encrypt: function (cipher, message, password, cfg) {
  3320. // Apply config defaults
  3321. cfg = this.cfg.extend(cfg);
  3322. // Derive key and other params
  3323. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize);
  3324. // Add IV to config
  3325. cfg.iv = derivedParams.iv;
  3326. // Encrypt
  3327. var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
  3328. // Mix in derived params
  3329. ciphertext.mixIn(derivedParams);
  3330. return ciphertext;
  3331. },
  3332. /**
  3333. * Decrypts serialized ciphertext using a password.
  3334. *
  3335. * @param {Cipher} cipher The cipher algorithm to use.
  3336. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  3337. * @param {string} password The password.
  3338. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  3339. *
  3340. * @return {WordArray} The plaintext.
  3341. *
  3342. * @static
  3343. *
  3344. * @example
  3345. *
  3346. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
  3347. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
  3348. */
  3349. decrypt: function (cipher, ciphertext, password, cfg) {
  3350. // Apply config defaults
  3351. cfg = this.cfg.extend(cfg);
  3352. // Convert string to CipherParams
  3353. ciphertext = this._parse(ciphertext, cfg.format);
  3354. // Derive key and other params
  3355. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt);
  3356. // Add IV to config
  3357. cfg.iv = derivedParams.iv;
  3358. // Decrypt
  3359. var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg);
  3360. return plaintext;
  3361. }
  3362. });
  3363. }());
  3364. }));
  3365. },{"./core":18}],18:[function(require,module,exports){
  3366. ;(function (root, factory) {
  3367. if (typeof exports === "object") {
  3368. // CommonJS
  3369. module.exports = exports = factory();
  3370. }
  3371. else if (typeof define === "function" && define.amd) {
  3372. // AMD
  3373. define([], factory);
  3374. }
  3375. else {
  3376. // Global (browser)
  3377. root.CryptoJS = factory();
  3378. }
  3379. }(this, function () {
  3380. /**
  3381. * CryptoJS core components.
  3382. */
  3383. var CryptoJS = CryptoJS || (function (Math, undefined) {
  3384. /*
  3385. * Local polyfil of Object.create
  3386. */
  3387. var create = Object.create || (function () {
  3388. function F() {};
  3389. return function (obj) {
  3390. var subtype;
  3391. F.prototype = obj;
  3392. subtype = new F();
  3393. F.prototype = null;
  3394. return subtype;
  3395. };
  3396. }())
  3397. /**
  3398. * CryptoJS namespace.
  3399. */
  3400. var C = {};
  3401. /**
  3402. * Library namespace.
  3403. */
  3404. var C_lib = C.lib = {};
  3405. /**
  3406. * Base object for prototypal inheritance.
  3407. */
  3408. var Base = C_lib.Base = (function () {
  3409. return {
  3410. /**
  3411. * Creates a new object that inherits from this object.
  3412. *
  3413. * @param {Object} overrides Properties to copy into the new object.
  3414. *
  3415. * @return {Object} The new object.
  3416. *
  3417. * @static
  3418. *
  3419. * @example
  3420. *
  3421. * var MyType = CryptoJS.lib.Base.extend({
  3422. * field: 'value',
  3423. *
  3424. * method: function () {
  3425. * }
  3426. * });
  3427. */
  3428. extend: function (overrides) {
  3429. // Spawn
  3430. var subtype = create(this);
  3431. // Augment
  3432. if (overrides) {
  3433. subtype.mixIn(overrides);
  3434. }
  3435. // Create default initializer
  3436. if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
  3437. subtype.init = function () {
  3438. subtype.$super.init.apply(this, arguments);
  3439. };
  3440. }
  3441. // Initializer's prototype is the subtype object
  3442. subtype.init.prototype = subtype;
  3443. // Reference supertype
  3444. subtype.$super = this;
  3445. return subtype;
  3446. },
  3447. /**
  3448. * Extends this object and runs the init method.
  3449. * Arguments to create() will be passed to init().
  3450. *
  3451. * @return {Object} The new object.
  3452. *
  3453. * @static
  3454. *
  3455. * @example
  3456. *
  3457. * var instance = MyType.create();
  3458. */
  3459. create: function () {
  3460. var instance = this.extend();
  3461. instance.init.apply(instance, arguments);
  3462. return instance;
  3463. },
  3464. /**
  3465. * Initializes a newly created object.
  3466. * Override this method to add some logic when your objects are created.
  3467. *
  3468. * @example
  3469. *
  3470. * var MyType = CryptoJS.lib.Base.extend({
  3471. * init: function () {
  3472. * // ...
  3473. * }
  3474. * });
  3475. */
  3476. init: function () {
  3477. },
  3478. /**
  3479. * Copies properties into this object.
  3480. *
  3481. * @param {Object} properties The properties to mix in.
  3482. *
  3483. * @example
  3484. *
  3485. * MyType.mixIn({
  3486. * field: 'value'
  3487. * });
  3488. */
  3489. mixIn: function (properties) {
  3490. for (var propertyName in properties) {
  3491. if (properties.hasOwnProperty(propertyName)) {
  3492. this[propertyName] = properties[propertyName];
  3493. }
  3494. }
  3495. // IE won't copy toString using the loop above
  3496. if (properties.hasOwnProperty('toString')) {
  3497. this.toString = properties.toString;
  3498. }
  3499. },
  3500. /**
  3501. * Creates a copy of this object.
  3502. *
  3503. * @return {Object} The clone.
  3504. *
  3505. * @example
  3506. *
  3507. * var clone = instance.clone();
  3508. */
  3509. clone: function () {
  3510. return this.init.prototype.extend(this);
  3511. }
  3512. };
  3513. }());
  3514. /**
  3515. * An array of 32-bit words.
  3516. *
  3517. * @property {Array} words The array of 32-bit words.
  3518. * @property {number} sigBytes The number of significant bytes in this word array.
  3519. */
  3520. var WordArray = C_lib.WordArray = Base.extend({
  3521. /**
  3522. * Initializes a newly created word array.
  3523. *
  3524. * @param {Array} words (Optional) An array of 32-bit words.
  3525. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  3526. *
  3527. * @example
  3528. *
  3529. * var wordArray = CryptoJS.lib.WordArray.create();
  3530. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
  3531. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
  3532. */
  3533. init: function (words, sigBytes) {
  3534. words = this.words = words || [];
  3535. if (sigBytes != undefined) {
  3536. this.sigBytes = sigBytes;
  3537. } else {
  3538. this.sigBytes = words.length * 4;
  3539. }
  3540. },
  3541. /**
  3542. * Converts this word array to a string.
  3543. *
  3544. * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
  3545. *
  3546. * @return {string} The stringified word array.
  3547. *
  3548. * @example
  3549. *
  3550. * var string = wordArray + '';
  3551. * var string = wordArray.toString();
  3552. * var string = wordArray.toString(CryptoJS.enc.Utf8);
  3553. */
  3554. toString: function (encoder) {
  3555. return (encoder || Hex).stringify(this);
  3556. },
  3557. /**
  3558. * Concatenates a word array to this word array.
  3559. *
  3560. * @param {WordArray} wordArray The word array to append.
  3561. *
  3562. * @return {WordArray} This word array.
  3563. *
  3564. * @example
  3565. *
  3566. * wordArray1.concat(wordArray2);
  3567. */
  3568. concat: function (wordArray) {
  3569. // Shortcuts
  3570. var thisWords = this.words;
  3571. var thatWords = wordArray.words;
  3572. var thisSigBytes = this.sigBytes;
  3573. var thatSigBytes = wordArray.sigBytes;
  3574. // Clamp excess bits
  3575. this.clamp();
  3576. // Concat
  3577. if (thisSigBytes % 4) {
  3578. // Copy one byte at a time
  3579. for (var i = 0; i < thatSigBytes; i++) {
  3580. var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  3581. thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
  3582. }
  3583. } else {
  3584. // Copy one word at a time
  3585. for (var i = 0; i < thatSigBytes; i += 4) {
  3586. thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2];
  3587. }
  3588. }
  3589. this.sigBytes += thatSigBytes;
  3590. // Chainable
  3591. return this;
  3592. },
  3593. /**
  3594. * Removes insignificant bits.
  3595. *
  3596. * @example
  3597. *
  3598. * wordArray.clamp();
  3599. */
  3600. clamp: function () {
  3601. // Shortcuts
  3602. var words = this.words;
  3603. var sigBytes = this.sigBytes;
  3604. // Clamp
  3605. words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
  3606. words.length = Math.ceil(sigBytes / 4);
  3607. },
  3608. /**
  3609. * Creates a copy of this word array.
  3610. *
  3611. * @return {WordArray} The clone.
  3612. *
  3613. * @example
  3614. *
  3615. * var clone = wordArray.clone();
  3616. */
  3617. clone: function () {
  3618. var clone = Base.clone.call(this);
  3619. clone.words = this.words.slice(0);
  3620. return clone;
  3621. },
  3622. /**
  3623. * Creates a word array filled with random bytes.
  3624. *
  3625. * @param {number} nBytes The number of random bytes to generate.
  3626. *
  3627. * @return {WordArray} The random word array.
  3628. *
  3629. * @static
  3630. *
  3631. * @example
  3632. *
  3633. * var wordArray = CryptoJS.lib.WordArray.random(16);
  3634. */
  3635. random: function (nBytes) {
  3636. var words = [];
  3637. var r = (function (m_w) {
  3638. var m_w = m_w;
  3639. var m_z = 0x3ade68b1;
  3640. var mask = 0xffffffff;
  3641. return function () {
  3642. m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
  3643. m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
  3644. var result = ((m_z << 0x10) + m_w) & mask;
  3645. result /= 0x100000000;
  3646. result += 0.5;
  3647. return result * (Math.random() > .5 ? 1 : -1);
  3648. }
  3649. });
  3650. for (var i = 0, rcache; i < nBytes; i += 4) {
  3651. var _r = r((rcache || Math.random()) * 0x100000000);
  3652. rcache = _r() * 0x3ade67b7;
  3653. words.push((_r() * 0x100000000) | 0);
  3654. }
  3655. return new WordArray.init(words, nBytes);
  3656. }
  3657. });
  3658. /**
  3659. * Encoder namespace.
  3660. */
  3661. var C_enc = C.enc = {};
  3662. /**
  3663. * Hex encoding strategy.
  3664. */
  3665. var Hex = C_enc.Hex = {
  3666. /**
  3667. * Converts a word array to a hex string.
  3668. *
  3669. * @param {WordArray} wordArray The word array.
  3670. *
  3671. * @return {string} The hex string.
  3672. *
  3673. * @static
  3674. *
  3675. * @example
  3676. *
  3677. * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
  3678. */
  3679. stringify: function (wordArray) {
  3680. // Shortcuts
  3681. var words = wordArray.words;
  3682. var sigBytes = wordArray.sigBytes;
  3683. // Convert
  3684. var hexChars = [];
  3685. for (var i = 0; i < sigBytes; i++) {
  3686. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  3687. hexChars.push((bite >>> 4).toString(16));
  3688. hexChars.push((bite & 0x0f).toString(16));
  3689. }
  3690. return hexChars.join('');
  3691. },
  3692. /**
  3693. * Converts a hex string to a word array.
  3694. *
  3695. * @param {string} hexStr The hex string.
  3696. *
  3697. * @return {WordArray} The word array.
  3698. *
  3699. * @static
  3700. *
  3701. * @example
  3702. *
  3703. * var wordArray = CryptoJS.enc.Hex.parse(hexString);
  3704. */
  3705. parse: function (hexStr) {
  3706. // Shortcut
  3707. var hexStrLength = hexStr.length;
  3708. // Convert
  3709. var words = [];
  3710. for (var i = 0; i < hexStrLength; i += 2) {
  3711. words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
  3712. }
  3713. return new WordArray.init(words, hexStrLength / 2);
  3714. }
  3715. };
  3716. /**
  3717. * Latin1 encoding strategy.
  3718. */
  3719. var Latin1 = C_enc.Latin1 = {
  3720. /**
  3721. * Converts a word array to a Latin1 string.
  3722. *
  3723. * @param {WordArray} wordArray The word array.
  3724. *
  3725. * @return {string} The Latin1 string.
  3726. *
  3727. * @static
  3728. *
  3729. * @example
  3730. *
  3731. * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
  3732. */
  3733. stringify: function (wordArray) {
  3734. // Shortcuts
  3735. var words = wordArray.words;
  3736. var sigBytes = wordArray.sigBytes;
  3737. // Convert
  3738. var latin1Chars = [];
  3739. for (var i = 0; i < sigBytes; i++) {
  3740. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  3741. latin1Chars.push(String.fromCharCode(bite));
  3742. }
  3743. return latin1Chars.join('');
  3744. },
  3745. /**
  3746. * Converts a Latin1 string to a word array.
  3747. *
  3748. * @param {string} latin1Str The Latin1 string.
  3749. *
  3750. * @return {WordArray} The word array.
  3751. *
  3752. * @static
  3753. *
  3754. * @example
  3755. *
  3756. * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
  3757. */
  3758. parse: function (latin1Str) {
  3759. // Shortcut
  3760. var latin1StrLength = latin1Str.length;
  3761. // Convert
  3762. var words = [];
  3763. for (var i = 0; i < latin1StrLength; i++) {
  3764. words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
  3765. }
  3766. return new WordArray.init(words, latin1StrLength);
  3767. }
  3768. };
  3769. /**
  3770. * UTF-8 encoding strategy.
  3771. */
  3772. var Utf8 = C_enc.Utf8 = {
  3773. /**
  3774. * Converts a word array to a UTF-8 string.
  3775. *
  3776. * @param {WordArray} wordArray The word array.
  3777. *
  3778. * @return {string} The UTF-8 string.
  3779. *
  3780. * @static
  3781. *
  3782. * @example
  3783. *
  3784. * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
  3785. */
  3786. stringify: function (wordArray) {
  3787. try {
  3788. return decodeURIComponent(escape(Latin1.stringify(wordArray)));
  3789. } catch (e) {
  3790. throw new Error('Malformed UTF-8 data');
  3791. }
  3792. },
  3793. /**
  3794. * Converts a UTF-8 string to a word array.
  3795. *
  3796. * @param {string} utf8Str The UTF-8 string.
  3797. *
  3798. * @return {WordArray} The word array.
  3799. *
  3800. * @static
  3801. *
  3802. * @example
  3803. *
  3804. * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
  3805. */
  3806. parse: function (utf8Str) {
  3807. return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
  3808. }
  3809. };
  3810. /**
  3811. * Abstract buffered block algorithm template.
  3812. *
  3813. * The property blockSize must be implemented in a concrete subtype.
  3814. *
  3815. * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
  3816. */
  3817. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
  3818. /**
  3819. * Resets this block algorithm's data buffer to its initial state.
  3820. *
  3821. * @example
  3822. *
  3823. * bufferedBlockAlgorithm.reset();
  3824. */
  3825. reset: function () {
  3826. // Initial values
  3827. this._data = new WordArray.init();
  3828. this._nDataBytes = 0;
  3829. },
  3830. /**
  3831. * Adds new data to this block algorithm's buffer.
  3832. *
  3833. * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
  3834. *
  3835. * @example
  3836. *
  3837. * bufferedBlockAlgorithm._append('data');
  3838. * bufferedBlockAlgorithm._append(wordArray);
  3839. */
  3840. _append: function (data) {
  3841. // Convert string to WordArray, else assume WordArray already
  3842. if (typeof data == 'string') {
  3843. data = Utf8.parse(data);
  3844. }
  3845. // Append
  3846. this._data.concat(data);
  3847. this._nDataBytes += data.sigBytes;
  3848. },
  3849. /**
  3850. * Processes available data blocks.
  3851. *
  3852. * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
  3853. *
  3854. * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
  3855. *
  3856. * @return {WordArray} The processed data.
  3857. *
  3858. * @example
  3859. *
  3860. * var processedData = bufferedBlockAlgorithm._process();
  3861. * var processedData = bufferedBlockAlgorithm._process(!!'flush');
  3862. */
  3863. _process: function (doFlush) {
  3864. // Shortcuts
  3865. var data = this._data;
  3866. var dataWords = data.words;
  3867. var dataSigBytes = data.sigBytes;
  3868. var blockSize = this.blockSize;
  3869. var blockSizeBytes = blockSize * 4;
  3870. // Count blocks ready
  3871. var nBlocksReady = dataSigBytes / blockSizeBytes;
  3872. if (doFlush) {
  3873. // Round up to include partial blocks
  3874. nBlocksReady = Math.ceil(nBlocksReady);
  3875. } else {
  3876. // Round down to include only full blocks,
  3877. // less the number of blocks that must remain in the buffer
  3878. nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
  3879. }
  3880. // Count words ready
  3881. var nWordsReady = nBlocksReady * blockSize;
  3882. // Count bytes ready
  3883. var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
  3884. // Process blocks
  3885. if (nWordsReady) {
  3886. for (var offset = 0; offset < nWordsReady; offset += blockSize) {
  3887. // Perform concrete-algorithm logic
  3888. this._doProcessBlock(dataWords, offset);
  3889. }
  3890. // Remove processed words
  3891. var processedWords = dataWords.splice(0, nWordsReady);
  3892. data.sigBytes -= nBytesReady;
  3893. }
  3894. // Return processed words
  3895. return new WordArray.init(processedWords, nBytesReady);
  3896. },
  3897. /**
  3898. * Creates a copy of this object.
  3899. *
  3900. * @return {Object} The clone.
  3901. *
  3902. * @example
  3903. *
  3904. * var clone = bufferedBlockAlgorithm.clone();
  3905. */
  3906. clone: function () {
  3907. var clone = Base.clone.call(this);
  3908. clone._data = this._data.clone();
  3909. return clone;
  3910. },
  3911. _minBufferSize: 0
  3912. });
  3913. /**
  3914. * Abstract hasher template.
  3915. *
  3916. * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
  3917. */
  3918. var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
  3919. /**
  3920. * Configuration options.
  3921. */
  3922. cfg: Base.extend(),
  3923. /**
  3924. * Initializes a newly created hasher.
  3925. *
  3926. * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
  3927. *
  3928. * @example
  3929. *
  3930. * var hasher = CryptoJS.algo.SHA256.create();
  3931. */
  3932. init: function (cfg) {
  3933. // Apply config defaults
  3934. this.cfg = this.cfg.extend(cfg);
  3935. // Set initial values
  3936. this.reset();
  3937. },
  3938. /**
  3939. * Resets this hasher to its initial state.
  3940. *
  3941. * @example
  3942. *
  3943. * hasher.reset();
  3944. */
  3945. reset: function () {
  3946. // Reset data buffer
  3947. BufferedBlockAlgorithm.reset.call(this);
  3948. // Perform concrete-hasher logic
  3949. this._doReset();
  3950. },
  3951. /**
  3952. * Updates this hasher with a message.
  3953. *
  3954. * @param {WordArray|string} messageUpdate The message to append.
  3955. *
  3956. * @return {Hasher} This hasher.
  3957. *
  3958. * @example
  3959. *
  3960. * hasher.update('message');
  3961. * hasher.update(wordArray);
  3962. */
  3963. update: function (messageUpdate) {
  3964. // Append
  3965. this._append(messageUpdate);
  3966. // Update the hash
  3967. this._process();
  3968. // Chainable
  3969. return this;
  3970. },
  3971. /**
  3972. * Finalizes the hash computation.
  3973. * Note that the finalize operation is effectively a destructive, read-once operation.
  3974. *
  3975. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  3976. *
  3977. * @return {WordArray} The hash.
  3978. *
  3979. * @example
  3980. *
  3981. * var hash = hasher.finalize();
  3982. * var hash = hasher.finalize('message');
  3983. * var hash = hasher.finalize(wordArray);
  3984. */
  3985. finalize: function (messageUpdate) {
  3986. // Final message update
  3987. if (messageUpdate) {
  3988. this._append(messageUpdate);
  3989. }
  3990. // Perform concrete-hasher logic
  3991. var hash = this._doFinalize();
  3992. return hash;
  3993. },
  3994. blockSize: 512/32,
  3995. /**
  3996. * Creates a shortcut function to a hasher's object interface.
  3997. *
  3998. * @param {Hasher} hasher The hasher to create a helper for.
  3999. *
  4000. * @return {Function} The shortcut function.
  4001. *
  4002. * @static
  4003. *
  4004. * @example
  4005. *
  4006. * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
  4007. */
  4008. _createHelper: function (hasher) {
  4009. return function (message, cfg) {
  4010. return new hasher.init(cfg).finalize(message);
  4011. };
  4012. },
  4013. /**
  4014. * Creates a shortcut function to the HMAC's object interface.
  4015. *
  4016. * @param {Hasher} hasher The hasher to use in this HMAC helper.
  4017. *
  4018. * @return {Function} The shortcut function.
  4019. *
  4020. * @static
  4021. *
  4022. * @example
  4023. *
  4024. * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
  4025. */
  4026. _createHmacHelper: function (hasher) {
  4027. return function (message, key) {
  4028. return new C_algo.HMAC.init(hasher, key).finalize(message);
  4029. };
  4030. }
  4031. });
  4032. /**
  4033. * Algorithm namespace.
  4034. */
  4035. var C_algo = C.algo = {};
  4036. return C;
  4037. }(Math));
  4038. return CryptoJS;
  4039. }));
  4040. },{}],19:[function(require,module,exports){
  4041. ;(function (root, factory) {
  4042. if (typeof exports === "object") {
  4043. // CommonJS
  4044. module.exports = exports = factory(require("./core"));
  4045. }
  4046. else if (typeof define === "function" && define.amd) {
  4047. // AMD
  4048. define(["./core"], factory);
  4049. }
  4050. else {
  4051. // Global (browser)
  4052. factory(root.CryptoJS);
  4053. }
  4054. }(this, function (CryptoJS) {
  4055. (function () {
  4056. // Shortcuts
  4057. var C = CryptoJS;
  4058. var C_lib = C.lib;
  4059. var WordArray = C_lib.WordArray;
  4060. var C_enc = C.enc;
  4061. /**
  4062. * Base64 encoding strategy.
  4063. */
  4064. var Base64 = C_enc.Base64 = {
  4065. /**
  4066. * Converts a word array to a Base64 string.
  4067. *
  4068. * @param {WordArray} wordArray The word array.
  4069. *
  4070. * @return {string} The Base64 string.
  4071. *
  4072. * @static
  4073. *
  4074. * @example
  4075. *
  4076. * var base64String = CryptoJS.enc.Base64.stringify(wordArray);
  4077. */
  4078. stringify: function (wordArray) {
  4079. // Shortcuts
  4080. var words = wordArray.words;
  4081. var sigBytes = wordArray.sigBytes;
  4082. var map = this._map;
  4083. // Clamp excess bits
  4084. wordArray.clamp();
  4085. // Convert
  4086. var base64Chars = [];
  4087. for (var i = 0; i < sigBytes; i += 3) {
  4088. var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  4089. var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
  4090. var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
  4091. var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
  4092. for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
  4093. base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
  4094. }
  4095. }
  4096. // Add padding
  4097. var paddingChar = map.charAt(64);
  4098. if (paddingChar) {
  4099. while (base64Chars.length % 4) {
  4100. base64Chars.push(paddingChar);
  4101. }
  4102. }
  4103. return base64Chars.join('');
  4104. },
  4105. /**
  4106. * Converts a Base64 string to a word array.
  4107. *
  4108. * @param {string} base64Str The Base64 string.
  4109. *
  4110. * @return {WordArray} The word array.
  4111. *
  4112. * @static
  4113. *
  4114. * @example
  4115. *
  4116. * var wordArray = CryptoJS.enc.Base64.parse(base64String);
  4117. */
  4118. parse: function (base64Str) {
  4119. // Shortcuts
  4120. var base64StrLength = base64Str.length;
  4121. var map = this._map;
  4122. var reverseMap = this._reverseMap;
  4123. if (!reverseMap) {
  4124. reverseMap = this._reverseMap = [];
  4125. for (var j = 0; j < map.length; j++) {
  4126. reverseMap[map.charCodeAt(j)] = j;
  4127. }
  4128. }
  4129. // Ignore padding
  4130. var paddingChar = map.charAt(64);
  4131. if (paddingChar) {
  4132. var paddingIndex = base64Str.indexOf(paddingChar);
  4133. if (paddingIndex !== -1) {
  4134. base64StrLength = paddingIndex;
  4135. }
  4136. }
  4137. // Convert
  4138. return parseLoop(base64Str, base64StrLength, reverseMap);
  4139. },
  4140. _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
  4141. };
  4142. function parseLoop(base64Str, base64StrLength, reverseMap) {
  4143. var words = [];
  4144. var nBytes = 0;
  4145. for (var i = 0; i < base64StrLength; i++) {
  4146. if (i % 4) {
  4147. var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
  4148. var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
  4149. words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8);
  4150. nBytes++;
  4151. }
  4152. }
  4153. return WordArray.create(words, nBytes);
  4154. }
  4155. }());
  4156. return CryptoJS.enc.Base64;
  4157. }));
  4158. },{"./core":18}],20:[function(require,module,exports){
  4159. ;(function (root, factory) {
  4160. if (typeof exports === "object") {
  4161. // CommonJS
  4162. module.exports = exports = factory(require("./core"));
  4163. }
  4164. else if (typeof define === "function" && define.amd) {
  4165. // AMD
  4166. define(["./core"], factory);
  4167. }
  4168. else {
  4169. // Global (browser)
  4170. factory(root.CryptoJS);
  4171. }
  4172. }(this, function (CryptoJS) {
  4173. return CryptoJS.enc.Hex;
  4174. }));
  4175. },{"./core":18}],21:[function(require,module,exports){
  4176. ;(function (root, factory) {
  4177. if (typeof exports === "object") {
  4178. // CommonJS
  4179. module.exports = exports = factory(require("./core"));
  4180. }
  4181. else if (typeof define === "function" && define.amd) {
  4182. // AMD
  4183. define(["./core"], factory);
  4184. }
  4185. else {
  4186. // Global (browser)
  4187. factory(root.CryptoJS);
  4188. }
  4189. }(this, function (CryptoJS) {
  4190. return CryptoJS.enc.Latin1;
  4191. }));
  4192. },{"./core":18}],22:[function(require,module,exports){
  4193. ;(function (root, factory) {
  4194. if (typeof exports === "object") {
  4195. // CommonJS
  4196. module.exports = exports = factory(require("./core"));
  4197. }
  4198. else if (typeof define === "function" && define.amd) {
  4199. // AMD
  4200. define(["./core"], factory);
  4201. }
  4202. else {
  4203. // Global (browser)
  4204. factory(root.CryptoJS);
  4205. }
  4206. }(this, function (CryptoJS) {
  4207. return CryptoJS.enc.Utf8;
  4208. }));
  4209. },{"./core":18}],23:[function(require,module,exports){
  4210. ;(function (root, factory, undef) {
  4211. if (typeof exports === "object") {
  4212. // CommonJS
  4213. module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
  4214. }
  4215. else if (typeof define === "function" && define.amd) {
  4216. // AMD
  4217. define(["./core", "./sha1", "./hmac"], factory);
  4218. }
  4219. else {
  4220. // Global (browser)
  4221. factory(root.CryptoJS);
  4222. }
  4223. }(this, function (CryptoJS) {
  4224. (function () {
  4225. // Shortcuts
  4226. var C = CryptoJS;
  4227. var C_lib = C.lib;
  4228. var Base = C_lib.Base;
  4229. var WordArray = C_lib.WordArray;
  4230. var C_algo = C.algo;
  4231. var MD5 = C_algo.MD5;
  4232. /**
  4233. * This key derivation function is meant to conform with EVP_BytesToKey.
  4234. * www.openssl.org/docs/crypto/EVP_BytesToKey.html
  4235. */
  4236. var EvpKDF = C_algo.EvpKDF = Base.extend({
  4237. /**
  4238. * Configuration options.
  4239. *
  4240. * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  4241. * @property {Hasher} hasher The hash algorithm to use. Default: MD5
  4242. * @property {number} iterations The number of iterations to perform. Default: 1
  4243. */
  4244. cfg: Base.extend({
  4245. keySize: 128/32,
  4246. hasher: MD5,
  4247. iterations: 1
  4248. }),
  4249. /**
  4250. * Initializes a newly created key derivation function.
  4251. *
  4252. * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  4253. *
  4254. * @example
  4255. *
  4256. * var kdf = CryptoJS.algo.EvpKDF.create();
  4257. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
  4258. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
  4259. */
  4260. init: function (cfg) {
  4261. this.cfg = this.cfg.extend(cfg);
  4262. },
  4263. /**
  4264. * Derives a key from a password.
  4265. *
  4266. * @param {WordArray|string} password The password.
  4267. * @param {WordArray|string} salt A salt.
  4268. *
  4269. * @return {WordArray} The derived key.
  4270. *
  4271. * @example
  4272. *
  4273. * var key = kdf.compute(password, salt);
  4274. */
  4275. compute: function (password, salt) {
  4276. // Shortcut
  4277. var cfg = this.cfg;
  4278. // Init hasher
  4279. var hasher = cfg.hasher.create();
  4280. // Initial values
  4281. var derivedKey = WordArray.create();
  4282. // Shortcuts
  4283. var derivedKeyWords = derivedKey.words;
  4284. var keySize = cfg.keySize;
  4285. var iterations = cfg.iterations;
  4286. // Generate key
  4287. while (derivedKeyWords.length < keySize) {
  4288. if (block) {
  4289. hasher.update(block);
  4290. }
  4291. var block = hasher.update(password).finalize(salt);
  4292. hasher.reset();
  4293. // Iterations
  4294. for (var i = 1; i < iterations; i++) {
  4295. block = hasher.finalize(block);
  4296. hasher.reset();
  4297. }
  4298. derivedKey.concat(block);
  4299. }
  4300. derivedKey.sigBytes = keySize * 4;
  4301. return derivedKey;
  4302. }
  4303. });
  4304. /**
  4305. * Derives a key from a password.
  4306. *
  4307. * @param {WordArray|string} password The password.
  4308. * @param {WordArray|string} salt A salt.
  4309. * @param {Object} cfg (Optional) The configuration options to use for this computation.
  4310. *
  4311. * @return {WordArray} The derived key.
  4312. *
  4313. * @static
  4314. *
  4315. * @example
  4316. *
  4317. * var key = CryptoJS.EvpKDF(password, salt);
  4318. * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
  4319. * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
  4320. */
  4321. C.EvpKDF = function (password, salt, cfg) {
  4322. return EvpKDF.create(cfg).compute(password, salt);
  4323. };
  4324. }());
  4325. return CryptoJS.EvpKDF;
  4326. }));
  4327. },{"./core":18,"./hmac":25,"./sha1":27}],24:[function(require,module,exports){
  4328. ;(function (root, factory, undef) {
  4329. if (typeof exports === "object") {
  4330. // CommonJS
  4331. module.exports = exports = factory(require("./core"), require("./sha256"), require("./hmac"));
  4332. }
  4333. else if (typeof define === "function" && define.amd) {
  4334. // AMD
  4335. define(["./core", "./sha256", "./hmac"], factory);
  4336. }
  4337. else {
  4338. // Global (browser)
  4339. factory(root.CryptoJS);
  4340. }
  4341. }(this, function (CryptoJS) {
  4342. return CryptoJS.HmacSHA256;
  4343. }));
  4344. },{"./core":18,"./hmac":25,"./sha256":28}],25:[function(require,module,exports){
  4345. ;(function (root, factory) {
  4346. if (typeof exports === "object") {
  4347. // CommonJS
  4348. module.exports = exports = factory(require("./core"));
  4349. }
  4350. else if (typeof define === "function" && define.amd) {
  4351. // AMD
  4352. define(["./core"], factory);
  4353. }
  4354. else {
  4355. // Global (browser)
  4356. factory(root.CryptoJS);
  4357. }
  4358. }(this, function (CryptoJS) {
  4359. (function () {
  4360. // Shortcuts
  4361. var C = CryptoJS;
  4362. var C_lib = C.lib;
  4363. var Base = C_lib.Base;
  4364. var C_enc = C.enc;
  4365. var Utf8 = C_enc.Utf8;
  4366. var C_algo = C.algo;
  4367. /**
  4368. * HMAC algorithm.
  4369. */
  4370. var HMAC = C_algo.HMAC = Base.extend({
  4371. /**
  4372. * Initializes a newly created HMAC.
  4373. *
  4374. * @param {Hasher} hasher The hash algorithm to use.
  4375. * @param {WordArray|string} key The secret key.
  4376. *
  4377. * @example
  4378. *
  4379. * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
  4380. */
  4381. init: function (hasher, key) {
  4382. // Init hasher
  4383. hasher = this._hasher = new hasher.init();
  4384. // Convert string to WordArray, else assume WordArray already
  4385. if (typeof key == 'string') {
  4386. key = Utf8.parse(key);
  4387. }
  4388. // Shortcuts
  4389. var hasherBlockSize = hasher.blockSize;
  4390. var hasherBlockSizeBytes = hasherBlockSize * 4;
  4391. // Allow arbitrary length keys
  4392. if (key.sigBytes > hasherBlockSizeBytes) {
  4393. key = hasher.finalize(key);
  4394. }
  4395. // Clamp excess bits
  4396. key.clamp();
  4397. // Clone key for inner and outer pads
  4398. var oKey = this._oKey = key.clone();
  4399. var iKey = this._iKey = key.clone();
  4400. // Shortcuts
  4401. var oKeyWords = oKey.words;
  4402. var iKeyWords = iKey.words;
  4403. // XOR keys with pad constants
  4404. for (var i = 0; i < hasherBlockSize; i++) {
  4405. oKeyWords[i] ^= 0x5c5c5c5c;
  4406. iKeyWords[i] ^= 0x36363636;
  4407. }
  4408. oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
  4409. // Set initial values
  4410. this.reset();
  4411. },
  4412. /**
  4413. * Resets this HMAC to its initial state.
  4414. *
  4415. * @example
  4416. *
  4417. * hmacHasher.reset();
  4418. */
  4419. reset: function () {
  4420. // Shortcut
  4421. var hasher = this._hasher;
  4422. // Reset
  4423. hasher.reset();
  4424. hasher.update(this._iKey);
  4425. },
  4426. /**
  4427. * Updates this HMAC with a message.
  4428. *
  4429. * @param {WordArray|string} messageUpdate The message to append.
  4430. *
  4431. * @return {HMAC} This HMAC instance.
  4432. *
  4433. * @example
  4434. *
  4435. * hmacHasher.update('message');
  4436. * hmacHasher.update(wordArray);
  4437. */
  4438. update: function (messageUpdate) {
  4439. this._hasher.update(messageUpdate);
  4440. // Chainable
  4441. return this;
  4442. },
  4443. /**
  4444. * Finalizes the HMAC computation.
  4445. * Note that the finalize operation is effectively a destructive, read-once operation.
  4446. *
  4447. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  4448. *
  4449. * @return {WordArray} The HMAC.
  4450. *
  4451. * @example
  4452. *
  4453. * var hmac = hmacHasher.finalize();
  4454. * var hmac = hmacHasher.finalize('message');
  4455. * var hmac = hmacHasher.finalize(wordArray);
  4456. */
  4457. finalize: function (messageUpdate) {
  4458. // Shortcut
  4459. var hasher = this._hasher;
  4460. // Compute HMAC
  4461. var innerHash = hasher.finalize(messageUpdate);
  4462. hasher.reset();
  4463. var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
  4464. return hmac;
  4465. }
  4466. });
  4467. }());
  4468. }));
  4469. },{"./core":18}],26:[function(require,module,exports){
  4470. ;(function (root, factory) {
  4471. if (typeof exports === "object") {
  4472. // CommonJS
  4473. module.exports = exports = factory(require("./core"));
  4474. }
  4475. else if (typeof define === "function" && define.amd) {
  4476. // AMD
  4477. define(["./core"], factory);
  4478. }
  4479. else {
  4480. // Global (browser)
  4481. factory(root.CryptoJS);
  4482. }
  4483. }(this, function (CryptoJS) {
  4484. (function (Math) {
  4485. // Shortcuts
  4486. var C = CryptoJS;
  4487. var C_lib = C.lib;
  4488. var WordArray = C_lib.WordArray;
  4489. var Hasher = C_lib.Hasher;
  4490. var C_algo = C.algo;
  4491. // Constants table
  4492. var T = [];
  4493. // Compute constants
  4494. (function () {
  4495. for (var i = 0; i < 64; i++) {
  4496. T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
  4497. }
  4498. }());
  4499. /**
  4500. * MD5 hash algorithm.
  4501. */
  4502. var MD5 = C_algo.MD5 = Hasher.extend({
  4503. _doReset: function () {
  4504. this._hash = new WordArray.init([
  4505. 0x67452301, 0xefcdab89,
  4506. 0x98badcfe, 0x10325476
  4507. ]);
  4508. },
  4509. _doProcessBlock: function (M, offset) {
  4510. // Swap endian
  4511. for (var i = 0; i < 16; i++) {
  4512. // Shortcuts
  4513. var offset_i = offset + i;
  4514. var M_offset_i = M[offset_i];
  4515. M[offset_i] = (
  4516. (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
  4517. (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
  4518. );
  4519. }
  4520. // Shortcuts
  4521. var H = this._hash.words;
  4522. var M_offset_0 = M[offset + 0];
  4523. var M_offset_1 = M[offset + 1];
  4524. var M_offset_2 = M[offset + 2];
  4525. var M_offset_3 = M[offset + 3];
  4526. var M_offset_4 = M[offset + 4];
  4527. var M_offset_5 = M[offset + 5];
  4528. var M_offset_6 = M[offset + 6];
  4529. var M_offset_7 = M[offset + 7];
  4530. var M_offset_8 = M[offset + 8];
  4531. var M_offset_9 = M[offset + 9];
  4532. var M_offset_10 = M[offset + 10];
  4533. var M_offset_11 = M[offset + 11];
  4534. var M_offset_12 = M[offset + 12];
  4535. var M_offset_13 = M[offset + 13];
  4536. var M_offset_14 = M[offset + 14];
  4537. var M_offset_15 = M[offset + 15];
  4538. // Working varialbes
  4539. var a = H[0];
  4540. var b = H[1];
  4541. var c = H[2];
  4542. var d = H[3];
  4543. // Computation
  4544. a = FF(a, b, c, d, M_offset_0, 7, T[0]);
  4545. d = FF(d, a, b, c, M_offset_1, 12, T[1]);
  4546. c = FF(c, d, a, b, M_offset_2, 17, T[2]);
  4547. b = FF(b, c, d, a, M_offset_3, 22, T[3]);
  4548. a = FF(a, b, c, d, M_offset_4, 7, T[4]);
  4549. d = FF(d, a, b, c, M_offset_5, 12, T[5]);
  4550. c = FF(c, d, a, b, M_offset_6, 17, T[6]);
  4551. b = FF(b, c, d, a, M_offset_7, 22, T[7]);
  4552. a = FF(a, b, c, d, M_offset_8, 7, T[8]);
  4553. d = FF(d, a, b, c, M_offset_9, 12, T[9]);
  4554. c = FF(c, d, a, b, M_offset_10, 17, T[10]);
  4555. b = FF(b, c, d, a, M_offset_11, 22, T[11]);
  4556. a = FF(a, b, c, d, M_offset_12, 7, T[12]);
  4557. d = FF(d, a, b, c, M_offset_13, 12, T[13]);
  4558. c = FF(c, d, a, b, M_offset_14, 17, T[14]);
  4559. b = FF(b, c, d, a, M_offset_15, 22, T[15]);
  4560. a = GG(a, b, c, d, M_offset_1, 5, T[16]);
  4561. d = GG(d, a, b, c, M_offset_6, 9, T[17]);
  4562. c = GG(c, d, a, b, M_offset_11, 14, T[18]);
  4563. b = GG(b, c, d, a, M_offset_0, 20, T[19]);
  4564. a = GG(a, b, c, d, M_offset_5, 5, T[20]);
  4565. d = GG(d, a, b, c, M_offset_10, 9, T[21]);
  4566. c = GG(c, d, a, b, M_offset_15, 14, T[22]);
  4567. b = GG(b, c, d, a, M_offset_4, 20, T[23]);
  4568. a = GG(a, b, c, d, M_offset_9, 5, T[24]);
  4569. d = GG(d, a, b, c, M_offset_14, 9, T[25]);
  4570. c = GG(c, d, a, b, M_offset_3, 14, T[26]);
  4571. b = GG(b, c, d, a, M_offset_8, 20, T[27]);
  4572. a = GG(a, b, c, d, M_offset_13, 5, T[28]);
  4573. d = GG(d, a, b, c, M_offset_2, 9, T[29]);
  4574. c = GG(c, d, a, b, M_offset_7, 14, T[30]);
  4575. b = GG(b, c, d, a, M_offset_12, 20, T[31]);
  4576. a = HH(a, b, c, d, M_offset_5, 4, T[32]);
  4577. d = HH(d, a, b, c, M_offset_8, 11, T[33]);
  4578. c = HH(c, d, a, b, M_offset_11, 16, T[34]);
  4579. b = HH(b, c, d, a, M_offset_14, 23, T[35]);
  4580. a = HH(a, b, c, d, M_offset_1, 4, T[36]);
  4581. d = HH(d, a, b, c, M_offset_4, 11, T[37]);
  4582. c = HH(c, d, a, b, M_offset_7, 16, T[38]);
  4583. b = HH(b, c, d, a, M_offset_10, 23, T[39]);
  4584. a = HH(a, b, c, d, M_offset_13, 4, T[40]);
  4585. d = HH(d, a, b, c, M_offset_0, 11, T[41]);
  4586. c = HH(c, d, a, b, M_offset_3, 16, T[42]);
  4587. b = HH(b, c, d, a, M_offset_6, 23, T[43]);
  4588. a = HH(a, b, c, d, M_offset_9, 4, T[44]);
  4589. d = HH(d, a, b, c, M_offset_12, 11, T[45]);
  4590. c = HH(c, d, a, b, M_offset_15, 16, T[46]);
  4591. b = HH(b, c, d, a, M_offset_2, 23, T[47]);
  4592. a = II(a, b, c, d, M_offset_0, 6, T[48]);
  4593. d = II(d, a, b, c, M_offset_7, 10, T[49]);
  4594. c = II(c, d, a, b, M_offset_14, 15, T[50]);
  4595. b = II(b, c, d, a, M_offset_5, 21, T[51]);
  4596. a = II(a, b, c, d, M_offset_12, 6, T[52]);
  4597. d = II(d, a, b, c, M_offset_3, 10, T[53]);
  4598. c = II(c, d, a, b, M_offset_10, 15, T[54]);
  4599. b = II(b, c, d, a, M_offset_1, 21, T[55]);
  4600. a = II(a, b, c, d, M_offset_8, 6, T[56]);
  4601. d = II(d, a, b, c, M_offset_15, 10, T[57]);
  4602. c = II(c, d, a, b, M_offset_6, 15, T[58]);
  4603. b = II(b, c, d, a, M_offset_13, 21, T[59]);
  4604. a = II(a, b, c, d, M_offset_4, 6, T[60]);
  4605. d = II(d, a, b, c, M_offset_11, 10, T[61]);
  4606. c = II(c, d, a, b, M_offset_2, 15, T[62]);
  4607. b = II(b, c, d, a, M_offset_9, 21, T[63]);
  4608. // Intermediate hash value
  4609. H[0] = (H[0] + a) | 0;
  4610. H[1] = (H[1] + b) | 0;
  4611. H[2] = (H[2] + c) | 0;
  4612. H[3] = (H[3] + d) | 0;
  4613. },
  4614. _doFinalize: function () {
  4615. // Shortcuts
  4616. var data = this._data;
  4617. var dataWords = data.words;
  4618. var nBitsTotal = this._nDataBytes * 8;
  4619. var nBitsLeft = data.sigBytes * 8;
  4620. // Add padding
  4621. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  4622. var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
  4623. var nBitsTotalL = nBitsTotal;
  4624. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
  4625. (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
  4626. (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
  4627. );
  4628. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
  4629. (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
  4630. (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
  4631. );
  4632. data.sigBytes = (dataWords.length + 1) * 4;
  4633. // Hash final blocks
  4634. this._process();
  4635. // Shortcuts
  4636. var hash = this._hash;
  4637. var H = hash.words;
  4638. // Swap endian
  4639. for (var i = 0; i < 4; i++) {
  4640. // Shortcut
  4641. var H_i = H[i];
  4642. H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
  4643. (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
  4644. }
  4645. // Return final computed hash
  4646. return hash;
  4647. },
  4648. clone: function () {
  4649. var clone = Hasher.clone.call(this);
  4650. clone._hash = this._hash.clone();
  4651. return clone;
  4652. }
  4653. });
  4654. function FF(a, b, c, d, x, s, t) {
  4655. var n = a + ((b & c) | (~b & d)) + x + t;
  4656. return ((n << s) | (n >>> (32 - s))) + b;
  4657. }
  4658. function GG(a, b, c, d, x, s, t) {
  4659. var n = a + ((b & d) | (c & ~d)) + x + t;
  4660. return ((n << s) | (n >>> (32 - s))) + b;
  4661. }
  4662. function HH(a, b, c, d, x, s, t) {
  4663. var n = a + (b ^ c ^ d) + x + t;
  4664. return ((n << s) | (n >>> (32 - s))) + b;
  4665. }
  4666. function II(a, b, c, d, x, s, t) {
  4667. var n = a + (c ^ (b | ~d)) + x + t;
  4668. return ((n << s) | (n >>> (32 - s))) + b;
  4669. }
  4670. /**
  4671. * Shortcut function to the hasher's object interface.
  4672. *
  4673. * @param {WordArray|string} message The message to hash.
  4674. *
  4675. * @return {WordArray} The hash.
  4676. *
  4677. * @static
  4678. *
  4679. * @example
  4680. *
  4681. * var hash = CryptoJS.MD5('message');
  4682. * var hash = CryptoJS.MD5(wordArray);
  4683. */
  4684. C.MD5 = Hasher._createHelper(MD5);
  4685. /**
  4686. * Shortcut function to the HMAC's object interface.
  4687. *
  4688. * @param {WordArray|string} message The message to hash.
  4689. * @param {WordArray|string} key The secret key.
  4690. *
  4691. * @return {WordArray} The HMAC.
  4692. *
  4693. * @static
  4694. *
  4695. * @example
  4696. *
  4697. * var hmac = CryptoJS.HmacMD5(message, key);
  4698. */
  4699. C.HmacMD5 = Hasher._createHmacHelper(MD5);
  4700. }(Math));
  4701. return CryptoJS.MD5;
  4702. }));
  4703. },{"./core":18}],27:[function(require,module,exports){
  4704. ;(function (root, factory) {
  4705. if (typeof exports === "object") {
  4706. // CommonJS
  4707. module.exports = exports = factory(require("./core"));
  4708. }
  4709. else if (typeof define === "function" && define.amd) {
  4710. // AMD
  4711. define(["./core"], factory);
  4712. }
  4713. else {
  4714. // Global (browser)
  4715. factory(root.CryptoJS);
  4716. }
  4717. }(this, function (CryptoJS) {
  4718. (function () {
  4719. // Shortcuts
  4720. var C = CryptoJS;
  4721. var C_lib = C.lib;
  4722. var WordArray = C_lib.WordArray;
  4723. var Hasher = C_lib.Hasher;
  4724. var C_algo = C.algo;
  4725. // Reusable object
  4726. var W = [];
  4727. /**
  4728. * SHA-1 hash algorithm.
  4729. */
  4730. var SHA1 = C_algo.SHA1 = Hasher.extend({
  4731. _doReset: function () {
  4732. this._hash = new WordArray.init([
  4733. 0x67452301, 0xefcdab89,
  4734. 0x98badcfe, 0x10325476,
  4735. 0xc3d2e1f0
  4736. ]);
  4737. },
  4738. _doProcessBlock: function (M, offset) {
  4739. // Shortcut
  4740. var H = this._hash.words;
  4741. // Working variables
  4742. var a = H[0];
  4743. var b = H[1];
  4744. var c = H[2];
  4745. var d = H[3];
  4746. var e = H[4];
  4747. // Computation
  4748. for (var i = 0; i < 80; i++) {
  4749. if (i < 16) {
  4750. W[i] = M[offset + i] | 0;
  4751. } else {
  4752. var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  4753. W[i] = (n << 1) | (n >>> 31);
  4754. }
  4755. var t = ((a << 5) | (a >>> 27)) + e + W[i];
  4756. if (i < 20) {
  4757. t += ((b & c) | (~b & d)) + 0x5a827999;
  4758. } else if (i < 40) {
  4759. t += (b ^ c ^ d) + 0x6ed9eba1;
  4760. } else if (i < 60) {
  4761. t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
  4762. } else /* if (i < 80) */ {
  4763. t += (b ^ c ^ d) - 0x359d3e2a;
  4764. }
  4765. e = d;
  4766. d = c;
  4767. c = (b << 30) | (b >>> 2);
  4768. b = a;
  4769. a = t;
  4770. }
  4771. // Intermediate hash value
  4772. H[0] = (H[0] + a) | 0;
  4773. H[1] = (H[1] + b) | 0;
  4774. H[2] = (H[2] + c) | 0;
  4775. H[3] = (H[3] + d) | 0;
  4776. H[4] = (H[4] + e) | 0;
  4777. },
  4778. _doFinalize: function () {
  4779. // Shortcuts
  4780. var data = this._data;
  4781. var dataWords = data.words;
  4782. var nBitsTotal = this._nDataBytes * 8;
  4783. var nBitsLeft = data.sigBytes * 8;
  4784. // Add padding
  4785. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  4786. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  4787. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  4788. data.sigBytes = dataWords.length * 4;
  4789. // Hash final blocks
  4790. this._process();
  4791. // Return final computed hash
  4792. return this._hash;
  4793. },
  4794. clone: function () {
  4795. var clone = Hasher.clone.call(this);
  4796. clone._hash = this._hash.clone();
  4797. return clone;
  4798. }
  4799. });
  4800. /**
  4801. * Shortcut function to the hasher's object interface.
  4802. *
  4803. * @param {WordArray|string} message The message to hash.
  4804. *
  4805. * @return {WordArray} The hash.
  4806. *
  4807. * @static
  4808. *
  4809. * @example
  4810. *
  4811. * var hash = CryptoJS.SHA1('message');
  4812. * var hash = CryptoJS.SHA1(wordArray);
  4813. */
  4814. C.SHA1 = Hasher._createHelper(SHA1);
  4815. /**
  4816. * Shortcut function to the HMAC's object interface.
  4817. *
  4818. * @param {WordArray|string} message The message to hash.
  4819. * @param {WordArray|string} key The secret key.
  4820. *
  4821. * @return {WordArray} The HMAC.
  4822. *
  4823. * @static
  4824. *
  4825. * @example
  4826. *
  4827. * var hmac = CryptoJS.HmacSHA1(message, key);
  4828. */
  4829. C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
  4830. }());
  4831. return CryptoJS.SHA1;
  4832. }));
  4833. },{"./core":18}],28:[function(require,module,exports){
  4834. ;(function (root, factory) {
  4835. if (typeof exports === "object") {
  4836. // CommonJS
  4837. module.exports = exports = factory(require("./core"));
  4838. }
  4839. else if (typeof define === "function" && define.amd) {
  4840. // AMD
  4841. define(["./core"], factory);
  4842. }
  4843. else {
  4844. // Global (browser)
  4845. factory(root.CryptoJS);
  4846. }
  4847. }(this, function (CryptoJS) {
  4848. (function (Math) {
  4849. // Shortcuts
  4850. var C = CryptoJS;
  4851. var C_lib = C.lib;
  4852. var WordArray = C_lib.WordArray;
  4853. var Hasher = C_lib.Hasher;
  4854. var C_algo = C.algo;
  4855. // Initialization and round constants tables
  4856. var H = [];
  4857. var K = [];
  4858. // Compute constants
  4859. (function () {
  4860. function isPrime(n) {
  4861. var sqrtN = Math.sqrt(n);
  4862. for (var factor = 2; factor <= sqrtN; factor++) {
  4863. if (!(n % factor)) {
  4864. return false;
  4865. }
  4866. }
  4867. return true;
  4868. }
  4869. function getFractionalBits(n) {
  4870. return ((n - (n | 0)) * 0x100000000) | 0;
  4871. }
  4872. var n = 2;
  4873. var nPrime = 0;
  4874. while (nPrime < 64) {
  4875. if (isPrime(n)) {
  4876. if (nPrime < 8) {
  4877. H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
  4878. }
  4879. K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
  4880. nPrime++;
  4881. }
  4882. n++;
  4883. }
  4884. }());
  4885. // Reusable object
  4886. var W = [];
  4887. /**
  4888. * SHA-256 hash algorithm.
  4889. */
  4890. var SHA256 = C_algo.SHA256 = Hasher.extend({
  4891. _doReset: function () {
  4892. this._hash = new WordArray.init(H.slice(0));
  4893. },
  4894. _doProcessBlock: function (M, offset) {
  4895. // Shortcut
  4896. var H = this._hash.words;
  4897. // Working variables
  4898. var a = H[0];
  4899. var b = H[1];
  4900. var c = H[2];
  4901. var d = H[3];
  4902. var e = H[4];
  4903. var f = H[5];
  4904. var g = H[6];
  4905. var h = H[7];
  4906. // Computation
  4907. for (var i = 0; i < 64; i++) {
  4908. if (i < 16) {
  4909. W[i] = M[offset + i] | 0;
  4910. } else {
  4911. var gamma0x = W[i - 15];
  4912. var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^
  4913. ((gamma0x << 14) | (gamma0x >>> 18)) ^
  4914. (gamma0x >>> 3);
  4915. var gamma1x = W[i - 2];
  4916. var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^
  4917. ((gamma1x << 13) | (gamma1x >>> 19)) ^
  4918. (gamma1x >>> 10);
  4919. W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
  4920. }
  4921. var ch = (e & f) ^ (~e & g);
  4922. var maj = (a & b) ^ (a & c) ^ (b & c);
  4923. var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22));
  4924. var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25));
  4925. var t1 = h + sigma1 + ch + K[i] + W[i];
  4926. var t2 = sigma0 + maj;
  4927. h = g;
  4928. g = f;
  4929. f = e;
  4930. e = (d + t1) | 0;
  4931. d = c;
  4932. c = b;
  4933. b = a;
  4934. a = (t1 + t2) | 0;
  4935. }
  4936. // Intermediate hash value
  4937. H[0] = (H[0] + a) | 0;
  4938. H[1] = (H[1] + b) | 0;
  4939. H[2] = (H[2] + c) | 0;
  4940. H[3] = (H[3] + d) | 0;
  4941. H[4] = (H[4] + e) | 0;
  4942. H[5] = (H[5] + f) | 0;
  4943. H[6] = (H[6] + g) | 0;
  4944. H[7] = (H[7] + h) | 0;
  4945. },
  4946. _doFinalize: function () {
  4947. // Shortcuts
  4948. var data = this._data;
  4949. var dataWords = data.words;
  4950. var nBitsTotal = this._nDataBytes * 8;
  4951. var nBitsLeft = data.sigBytes * 8;
  4952. // Add padding
  4953. dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
  4954. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
  4955. dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
  4956. data.sigBytes = dataWords.length * 4;
  4957. // Hash final blocks
  4958. this._process();
  4959. // Return final computed hash
  4960. return this._hash;
  4961. },
  4962. clone: function () {
  4963. var clone = Hasher.clone.call(this);
  4964. clone._hash = this._hash.clone();
  4965. return clone;
  4966. }
  4967. });
  4968. /**
  4969. * Shortcut function to the hasher's object interface.
  4970. *
  4971. * @param {WordArray|string} message The message to hash.
  4972. *
  4973. * @return {WordArray} The hash.
  4974. *
  4975. * @static
  4976. *
  4977. * @example
  4978. *
  4979. * var hash = CryptoJS.SHA256('message');
  4980. * var hash = CryptoJS.SHA256(wordArray);
  4981. */
  4982. C.SHA256 = Hasher._createHelper(SHA256);
  4983. /**
  4984. * Shortcut function to the HMAC's object interface.
  4985. *
  4986. * @param {WordArray|string} message The message to hash.
  4987. * @param {WordArray|string} key The secret key.
  4988. *
  4989. * @return {WordArray} The HMAC.
  4990. *
  4991. * @static
  4992. *
  4993. * @example
  4994. *
  4995. * var hmac = CryptoJS.HmacSHA256(message, key);
  4996. */
  4997. C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
  4998. }(Math));
  4999. return CryptoJS.SHA256;
  5000. }));
  5001. },{"./core":18}],29:[function(require,module,exports){
  5002. require=(function(e,t,n,r){function i(r){if(!n[r]){if(!t[r]){if(e)return e(r);throw new Error("Cannot find module '"+r+"'")}var s=n[r]={exports:{}};t[r][0](function(e){var n=t[r][1][e];return i(n?n:e)},s,s.exports)}return n[r].exports}for(var s=0;s<r.length;s++)i(r[s]);return i})(typeof require!=="undefined"&&require,{1:[function(require,module,exports){
  5003. // UTILITY
  5004. var util = require('util');
  5005. var Buffer = require("buffer").Buffer;
  5006. var pSlice = Array.prototype.slice;
  5007. function objectKeys(object) {
  5008. if (Object.keys) return Object.keys(object);
  5009. var result = [];
  5010. for (var name in object) {
  5011. if (Object.prototype.hasOwnProperty.call(object, name)) {
  5012. result.push(name);
  5013. }
  5014. }
  5015. return result;
  5016. }
  5017. // 1. The assert module provides functions that throw
  5018. // AssertionError's when particular conditions are not met. The
  5019. // assert module must conform to the following interface.
  5020. var assert = module.exports = ok;
  5021. // 2. The AssertionError is defined in assert.
  5022. // new assert.AssertionError({ message: message,
  5023. // actual: actual,
  5024. // expected: expected })
  5025. assert.AssertionError = function AssertionError(options) {
  5026. this.name = 'AssertionError';
  5027. this.message = options.message;
  5028. this.actual = options.actual;
  5029. this.expected = options.expected;
  5030. this.operator = options.operator;
  5031. var stackStartFunction = options.stackStartFunction || fail;
  5032. if (Error.captureStackTrace) {
  5033. Error.captureStackTrace(this, stackStartFunction);
  5034. }
  5035. };
  5036. util.inherits(assert.AssertionError, Error);
  5037. function replacer(key, value) {
  5038. if (value === undefined) {
  5039. return '' + value;
  5040. }
  5041. if (typeof value === 'number' && (isNaN(value) || !isFinite(value))) {
  5042. return value.toString();
  5043. }
  5044. if (typeof value === 'function' || value instanceof RegExp) {
  5045. return value.toString();
  5046. }
  5047. return value;
  5048. }
  5049. function truncate(s, n) {
  5050. if (typeof s == 'string') {
  5051. return s.length < n ? s : s.slice(0, n);
  5052. } else {
  5053. return s;
  5054. }
  5055. }
  5056. assert.AssertionError.prototype.toString = function() {
  5057. if (this.message) {
  5058. return [this.name + ':', this.message].join(' ');
  5059. } else {
  5060. return [
  5061. this.name + ':',
  5062. truncate(JSON.stringify(this.actual, replacer), 128),
  5063. this.operator,
  5064. truncate(JSON.stringify(this.expected, replacer), 128)
  5065. ].join(' ');
  5066. }
  5067. };
  5068. // assert.AssertionError instanceof Error
  5069. assert.AssertionError.__proto__ = Error.prototype;
  5070. // At present only the three keys mentioned above are used and
  5071. // understood by the spec. Implementations or sub modules can pass
  5072. // other keys to the AssertionError's constructor - they will be
  5073. // ignored.
  5074. // 3. All of the following functions must throw an AssertionError
  5075. // when a corresponding condition is not met, with a message that
  5076. // may be undefined if not provided. All assertion methods provide
  5077. // both the actual and expected values to the assertion error for
  5078. // display purposes.
  5079. function fail(actual, expected, message, operator, stackStartFunction) {
  5080. throw new assert.AssertionError({
  5081. message: message,
  5082. actual: actual,
  5083. expected: expected,
  5084. operator: operator,
  5085. stackStartFunction: stackStartFunction
  5086. });
  5087. }
  5088. // EXTENSION! allows for well behaved errors defined elsewhere.
  5089. assert.fail = fail;
  5090. // 4. Pure assertion tests whether a value is truthy, as determined
  5091. // by !!guard.
  5092. // assert.ok(guard, message_opt);
  5093. // This statement is equivalent to assert.equal(true, guard,
  5094. // message_opt);. To test strictly for the value true, use
  5095. // assert.strictEqual(true, guard, message_opt);.
  5096. function ok(value, message) {
  5097. if (!!!value) fail(value, true, message, '==', assert.ok);
  5098. }
  5099. assert.ok = ok;
  5100. // 5. The equality assertion tests shallow, coercive equality with
  5101. // ==.
  5102. // assert.equal(actual, expected, message_opt);
  5103. assert.equal = function equal(actual, expected, message) {
  5104. if (actual != expected) fail(actual, expected, message, '==', assert.equal);
  5105. };
  5106. // 6. The non-equality assertion tests for whether two objects are not equal
  5107. // with != assert.notEqual(actual, expected, message_opt);
  5108. assert.notEqual = function notEqual(actual, expected, message) {
  5109. if (actual == expected) {
  5110. fail(actual, expected, message, '!=', assert.notEqual);
  5111. }
  5112. };
  5113. // 7. The equivalence assertion tests a deep equality relation.
  5114. // assert.deepEqual(actual, expected, message_opt);
  5115. assert.deepEqual = function deepEqual(actual, expected, message) {
  5116. if (!_deepEqual(actual, expected)) {
  5117. fail(actual, expected, message, 'deepEqual', assert.deepEqual);
  5118. }
  5119. };
  5120. function _deepEqual(actual, expected) {
  5121. // 7.1. All identical values are equivalent, as determined by ===.
  5122. if (actual === expected) {
  5123. return true;
  5124. } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
  5125. if (actual.length != expected.length) return false;
  5126. for (var i = 0; i < actual.length; i++) {
  5127. if (actual[i] !== expected[i]) return false;
  5128. }
  5129. return true;
  5130. // 7.2. If the expected value is a Date object, the actual value is
  5131. // equivalent if it is also a Date object that refers to the same time.
  5132. } else if (actual instanceof Date && expected instanceof Date) {
  5133. return actual.getTime() === expected.getTime();
  5134. // 7.3. Other pairs that do not both pass typeof value == 'object',
  5135. // equivalence is determined by ==.
  5136. } else if (typeof actual != 'object' && typeof expected != 'object') {
  5137. return actual == expected;
  5138. // 7.4. For all other Object pairs, including Array objects, equivalence is
  5139. // determined by having the same number of owned properties (as verified
  5140. // with Object.prototype.hasOwnProperty.call), the same set of keys
  5141. // (although not necessarily the same order), equivalent values for every
  5142. // corresponding key, and an identical 'prototype' property. Note: this
  5143. // accounts for both named and indexed properties on Arrays.
  5144. } else {
  5145. return objEquiv(actual, expected);
  5146. }
  5147. }
  5148. function isUndefinedOrNull(value) {
  5149. return value === null || value === undefined;
  5150. }
  5151. function isArguments(object) {
  5152. return Object.prototype.toString.call(object) == '[object Arguments]';
  5153. }
  5154. function objEquiv(a, b) {
  5155. if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
  5156. return false;
  5157. // an identical 'prototype' property.
  5158. if (a.prototype !== b.prototype) return false;
  5159. //~~~I've managed to break Object.keys through screwy arguments passing.
  5160. // Converting to array solves the problem.
  5161. if (isArguments(a)) {
  5162. if (!isArguments(b)) {
  5163. return false;
  5164. }
  5165. a = pSlice.call(a);
  5166. b = pSlice.call(b);
  5167. return _deepEqual(a, b);
  5168. }
  5169. try {
  5170. var ka = objectKeys(a),
  5171. kb = objectKeys(b),
  5172. key, i;
  5173. } catch (e) {//happens when one is a string literal and the other isn't
  5174. return false;
  5175. }
  5176. // having the same number of owned properties (keys incorporates
  5177. // hasOwnProperty)
  5178. if (ka.length != kb.length)
  5179. return false;
  5180. //the same set of keys (although not necessarily the same order),
  5181. ka.sort();
  5182. kb.sort();
  5183. //~~~cheap key test
  5184. for (i = ka.length - 1; i >= 0; i--) {
  5185. if (ka[i] != kb[i])
  5186. return false;
  5187. }
  5188. //equivalent values for every corresponding key, and
  5189. //~~~possibly expensive deep test
  5190. for (i = ka.length - 1; i >= 0; i--) {
  5191. key = ka[i];
  5192. if (!_deepEqual(a[key], b[key])) return false;
  5193. }
  5194. return true;
  5195. }
  5196. // 8. The non-equivalence assertion tests for any deep inequality.
  5197. // assert.notDeepEqual(actual, expected, message_opt);
  5198. assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
  5199. if (_deepEqual(actual, expected)) {
  5200. fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
  5201. }
  5202. };
  5203. // 9. The strict equality assertion tests strict equality, as determined by ===.
  5204. // assert.strictEqual(actual, expected, message_opt);
  5205. assert.strictEqual = function strictEqual(actual, expected, message) {
  5206. if (actual !== expected) {
  5207. fail(actual, expected, message, '===', assert.strictEqual);
  5208. }
  5209. };
  5210. // 10. The strict non-equality assertion tests for strict inequality, as
  5211. // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
  5212. assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
  5213. if (actual === expected) {
  5214. fail(actual, expected, message, '!==', assert.notStrictEqual);
  5215. }
  5216. };
  5217. function expectedException(actual, expected) {
  5218. if (!actual || !expected) {
  5219. return false;
  5220. }
  5221. if (expected instanceof RegExp) {
  5222. return expected.test(actual);
  5223. } else if (actual instanceof expected) {
  5224. return true;
  5225. } else if (expected.call({}, actual) === true) {
  5226. return true;
  5227. }
  5228. return false;
  5229. }
  5230. function _throws(shouldThrow, block, expected, message) {
  5231. var actual;
  5232. if (typeof expected === 'string') {
  5233. message = expected;
  5234. expected = null;
  5235. }
  5236. try {
  5237. block();
  5238. } catch (e) {
  5239. actual = e;
  5240. }
  5241. message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
  5242. (message ? ' ' + message : '.');
  5243. if (shouldThrow && !actual) {
  5244. fail('Missing expected exception' + message);
  5245. }
  5246. if (!shouldThrow && expectedException(actual, expected)) {
  5247. fail('Got unwanted exception' + message);
  5248. }
  5249. if ((shouldThrow && actual && expected &&
  5250. !expectedException(actual, expected)) || (!shouldThrow && actual)) {
  5251. throw actual;
  5252. }
  5253. }
  5254. // 11. Expected to throw an error:
  5255. // assert.throws(block, Error_opt, message_opt);
  5256. assert.throws = function(block, /*optional*/error, /*optional*/message) {
  5257. _throws.apply(this, [true].concat(pSlice.call(arguments)));
  5258. };
  5259. // EXTENSION! This is annoying to write outside this module.
  5260. assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
  5261. _throws.apply(this, [false].concat(pSlice.call(arguments)));
  5262. };
  5263. assert.ifError = function(err) { if (err) {throw err;}};
  5264. },{"util":2,"buffer":3}],2:[function(require,module,exports){
  5265. var events = require('events');
  5266. exports.isArray = isArray;
  5267. exports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'};
  5268. exports.isRegExp = function(obj){return Object.prototype.toString.call(obj) === '[object RegExp]'};
  5269. exports.print = function () {};
  5270. exports.puts = function () {};
  5271. exports.debug = function() {};
  5272. exports.inspect = function(obj, showHidden, depth, colors) {
  5273. var seen = [];
  5274. var stylize = function(str, styleType) {
  5275. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  5276. var styles =
  5277. { 'bold' : [1, 22],
  5278. 'italic' : [3, 23],
  5279. 'underline' : [4, 24],
  5280. 'inverse' : [7, 27],
  5281. 'white' : [37, 39],
  5282. 'grey' : [90, 39],
  5283. 'black' : [30, 39],
  5284. 'blue' : [34, 39],
  5285. 'cyan' : [36, 39],
  5286. 'green' : [32, 39],
  5287. 'magenta' : [35, 39],
  5288. 'red' : [31, 39],
  5289. 'yellow' : [33, 39] };
  5290. var style =
  5291. { 'special': 'cyan',
  5292. 'number': 'blue',
  5293. 'boolean': 'yellow',
  5294. 'undefined': 'grey',
  5295. 'null': 'bold',
  5296. 'string': 'green',
  5297. 'date': 'magenta',
  5298. // "name": intentionally not styling
  5299. 'regexp': 'red' }[styleType];
  5300. if (style) {
  5301. return '\033[' + styles[style][0] + 'm' + str +
  5302. '\033[' + styles[style][1] + 'm';
  5303. } else {
  5304. return str;
  5305. }
  5306. };
  5307. if (! colors) {
  5308. stylize = function(str, styleType) { return str; };
  5309. }
  5310. function format(value, recurseTimes) {
  5311. // Provide a hook for user-specified inspect functions.
  5312. // Check that value is an object with an inspect function on it
  5313. if (value && typeof value.inspect === 'function' &&
  5314. // Filter out the util module, it's inspect function is special
  5315. value !== exports &&
  5316. // Also filter out any prototype objects using the circular check.
  5317. !(value.constructor && value.constructor.prototype === value)) {
  5318. return value.inspect(recurseTimes);
  5319. }
  5320. // Primitive types cannot have properties
  5321. switch (typeof value) {
  5322. case 'undefined':
  5323. return stylize('undefined', 'undefined');
  5324. case 'string':
  5325. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  5326. .replace(/'/g, "\\'")
  5327. .replace(/\\"/g, '"') + '\'';
  5328. return stylize(simple, 'string');
  5329. case 'number':
  5330. return stylize('' + value, 'number');
  5331. case 'boolean':
  5332. return stylize('' + value, 'boolean');
  5333. }
  5334. // For some reason typeof null is "object", so special case here.
  5335. if (value === null) {
  5336. return stylize('null', 'null');
  5337. }
  5338. // Look up the keys of the object.
  5339. var visible_keys = Object_keys(value);
  5340. var keys = showHidden ? Object_getOwnPropertyNames(value) : visible_keys;
  5341. // Functions without properties can be shortcutted.
  5342. if (typeof value === 'function' && keys.length === 0) {
  5343. if (isRegExp(value)) {
  5344. return stylize('' + value, 'regexp');
  5345. } else {
  5346. var name = value.name ? ': ' + value.name : '';
  5347. return stylize('[Function' + name + ']', 'special');
  5348. }
  5349. }
  5350. // Dates without properties can be shortcutted
  5351. if (isDate(value) && keys.length === 0) {
  5352. return stylize(value.toUTCString(), 'date');
  5353. }
  5354. var base, type, braces;
  5355. // Determine the object type
  5356. if (isArray(value)) {
  5357. type = 'Array';
  5358. braces = ['[', ']'];
  5359. } else {
  5360. type = 'Object';
  5361. braces = ['{', '}'];
  5362. }
  5363. // Make functions say that they are functions
  5364. if (typeof value === 'function') {
  5365. var n = value.name ? ': ' + value.name : '';
  5366. base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']';
  5367. } else {
  5368. base = '';
  5369. }
  5370. // Make dates with properties first say the date
  5371. if (isDate(value)) {
  5372. base = ' ' + value.toUTCString();
  5373. }
  5374. if (keys.length === 0) {
  5375. return braces[0] + base + braces[1];
  5376. }
  5377. if (recurseTimes < 0) {
  5378. if (isRegExp(value)) {
  5379. return stylize('' + value, 'regexp');
  5380. } else {
  5381. return stylize('[Object]', 'special');
  5382. }
  5383. }
  5384. seen.push(value);
  5385. var output = keys.map(function(key) {
  5386. var name, str;
  5387. if (value.__lookupGetter__) {
  5388. if (value.__lookupGetter__(key)) {
  5389. if (value.__lookupSetter__(key)) {
  5390. str = stylize('[Getter/Setter]', 'special');
  5391. } else {
  5392. str = stylize('[Getter]', 'special');
  5393. }
  5394. } else {
  5395. if (value.__lookupSetter__(key)) {
  5396. str = stylize('[Setter]', 'special');
  5397. }
  5398. }
  5399. }
  5400. if (visible_keys.indexOf(key) < 0) {
  5401. name = '[' + key + ']';
  5402. }
  5403. if (!str) {
  5404. if (seen.indexOf(value[key]) < 0) {
  5405. if (recurseTimes === null) {
  5406. str = format(value[key]);
  5407. } else {
  5408. str = format(value[key], recurseTimes - 1);
  5409. }
  5410. if (str.indexOf('\n') > -1) {
  5411. if (isArray(value)) {
  5412. str = str.split('\n').map(function(line) {
  5413. return ' ' + line;
  5414. }).join('\n').substr(2);
  5415. } else {
  5416. str = '\n' + str.split('\n').map(function(line) {
  5417. return ' ' + line;
  5418. }).join('\n');
  5419. }
  5420. }
  5421. } else {
  5422. str = stylize('[Circular]', 'special');
  5423. }
  5424. }
  5425. if (typeof name === 'undefined') {
  5426. if (type === 'Array' && key.match(/^\d+$/)) {
  5427. return str;
  5428. }
  5429. name = JSON.stringify('' + key);
  5430. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  5431. name = name.substr(1, name.length - 2);
  5432. name = stylize(name, 'name');
  5433. } else {
  5434. name = name.replace(/'/g, "\\'")
  5435. .replace(/\\"/g, '"')
  5436. .replace(/(^"|"$)/g, "'");
  5437. name = stylize(name, 'string');
  5438. }
  5439. }
  5440. return name + ': ' + str;
  5441. });
  5442. seen.pop();
  5443. var numLinesEst = 0;
  5444. var length = output.reduce(function(prev, cur) {
  5445. numLinesEst++;
  5446. if (cur.indexOf('\n') >= 0) numLinesEst++;
  5447. return prev + cur.length + 1;
  5448. }, 0);
  5449. if (length > 50) {
  5450. output = braces[0] +
  5451. (base === '' ? '' : base + '\n ') +
  5452. ' ' +
  5453. output.join(',\n ') +
  5454. ' ' +
  5455. braces[1];
  5456. } else {
  5457. output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  5458. }
  5459. return output;
  5460. }
  5461. return format(obj, (typeof depth === 'undefined' ? 2 : depth));
  5462. };
  5463. function isArray(ar) {
  5464. return ar instanceof Array ||
  5465. Array.isArray(ar) ||
  5466. (ar && ar !== Object.prototype && isArray(ar.__proto__));
  5467. }
  5468. function isRegExp(re) {
  5469. return re instanceof RegExp ||
  5470. (typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]');
  5471. }
  5472. function isDate(d) {
  5473. if (d instanceof Date) return true;
  5474. if (typeof d !== 'object') return false;
  5475. var properties = Date.prototype && Object_getOwnPropertyNames(Date.prototype);
  5476. var proto = d.__proto__ && Object_getOwnPropertyNames(d.__proto__);
  5477. return JSON.stringify(proto) === JSON.stringify(properties);
  5478. }
  5479. function pad(n) {
  5480. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  5481. }
  5482. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  5483. 'Oct', 'Nov', 'Dec'];
  5484. // 26 Feb 16:19:34
  5485. function timestamp() {
  5486. var d = new Date();
  5487. var time = [pad(d.getHours()),
  5488. pad(d.getMinutes()),
  5489. pad(d.getSeconds())].join(':');
  5490. return [d.getDate(), months[d.getMonth()], time].join(' ');
  5491. }
  5492. exports.log = function (msg) {};
  5493. exports.pump = null;
  5494. var Object_keys = Object.keys || function (obj) {
  5495. var res = [];
  5496. for (var key in obj) res.push(key);
  5497. return res;
  5498. };
  5499. var Object_getOwnPropertyNames = Object.getOwnPropertyNames || function (obj) {
  5500. var res = [];
  5501. for (var key in obj) {
  5502. if (Object.hasOwnProperty.call(obj, key)) res.push(key);
  5503. }
  5504. return res;
  5505. };
  5506. var Object_create = Object.create || function (prototype, properties) {
  5507. // from es5-shim
  5508. var object;
  5509. if (prototype === null) {
  5510. object = { '__proto__' : null };
  5511. }
  5512. else {
  5513. if (typeof prototype !== 'object') {
  5514. throw new TypeError(
  5515. 'typeof prototype[' + (typeof prototype) + '] != \'object\''
  5516. );
  5517. }
  5518. var Type = function () {};
  5519. Type.prototype = prototype;
  5520. object = new Type();
  5521. object.__proto__ = prototype;
  5522. }
  5523. if (typeof properties !== 'undefined' && Object.defineProperties) {
  5524. Object.defineProperties(object, properties);
  5525. }
  5526. return object;
  5527. };
  5528. exports.inherits = function(ctor, superCtor) {
  5529. ctor.super_ = superCtor;
  5530. ctor.prototype = Object_create(superCtor.prototype, {
  5531. constructor: {
  5532. value: ctor,
  5533. enumerable: false,
  5534. writable: true,
  5535. configurable: true
  5536. }
  5537. });
  5538. };
  5539. var formatRegExp = /%[sdj%]/g;
  5540. exports.format = function(f) {
  5541. if (typeof f !== 'string') {
  5542. var objects = [];
  5543. for (var i = 0; i < arguments.length; i++) {
  5544. objects.push(exports.inspect(arguments[i]));
  5545. }
  5546. return objects.join(' ');
  5547. }
  5548. var i = 1;
  5549. var args = arguments;
  5550. var len = args.length;
  5551. var str = String(f).replace(formatRegExp, function(x) {
  5552. if (x === '%%') return '%';
  5553. if (i >= len) return x;
  5554. switch (x) {
  5555. case '%s': return String(args[i++]);
  5556. case '%d': return Number(args[i++]);
  5557. case '%j': return JSON.stringify(args[i++]);
  5558. default:
  5559. return x;
  5560. }
  5561. });
  5562. for(var x = args[i]; i < len; x = args[++i]){
  5563. if (x === null || typeof x !== 'object') {
  5564. str += ' ' + x;
  5565. } else {
  5566. str += ' ' + exports.inspect(x);
  5567. }
  5568. }
  5569. return str;
  5570. };
  5571. },{"events":4}],5:[function(require,module,exports){
  5572. exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) {
  5573. var e, m,
  5574. eLen = nBytes * 8 - mLen - 1,
  5575. eMax = (1 << eLen) - 1,
  5576. eBias = eMax >> 1,
  5577. nBits = -7,
  5578. i = isBE ? 0 : (nBytes - 1),
  5579. d = isBE ? 1 : -1,
  5580. s = buffer[offset + i];
  5581. i += d;
  5582. e = s & ((1 << (-nBits)) - 1);
  5583. s >>= (-nBits);
  5584. nBits += eLen;
  5585. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
  5586. m = e & ((1 << (-nBits)) - 1);
  5587. e >>= (-nBits);
  5588. nBits += mLen;
  5589. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
  5590. if (e === 0) {
  5591. e = 1 - eBias;
  5592. } else if (e === eMax) {
  5593. return m ? NaN : ((s ? -1 : 1) * Infinity);
  5594. } else {
  5595. m = m + Math.pow(2, mLen);
  5596. e = e - eBias;
  5597. }
  5598. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  5599. };
  5600. exports.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) {
  5601. var e, m, c,
  5602. eLen = nBytes * 8 - mLen - 1,
  5603. eMax = (1 << eLen) - 1,
  5604. eBias = eMax >> 1,
  5605. rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
  5606. i = isBE ? (nBytes - 1) : 0,
  5607. d = isBE ? -1 : 1,
  5608. s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  5609. value = Math.abs(value);
  5610. if (isNaN(value) || value === Infinity) {
  5611. m = isNaN(value) ? 1 : 0;
  5612. e = eMax;
  5613. } else {
  5614. e = Math.floor(Math.log(value) / Math.LN2);
  5615. if (value * (c = Math.pow(2, -e)) < 1) {
  5616. e--;
  5617. c *= 2;
  5618. }
  5619. if (e + eBias >= 1) {
  5620. value += rt / c;
  5621. } else {
  5622. value += rt * Math.pow(2, 1 - eBias);
  5623. }
  5624. if (value * c >= 2) {
  5625. e++;
  5626. c /= 2;
  5627. }
  5628. if (e + eBias >= eMax) {
  5629. m = 0;
  5630. e = eMax;
  5631. } else if (e + eBias >= 1) {
  5632. m = (value * c - 1) * Math.pow(2, mLen);
  5633. e = e + eBias;
  5634. } else {
  5635. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  5636. e = 0;
  5637. }
  5638. }
  5639. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
  5640. e = (e << mLen) | m;
  5641. eLen += mLen;
  5642. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
  5643. buffer[offset + i - d] |= s * 128;
  5644. };
  5645. },{}],6:[function(require,module,exports){
  5646. // shim for using process in browser
  5647. var process = module.exports = {};
  5648. process.nextTick = (function () {
  5649. var canSetImmediate = typeof window !== 'undefined'
  5650. && window.setImmediate;
  5651. var canPost = typeof window !== 'undefined'
  5652. && window.postMessage && window.addEventListener
  5653. ;
  5654. if (canSetImmediate) {
  5655. return function (f) { return window.setImmediate(f) };
  5656. }
  5657. if (canPost) {
  5658. var queue = [];
  5659. window.addEventListener('message', function (ev) {
  5660. if (ev.source === window && ev.data === 'process-tick') {
  5661. ev.stopPropagation();
  5662. if (queue.length > 0) {
  5663. var fn = queue.shift();
  5664. fn();
  5665. }
  5666. }
  5667. }, true);
  5668. return function nextTick(fn) {
  5669. queue.push(fn);
  5670. window.postMessage('process-tick', '*');
  5671. };
  5672. }
  5673. return function nextTick(fn) {
  5674. setTimeout(fn, 0);
  5675. };
  5676. })();
  5677. process.title = 'browser';
  5678. process.browser = true;
  5679. process.env = {};
  5680. process.argv = [];
  5681. process.binding = function (name) {
  5682. throw new Error('process.binding is not supported');
  5683. }
  5684. // TODO(shtylman)
  5685. process.cwd = function () { return '/' };
  5686. process.chdir = function (dir) {
  5687. throw new Error('process.chdir is not supported');
  5688. };
  5689. },{}],4:[function(require,module,exports){
  5690. (function(process){if (!process.EventEmitter) process.EventEmitter = function () {};
  5691. var EventEmitter = exports.EventEmitter = process.EventEmitter;
  5692. var isArray = typeof Array.isArray === 'function'
  5693. ? Array.isArray
  5694. : function (xs) {
  5695. return Object.prototype.toString.call(xs) === '[object Array]'
  5696. }
  5697. ;
  5698. function indexOf (xs, x) {
  5699. if (xs.indexOf) return xs.indexOf(x);
  5700. for (var i = 0; i < xs.length; i++) {
  5701. if (x === xs[i]) return i;
  5702. }
  5703. return -1;
  5704. }
  5705. // By default EventEmitters will print a warning if more than
  5706. // 10 listeners are added to it. This is a useful default which
  5707. // helps finding memory leaks.
  5708. //
  5709. // Obviously not all Emitters should be limited to 10. This function allows
  5710. // that to be increased. Set to zero for unlimited.
  5711. var defaultMaxListeners = 10;
  5712. EventEmitter.prototype.setMaxListeners = function(n) {
  5713. if (!this._events) this._events = {};
  5714. this._events.maxListeners = n;
  5715. };
  5716. EventEmitter.prototype.emit = function(type) {
  5717. // If there is no 'error' event listener then throw.
  5718. if (type === 'error') {
  5719. if (!this._events || !this._events.error ||
  5720. (isArray(this._events.error) && !this._events.error.length))
  5721. {
  5722. if (arguments[1] instanceof Error) {
  5723. throw arguments[1]; // Unhandled 'error' event
  5724. } else {
  5725. throw new Error("Uncaught, unspecified 'error' event.");
  5726. }
  5727. return false;
  5728. }
  5729. }
  5730. if (!this._events) return false;
  5731. var handler = this._events[type];
  5732. if (!handler) return false;
  5733. if (typeof handler == 'function') {
  5734. switch (arguments.length) {
  5735. // fast cases
  5736. case 1:
  5737. handler.call(this);
  5738. break;
  5739. case 2:
  5740. handler.call(this, arguments[1]);
  5741. break;
  5742. case 3:
  5743. handler.call(this, arguments[1], arguments[2]);
  5744. break;
  5745. // slower
  5746. default:
  5747. var args = Array.prototype.slice.call(arguments, 1);
  5748. handler.apply(this, args);
  5749. }
  5750. return true;
  5751. } else if (isArray(handler)) {
  5752. var args = Array.prototype.slice.call(arguments, 1);
  5753. var listeners = handler.slice();
  5754. for (var i = 0, l = listeners.length; i < l; i++) {
  5755. listeners[i].apply(this, args);
  5756. }
  5757. return true;
  5758. } else {
  5759. return false;
  5760. }
  5761. };
  5762. // EventEmitter is defined in src/node_events.cc
  5763. // EventEmitter.prototype.emit() is also defined there.
  5764. EventEmitter.prototype.addListener = function(type, listener) {
  5765. if ('function' !== typeof listener) {
  5766. throw new Error('addListener only takes instances of Function');
  5767. }
  5768. if (!this._events) this._events = {};
  5769. // To avoid recursion in the case that type == "newListeners"! Before
  5770. // adding it to the listeners, first emit "newListeners".
  5771. this.emit('newListener', type, listener);
  5772. if (!this._events[type]) {
  5773. // Optimize the case of one listener. Don't need the extra array object.
  5774. this._events[type] = listener;
  5775. } else if (isArray(this._events[type])) {
  5776. // Check for listener leak
  5777. if (!this._events[type].warned) {
  5778. var m;
  5779. if (this._events.maxListeners !== undefined) {
  5780. m = this._events.maxListeners;
  5781. } else {
  5782. m = defaultMaxListeners;
  5783. }
  5784. if (m && m > 0 && this._events[type].length > m) {
  5785. this._events[type].warned = true;
  5786. console.error('(node) warning: possible EventEmitter memory ' +
  5787. 'leak detected. %d listeners added. ' +
  5788. 'Use emitter.setMaxListeners() to increase limit.',
  5789. this._events[type].length);
  5790. console.trace();
  5791. }
  5792. }
  5793. // If we've already got an array, just append.
  5794. this._events[type].push(listener);
  5795. } else {
  5796. // Adding the second element, need to change to array.
  5797. this._events[type] = [this._events[type], listener];
  5798. }
  5799. return this;
  5800. };
  5801. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  5802. EventEmitter.prototype.once = function(type, listener) {
  5803. var self = this;
  5804. self.on(type, function g() {
  5805. self.removeListener(type, g);
  5806. listener.apply(this, arguments);
  5807. });
  5808. return this;
  5809. };
  5810. EventEmitter.prototype.removeListener = function(type, listener) {
  5811. if ('function' !== typeof listener) {
  5812. throw new Error('removeListener only takes instances of Function');
  5813. }
  5814. // does not use listeners(), so no side effect of creating _events[type]
  5815. if (!this._events || !this._events[type]) return this;
  5816. var list = this._events[type];
  5817. if (isArray(list)) {
  5818. var i = indexOf(list, listener);
  5819. if (i < 0) return this;
  5820. list.splice(i, 1);
  5821. if (list.length == 0)
  5822. delete this._events[type];
  5823. } else if (this._events[type] === listener) {
  5824. delete this._events[type];
  5825. }
  5826. return this;
  5827. };
  5828. EventEmitter.prototype.removeAllListeners = function(type) {
  5829. if (arguments.length === 0) {
  5830. this._events = {};
  5831. return this;
  5832. }
  5833. // does not use listeners(), so no side effect of creating _events[type]
  5834. if (type && this._events && this._events[type]) this._events[type] = null;
  5835. return this;
  5836. };
  5837. EventEmitter.prototype.listeners = function(type) {
  5838. if (!this._events) this._events = {};
  5839. if (!this._events[type]) this._events[type] = [];
  5840. if (!isArray(this._events[type])) {
  5841. this._events[type] = [this._events[type]];
  5842. }
  5843. return this._events[type];
  5844. };
  5845. })(require("__browserify_process"))
  5846. },{"__browserify_process":6}],"buffer-browserify":[function(require,module,exports){
  5847. module.exports=require('q9TxCC');
  5848. },{}],"q9TxCC":[function(require,module,exports){
  5849. function SlowBuffer (size) {
  5850. this.length = size;
  5851. };
  5852. var assert = require('assert');
  5853. exports.INSPECT_MAX_BYTES = 50;
  5854. function toHex(n) {
  5855. if (n < 16) return '0' + n.toString(16);
  5856. return n.toString(16);
  5857. }
  5858. function utf8ToBytes(str) {
  5859. var byteArray = [];
  5860. for (var i = 0; i < str.length; i++)
  5861. if (str.charCodeAt(i) <= 0x7F)
  5862. byteArray.push(str.charCodeAt(i));
  5863. else {
  5864. var h = encodeURIComponent(str.charAt(i)).substr(1).split('%');
  5865. for (var j = 0; j < h.length; j++)
  5866. byteArray.push(parseInt(h[j], 16));
  5867. }
  5868. return byteArray;
  5869. }
  5870. function asciiToBytes(str) {
  5871. var byteArray = []
  5872. for (var i = 0; i < str.length; i++ )
  5873. // Node's code seems to be doing this and not & 0x7F..
  5874. byteArray.push( str.charCodeAt(i) & 0xFF );
  5875. return byteArray;
  5876. }
  5877. function base64ToBytes(str) {
  5878. return require("base64-js").toByteArray(str);
  5879. }
  5880. SlowBuffer.byteLength = function (str, encoding) {
  5881. switch (encoding || "utf8") {
  5882. case 'hex':
  5883. return str.length / 2;
  5884. case 'utf8':
  5885. case 'utf-8':
  5886. return utf8ToBytes(str).length;
  5887. case 'ascii':
  5888. case 'binary':
  5889. return str.length;
  5890. case 'base64':
  5891. return base64ToBytes(str).length;
  5892. default:
  5893. throw new Error('Unknown encoding');
  5894. }
  5895. };
  5896. function blitBuffer(src, dst, offset, length) {
  5897. var pos, i = 0;
  5898. while (i < length) {
  5899. if ((i+offset >= dst.length) || (i >= src.length))
  5900. break;
  5901. dst[i + offset] = src[i];
  5902. i++;
  5903. }
  5904. return i;
  5905. }
  5906. SlowBuffer.prototype.utf8Write = function (string, offset, length) {
  5907. var bytes, pos;
  5908. return SlowBuffer._charsWritten = blitBuffer(utf8ToBytes(string), this, offset, length);
  5909. };
  5910. SlowBuffer.prototype.asciiWrite = function (string, offset, length) {
  5911. var bytes, pos;
  5912. return SlowBuffer._charsWritten = blitBuffer(asciiToBytes(string), this, offset, length);
  5913. };
  5914. SlowBuffer.prototype.binaryWrite = SlowBuffer.prototype.asciiWrite;
  5915. SlowBuffer.prototype.base64Write = function (string, offset, length) {
  5916. var bytes, pos;
  5917. return SlowBuffer._charsWritten = blitBuffer(base64ToBytes(string), this, offset, length);
  5918. };
  5919. SlowBuffer.prototype.base64Slice = function (start, end) {
  5920. var bytes = Array.prototype.slice.apply(this, arguments)
  5921. return require("base64-js").fromByteArray(bytes);
  5922. }
  5923. function decodeUtf8Char(str) {
  5924. try {
  5925. return decodeURIComponent(str);
  5926. } catch (err) {
  5927. return String.fromCharCode(0xFFFD); // UTF 8 invalid char
  5928. }
  5929. }
  5930. SlowBuffer.prototype.utf8Slice = function () {
  5931. var bytes = Array.prototype.slice.apply(this, arguments);
  5932. var res = "";
  5933. var tmp = "";
  5934. var i = 0;
  5935. while (i < bytes.length) {
  5936. if (bytes[i] <= 0x7F) {
  5937. res += decodeUtf8Char(tmp) + String.fromCharCode(bytes[i]);
  5938. tmp = "";
  5939. } else
  5940. tmp += "%" + bytes[i].toString(16);
  5941. i++;
  5942. }
  5943. return res + decodeUtf8Char(tmp);
  5944. }
  5945. SlowBuffer.prototype.asciiSlice = function () {
  5946. var bytes = Array.prototype.slice.apply(this, arguments);
  5947. var ret = "";
  5948. for (var i = 0; i < bytes.length; i++)
  5949. ret += String.fromCharCode(bytes[i]);
  5950. return ret;
  5951. }
  5952. SlowBuffer.prototype.binarySlice = SlowBuffer.prototype.asciiSlice;
  5953. SlowBuffer.prototype.inspect = function() {
  5954. var out = [],
  5955. len = this.length;
  5956. for (var i = 0; i < len; i++) {
  5957. out[i] = toHex(this[i]);
  5958. if (i == exports.INSPECT_MAX_BYTES) {
  5959. out[i + 1] = '...';
  5960. break;
  5961. }
  5962. }
  5963. return '<SlowBuffer ' + out.join(' ') + '>';
  5964. };
  5965. SlowBuffer.prototype.hexSlice = function(start, end) {
  5966. var len = this.length;
  5967. if (!start || start < 0) start = 0;
  5968. if (!end || end < 0 || end > len) end = len;
  5969. var out = '';
  5970. for (var i = start; i < end; i++) {
  5971. out += toHex(this[i]);
  5972. }
  5973. return out;
  5974. };
  5975. SlowBuffer.prototype.toString = function(encoding, start, end) {
  5976. encoding = String(encoding || 'utf8').toLowerCase();
  5977. start = +start || 0;
  5978. if (typeof end == 'undefined') end = this.length;
  5979. // Fastpath empty strings
  5980. if (+end == start) {
  5981. return '';
  5982. }
  5983. switch (encoding) {
  5984. case 'hex':
  5985. return this.hexSlice(start, end);
  5986. case 'utf8':
  5987. case 'utf-8':
  5988. return this.utf8Slice(start, end);
  5989. case 'ascii':
  5990. return this.asciiSlice(start, end);
  5991. case 'binary':
  5992. return this.binarySlice(start, end);
  5993. case 'base64':
  5994. return this.base64Slice(start, end);
  5995. case 'ucs2':
  5996. case 'ucs-2':
  5997. return this.ucs2Slice(start, end);
  5998. default:
  5999. throw new Error('Unknown encoding');
  6000. }
  6001. };
  6002. SlowBuffer.prototype.hexWrite = function(string, offset, length) {
  6003. offset = +offset || 0;
  6004. var remaining = this.length - offset;
  6005. if (!length) {
  6006. length = remaining;
  6007. } else {
  6008. length = +length;
  6009. if (length > remaining) {
  6010. length = remaining;
  6011. }
  6012. }
  6013. // must be an even number of digits
  6014. var strLen = string.length;
  6015. if (strLen % 2) {
  6016. throw new Error('Invalid hex string');
  6017. }
  6018. if (length > strLen / 2) {
  6019. length = strLen / 2;
  6020. }
  6021. for (var i = 0; i < length; i++) {
  6022. var byte = parseInt(string.substr(i * 2, 2), 16);
  6023. if (isNaN(byte)) throw new Error('Invalid hex string');
  6024. this[offset + i] = byte;
  6025. }
  6026. SlowBuffer._charsWritten = i * 2;
  6027. return i;
  6028. };
  6029. SlowBuffer.prototype.write = function(string, offset, length, encoding) {
  6030. // Support both (string, offset, length, encoding)
  6031. // and the legacy (string, encoding, offset, length)
  6032. if (isFinite(offset)) {
  6033. if (!isFinite(length)) {
  6034. encoding = length;
  6035. length = undefined;
  6036. }
  6037. } else { // legacy
  6038. var swap = encoding;
  6039. encoding = offset;
  6040. offset = length;
  6041. length = swap;
  6042. }
  6043. offset = +offset || 0;
  6044. var remaining = this.length - offset;
  6045. if (!length) {
  6046. length = remaining;
  6047. } else {
  6048. length = +length;
  6049. if (length > remaining) {
  6050. length = remaining;
  6051. }
  6052. }
  6053. encoding = String(encoding || 'utf8').toLowerCase();
  6054. switch (encoding) {
  6055. case 'hex':
  6056. return this.hexWrite(string, offset, length);
  6057. case 'utf8':
  6058. case 'utf-8':
  6059. return this.utf8Write(string, offset, length);
  6060. case 'ascii':
  6061. return this.asciiWrite(string, offset, length);
  6062. case 'binary':
  6063. return this.binaryWrite(string, offset, length);
  6064. case 'base64':
  6065. return this.base64Write(string, offset, length);
  6066. case 'ucs2':
  6067. case 'ucs-2':
  6068. return this.ucs2Write(string, offset, length);
  6069. default:
  6070. throw new Error('Unknown encoding');
  6071. }
  6072. };
  6073. // slice(start, end)
  6074. SlowBuffer.prototype.slice = function(start, end) {
  6075. if (end === undefined) end = this.length;
  6076. if (end > this.length) {
  6077. throw new Error('oob');
  6078. }
  6079. if (start > end) {
  6080. throw new Error('oob');
  6081. }
  6082. return new Buffer(this, end - start, +start);
  6083. };
  6084. SlowBuffer.prototype.copy = function(target, targetstart, sourcestart, sourceend) {
  6085. var temp = [];
  6086. for (var i=sourcestart; i<sourceend; i++) {
  6087. assert.ok(typeof this[i] !== 'undefined', "copying undefined buffer bytes!");
  6088. temp.push(this[i]);
  6089. }
  6090. for (var i=targetstart; i<targetstart+temp.length; i++) {
  6091. target[i] = temp[i-targetstart];
  6092. }
  6093. };
  6094. SlowBuffer.prototype.fill = function(value, start, end) {
  6095. if (end > this.length) {
  6096. throw new Error('oob');
  6097. }
  6098. if (start > end) {
  6099. throw new Error('oob');
  6100. }
  6101. for (var i = start; i < end; i++) {
  6102. this[i] = value;
  6103. }
  6104. }
  6105. function coerce(length) {
  6106. // Coerce length to a number (possibly NaN), round up
  6107. // in case it's fractional (e.g. 123.456) then do a
  6108. // double negate to coerce a NaN to 0. Easy, right?
  6109. length = ~~Math.ceil(+length);
  6110. return length < 0 ? 0 : length;
  6111. }
  6112. // Buffer
  6113. function Buffer(subject, encoding, offset) {
  6114. if (!(this instanceof Buffer)) {
  6115. return new Buffer(subject, encoding, offset);
  6116. }
  6117. var type;
  6118. // Are we slicing?
  6119. if (typeof offset === 'number') {
  6120. this.length = coerce(encoding);
  6121. this.parent = subject;
  6122. this.offset = offset;
  6123. } else {
  6124. // Find the length
  6125. switch (type = typeof subject) {
  6126. case 'number':
  6127. this.length = coerce(subject);
  6128. break;
  6129. case 'string':
  6130. this.length = Buffer.byteLength(subject, encoding);
  6131. break;
  6132. case 'object': // Assume object is an array
  6133. this.length = coerce(subject.length);
  6134. break;
  6135. default:
  6136. throw new Error('First argument needs to be a number, ' +
  6137. 'array or string.');
  6138. }
  6139. if (this.length > Buffer.poolSize) {
  6140. // Big buffer, just alloc one.
  6141. this.parent = new SlowBuffer(this.length);
  6142. this.offset = 0;
  6143. } else {
  6144. // Small buffer.
  6145. if (!pool || pool.length - pool.used < this.length) allocPool();
  6146. this.parent = pool;
  6147. this.offset = pool.used;
  6148. pool.used += this.length;
  6149. }
  6150. // Treat array-ish objects as a byte array.
  6151. if (isArrayIsh(subject)) {
  6152. for (var i = 0; i < this.length; i++) {
  6153. if (subject instanceof Buffer) {
  6154. this.parent[i + this.offset] = subject.readUInt8(i);
  6155. }
  6156. else {
  6157. this.parent[i + this.offset] = subject[i];
  6158. }
  6159. }
  6160. } else if (type == 'string') {
  6161. // We are a string
  6162. this.length = this.write(subject, 0, encoding);
  6163. }
  6164. }
  6165. }
  6166. function isArrayIsh(subject) {
  6167. return Array.isArray(subject) || Buffer.isBuffer(subject) ||
  6168. subject && typeof subject === 'object' &&
  6169. typeof subject.length === 'number';
  6170. }
  6171. exports.SlowBuffer = SlowBuffer;
  6172. exports.Buffer = Buffer;
  6173. Buffer.poolSize = 8 * 1024;
  6174. var pool;
  6175. function allocPool() {
  6176. pool = new SlowBuffer(Buffer.poolSize);
  6177. pool.used = 0;
  6178. }
  6179. // Static methods
  6180. Buffer.isBuffer = function isBuffer(b) {
  6181. return b instanceof Buffer || b instanceof SlowBuffer;
  6182. };
  6183. Buffer.concat = function (list, totalLength) {
  6184. if (!Array.isArray(list)) {
  6185. throw new Error("Usage: Buffer.concat(list, [totalLength])\n \
  6186. list should be an Array.");
  6187. }
  6188. if (list.length === 0) {
  6189. return new Buffer(0);
  6190. } else if (list.length === 1) {
  6191. return list[0];
  6192. }
  6193. if (typeof totalLength !== 'number') {
  6194. totalLength = 0;
  6195. for (var i = 0; i < list.length; i++) {
  6196. var buf = list[i];
  6197. totalLength += buf.length;
  6198. }
  6199. }
  6200. var buffer = new Buffer(totalLength);
  6201. var pos = 0;
  6202. for (var i = 0; i < list.length; i++) {
  6203. var buf = list[i];
  6204. buf.copy(buffer, pos);
  6205. pos += buf.length;
  6206. }
  6207. return buffer;
  6208. };
  6209. // Inspect
  6210. Buffer.prototype.inspect = function inspect() {
  6211. var out = [],
  6212. len = this.length;
  6213. for (var i = 0; i < len; i++) {
  6214. out[i] = toHex(this.parent[i + this.offset]);
  6215. if (i == exports.INSPECT_MAX_BYTES) {
  6216. out[i + 1] = '...';
  6217. break;
  6218. }
  6219. }
  6220. return '<Buffer ' + out.join(' ') + '>';
  6221. };
  6222. Buffer.prototype.get = function get(i) {
  6223. if (i < 0 || i >= this.length) throw new Error('oob');
  6224. return this.parent[this.offset + i];
  6225. };
  6226. Buffer.prototype.set = function set(i, v) {
  6227. if (i < 0 || i >= this.length) throw new Error('oob');
  6228. return this.parent[this.offset + i] = v;
  6229. };
  6230. // write(string, offset = 0, length = buffer.length-offset, encoding = 'utf8')
  6231. Buffer.prototype.write = function(string, offset, length, encoding) {
  6232. // Support both (string, offset, length, encoding)
  6233. // and the legacy (string, encoding, offset, length)
  6234. if (isFinite(offset)) {
  6235. if (!isFinite(length)) {
  6236. encoding = length;
  6237. length = undefined;
  6238. }
  6239. } else { // legacy
  6240. var swap = encoding;
  6241. encoding = offset;
  6242. offset = length;
  6243. length = swap;
  6244. }
  6245. offset = +offset || 0;
  6246. var remaining = this.length - offset;
  6247. if (!length) {
  6248. length = remaining;
  6249. } else {
  6250. length = +length;
  6251. if (length > remaining) {
  6252. length = remaining;
  6253. }
  6254. }
  6255. encoding = String(encoding || 'utf8').toLowerCase();
  6256. var ret;
  6257. switch (encoding) {
  6258. case 'hex':
  6259. ret = this.parent.hexWrite(string, this.offset + offset, length);
  6260. break;
  6261. case 'utf8':
  6262. case 'utf-8':
  6263. ret = this.parent.utf8Write(string, this.offset + offset, length);
  6264. break;
  6265. case 'ascii':
  6266. ret = this.parent.asciiWrite(string, this.offset + offset, length);
  6267. break;
  6268. case 'binary':
  6269. ret = this.parent.binaryWrite(string, this.offset + offset, length);
  6270. break;
  6271. case 'base64':
  6272. // Warning: maxLength not taken into account in base64Write
  6273. ret = this.parent.base64Write(string, this.offset + offset, length);
  6274. break;
  6275. case 'ucs2':
  6276. case 'ucs-2':
  6277. ret = this.parent.ucs2Write(string, this.offset + offset, length);
  6278. break;
  6279. default:
  6280. throw new Error('Unknown encoding');
  6281. }
  6282. Buffer._charsWritten = SlowBuffer._charsWritten;
  6283. return ret;
  6284. };
  6285. // toString(encoding, start=0, end=buffer.length)
  6286. Buffer.prototype.toString = function(encoding, start, end) {
  6287. encoding = String(encoding || 'utf8').toLowerCase();
  6288. if (typeof start == 'undefined' || start < 0) {
  6289. start = 0;
  6290. } else if (start > this.length) {
  6291. start = this.length;
  6292. }
  6293. if (typeof end == 'undefined' || end > this.length) {
  6294. end = this.length;
  6295. } else if (end < 0) {
  6296. end = 0;
  6297. }
  6298. start = start + this.offset;
  6299. end = end + this.offset;
  6300. switch (encoding) {
  6301. case 'hex':
  6302. return this.parent.hexSlice(start, end);
  6303. case 'utf8':
  6304. case 'utf-8':
  6305. return this.parent.utf8Slice(start, end);
  6306. case 'ascii':
  6307. return this.parent.asciiSlice(start, end);
  6308. case 'binary':
  6309. return this.parent.binarySlice(start, end);
  6310. case 'base64':
  6311. return this.parent.base64Slice(start, end);
  6312. case 'ucs2':
  6313. case 'ucs-2':
  6314. return this.parent.ucs2Slice(start, end);
  6315. default:
  6316. throw new Error('Unknown encoding');
  6317. }
  6318. };
  6319. // byteLength
  6320. Buffer.byteLength = SlowBuffer.byteLength;
  6321. // fill(value, start=0, end=buffer.length)
  6322. Buffer.prototype.fill = function fill(value, start, end) {
  6323. value || (value = 0);
  6324. start || (start = 0);
  6325. end || (end = this.length);
  6326. if (typeof value === 'string') {
  6327. value = value.charCodeAt(0);
  6328. }
  6329. if (!(typeof value === 'number') || isNaN(value)) {
  6330. throw new Error('value is not a number');
  6331. }
  6332. if (end < start) throw new Error('end < start');
  6333. // Fill 0 bytes; we're done
  6334. if (end === start) return 0;
  6335. if (this.length == 0) return 0;
  6336. if (start < 0 || start >= this.length) {
  6337. throw new Error('start out of bounds');
  6338. }
  6339. if (end < 0 || end > this.length) {
  6340. throw new Error('end out of bounds');
  6341. }
  6342. return this.parent.fill(value,
  6343. start + this.offset,
  6344. end + this.offset);
  6345. };
  6346. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  6347. Buffer.prototype.copy = function(target, target_start, start, end) {
  6348. var source = this;
  6349. start || (start = 0);
  6350. end || (end = this.length);
  6351. target_start || (target_start = 0);
  6352. if (end < start) throw new Error('sourceEnd < sourceStart');
  6353. // Copy 0 bytes; we're done
  6354. if (end === start) return 0;
  6355. if (target.length == 0 || source.length == 0) return 0;
  6356. if (target_start < 0 || target_start >= target.length) {
  6357. throw new Error('targetStart out of bounds');
  6358. }
  6359. if (start < 0 || start >= source.length) {
  6360. throw new Error('sourceStart out of bounds');
  6361. }
  6362. if (end < 0 || end > source.length) {
  6363. throw new Error('sourceEnd out of bounds');
  6364. }
  6365. // Are we oob?
  6366. if (end > this.length) {
  6367. end = this.length;
  6368. }
  6369. if (target.length - target_start < end - start) {
  6370. end = target.length - target_start + start;
  6371. }
  6372. return this.parent.copy(target.parent,
  6373. target_start + target.offset,
  6374. start + this.offset,
  6375. end + this.offset);
  6376. };
  6377. // slice(start, end)
  6378. Buffer.prototype.slice = function(start, end) {
  6379. if (end === undefined) end = this.length;
  6380. if (end > this.length) throw new Error('oob');
  6381. if (start > end) throw new Error('oob');
  6382. return new Buffer(this.parent, end - start, +start + this.offset);
  6383. };
  6384. // Legacy methods for backwards compatibility.
  6385. Buffer.prototype.utf8Slice = function(start, end) {
  6386. return this.toString('utf8', start, end);
  6387. };
  6388. Buffer.prototype.binarySlice = function(start, end) {
  6389. return this.toString('binary', start, end);
  6390. };
  6391. Buffer.prototype.asciiSlice = function(start, end) {
  6392. return this.toString('ascii', start, end);
  6393. };
  6394. Buffer.prototype.utf8Write = function(string, offset) {
  6395. return this.write(string, offset, 'utf8');
  6396. };
  6397. Buffer.prototype.binaryWrite = function(string, offset) {
  6398. return this.write(string, offset, 'binary');
  6399. };
  6400. Buffer.prototype.asciiWrite = function(string, offset) {
  6401. return this.write(string, offset, 'ascii');
  6402. };
  6403. Buffer.prototype.readUInt8 = function(offset, noAssert) {
  6404. var buffer = this;
  6405. if (!noAssert) {
  6406. assert.ok(offset !== undefined && offset !== null,
  6407. 'missing offset');
  6408. assert.ok(offset < buffer.length,
  6409. 'Trying to read beyond buffer length');
  6410. }
  6411. if (offset >= buffer.length) return;
  6412. return buffer.parent[buffer.offset + offset];
  6413. };
  6414. function readUInt16(buffer, offset, isBigEndian, noAssert) {
  6415. var val = 0;
  6416. if (!noAssert) {
  6417. assert.ok(typeof (isBigEndian) === 'boolean',
  6418. 'missing or invalid endian');
  6419. assert.ok(offset !== undefined && offset !== null,
  6420. 'missing offset');
  6421. assert.ok(offset + 1 < buffer.length,
  6422. 'Trying to read beyond buffer length');
  6423. }
  6424. if (offset >= buffer.length) return 0;
  6425. if (isBigEndian) {
  6426. val = buffer.parent[buffer.offset + offset] << 8;
  6427. if (offset + 1 < buffer.length) {
  6428. val |= buffer.parent[buffer.offset + offset + 1];
  6429. }
  6430. } else {
  6431. val = buffer.parent[buffer.offset + offset];
  6432. if (offset + 1 < buffer.length) {
  6433. val |= buffer.parent[buffer.offset + offset + 1] << 8;
  6434. }
  6435. }
  6436. return val;
  6437. }
  6438. Buffer.prototype.readUInt16LE = function(offset, noAssert) {
  6439. return readUInt16(this, offset, false, noAssert);
  6440. };
  6441. Buffer.prototype.readUInt16BE = function(offset, noAssert) {
  6442. return readUInt16(this, offset, true, noAssert);
  6443. };
  6444. function readUInt32(buffer, offset, isBigEndian, noAssert) {
  6445. var val = 0;
  6446. if (!noAssert) {
  6447. assert.ok(typeof (isBigEndian) === 'boolean',
  6448. 'missing or invalid endian');
  6449. assert.ok(offset !== undefined && offset !== null,
  6450. 'missing offset');
  6451. assert.ok(offset + 3 < buffer.length,
  6452. 'Trying to read beyond buffer length');
  6453. }
  6454. if (offset >= buffer.length) return 0;
  6455. if (isBigEndian) {
  6456. if (offset + 1 < buffer.length)
  6457. val = buffer.parent[buffer.offset + offset + 1] << 16;
  6458. if (offset + 2 < buffer.length)
  6459. val |= buffer.parent[buffer.offset + offset + 2] << 8;
  6460. if (offset + 3 < buffer.length)
  6461. val |= buffer.parent[buffer.offset + offset + 3];
  6462. val = val + (buffer.parent[buffer.offset + offset] << 24 >>> 0);
  6463. } else {
  6464. if (offset + 2 < buffer.length)
  6465. val = buffer.parent[buffer.offset + offset + 2] << 16;
  6466. if (offset + 1 < buffer.length)
  6467. val |= buffer.parent[buffer.offset + offset + 1] << 8;
  6468. val |= buffer.parent[buffer.offset + offset];
  6469. if (offset + 3 < buffer.length)
  6470. val = val + (buffer.parent[buffer.offset + offset + 3] << 24 >>> 0);
  6471. }
  6472. return val;
  6473. }
  6474. Buffer.prototype.readUInt32LE = function(offset, noAssert) {
  6475. return readUInt32(this, offset, false, noAssert);
  6476. };
  6477. Buffer.prototype.readUInt32BE = function(offset, noAssert) {
  6478. return readUInt32(this, offset, true, noAssert);
  6479. };
  6480. /*
  6481. * Signed integer types, yay team! A reminder on how two's complement actually
  6482. * works. The first bit is the signed bit, i.e. tells us whether or not the
  6483. * number should be positive or negative. If the two's complement value is
  6484. * positive, then we're done, as it's equivalent to the unsigned representation.
  6485. *
  6486. * Now if the number is positive, you're pretty much done, you can just leverage
  6487. * the unsigned translations and return those. Unfortunately, negative numbers
  6488. * aren't quite that straightforward.
  6489. *
  6490. * At first glance, one might be inclined to use the traditional formula to
  6491. * translate binary numbers between the positive and negative values in two's
  6492. * complement. (Though it doesn't quite work for the most negative value)
  6493. * Mainly:
  6494. * - invert all the bits
  6495. * - add one to the result
  6496. *
  6497. * Of course, this doesn't quite work in Javascript. Take for example the value
  6498. * of -128. This could be represented in 16 bits (big-endian) as 0xff80. But of
  6499. * course, Javascript will do the following:
  6500. *
  6501. * > ~0xff80
  6502. * -65409
  6503. *
  6504. * Whoh there, Javascript, that's not quite right. But wait, according to
  6505. * Javascript that's perfectly correct. When Javascript ends up seeing the
  6506. * constant 0xff80, it has no notion that it is actually a signed number. It
  6507. * assumes that we've input the unsigned value 0xff80. Thus, when it does the
  6508. * binary negation, it casts it into a signed value, (positive 0xff80). Then
  6509. * when you perform binary negation on that, it turns it into a negative number.
  6510. *
  6511. * Instead, we're going to have to use the following general formula, that works
  6512. * in a rather Javascript friendly way. I'm glad we don't support this kind of
  6513. * weird numbering scheme in the kernel.
  6514. *
  6515. * (BIT-MAX - (unsigned)val + 1) * -1
  6516. *
  6517. * The astute observer, may think that this doesn't make sense for 8-bit numbers
  6518. * (really it isn't necessary for them). However, when you get 16-bit numbers,
  6519. * you do. Let's go back to our prior example and see how this will look:
  6520. *
  6521. * (0xffff - 0xff80 + 1) * -1
  6522. * (0x007f + 1) * -1
  6523. * (0x0080) * -1
  6524. */
  6525. Buffer.prototype.readInt8 = function(offset, noAssert) {
  6526. var buffer = this;
  6527. var neg;
  6528. if (!noAssert) {
  6529. assert.ok(offset !== undefined && offset !== null,
  6530. 'missing offset');
  6531. assert.ok(offset < buffer.length,
  6532. 'Trying to read beyond buffer length');
  6533. }
  6534. if (offset >= buffer.length) return;
  6535. neg = buffer.parent[buffer.offset + offset] & 0x80;
  6536. if (!neg) {
  6537. return (buffer.parent[buffer.offset + offset]);
  6538. }
  6539. return ((0xff - buffer.parent[buffer.offset + offset] + 1) * -1);
  6540. };
  6541. function readInt16(buffer, offset, isBigEndian, noAssert) {
  6542. var neg, val;
  6543. if (!noAssert) {
  6544. assert.ok(typeof (isBigEndian) === 'boolean',
  6545. 'missing or invalid endian');
  6546. assert.ok(offset !== undefined && offset !== null,
  6547. 'missing offset');
  6548. assert.ok(offset + 1 < buffer.length,
  6549. 'Trying to read beyond buffer length');
  6550. }
  6551. val = readUInt16(buffer, offset, isBigEndian, noAssert);
  6552. neg = val & 0x8000;
  6553. if (!neg) {
  6554. return val;
  6555. }
  6556. return (0xffff - val + 1) * -1;
  6557. }
  6558. Buffer.prototype.readInt16LE = function(offset, noAssert) {
  6559. return readInt16(this, offset, false, noAssert);
  6560. };
  6561. Buffer.prototype.readInt16BE = function(offset, noAssert) {
  6562. return readInt16(this, offset, true, noAssert);
  6563. };
  6564. function readInt32(buffer, offset, isBigEndian, noAssert) {
  6565. var neg, val;
  6566. if (!noAssert) {
  6567. assert.ok(typeof (isBigEndian) === 'boolean',
  6568. 'missing or invalid endian');
  6569. assert.ok(offset !== undefined && offset !== null,
  6570. 'missing offset');
  6571. assert.ok(offset + 3 < buffer.length,
  6572. 'Trying to read beyond buffer length');
  6573. }
  6574. val = readUInt32(buffer, offset, isBigEndian, noAssert);
  6575. neg = val & 0x80000000;
  6576. if (!neg) {
  6577. return (val);
  6578. }
  6579. return (0xffffffff - val + 1) * -1;
  6580. }
  6581. Buffer.prototype.readInt32LE = function(offset, noAssert) {
  6582. return readInt32(this, offset, false, noAssert);
  6583. };
  6584. Buffer.prototype.readInt32BE = function(offset, noAssert) {
  6585. return readInt32(this, offset, true, noAssert);
  6586. };
  6587. function readFloat(buffer, offset, isBigEndian, noAssert) {
  6588. if (!noAssert) {
  6589. assert.ok(typeof (isBigEndian) === 'boolean',
  6590. 'missing or invalid endian');
  6591. assert.ok(offset + 3 < buffer.length,
  6592. 'Trying to read beyond buffer length');
  6593. }
  6594. return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
  6595. 23, 4);
  6596. }
  6597. Buffer.prototype.readFloatLE = function(offset, noAssert) {
  6598. return readFloat(this, offset, false, noAssert);
  6599. };
  6600. Buffer.prototype.readFloatBE = function(offset, noAssert) {
  6601. return readFloat(this, offset, true, noAssert);
  6602. };
  6603. function readDouble(buffer, offset, isBigEndian, noAssert) {
  6604. if (!noAssert) {
  6605. assert.ok(typeof (isBigEndian) === 'boolean',
  6606. 'missing or invalid endian');
  6607. assert.ok(offset + 7 < buffer.length,
  6608. 'Trying to read beyond buffer length');
  6609. }
  6610. return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
  6611. 52, 8);
  6612. }
  6613. Buffer.prototype.readDoubleLE = function(offset, noAssert) {
  6614. return readDouble(this, offset, false, noAssert);
  6615. };
  6616. Buffer.prototype.readDoubleBE = function(offset, noAssert) {
  6617. return readDouble(this, offset, true, noAssert);
  6618. };
  6619. /*
  6620. * We have to make sure that the value is a valid integer. This means that it is
  6621. * non-negative. It has no fractional component and that it does not exceed the
  6622. * maximum allowed value.
  6623. *
  6624. * value The number to check for validity
  6625. *
  6626. * max The maximum value
  6627. */
  6628. function verifuint(value, max) {
  6629. assert.ok(typeof (value) == 'number',
  6630. 'cannot write a non-number as a number');
  6631. assert.ok(value >= 0,
  6632. 'specified a negative value for writing an unsigned value');
  6633. assert.ok(value <= max, 'value is larger than maximum value for type');
  6634. assert.ok(Math.floor(value) === value, 'value has a fractional component');
  6635. }
  6636. Buffer.prototype.writeUInt8 = function(value, offset, noAssert) {
  6637. var buffer = this;
  6638. if (!noAssert) {
  6639. assert.ok(value !== undefined && value !== null,
  6640. 'missing value');
  6641. assert.ok(offset !== undefined && offset !== null,
  6642. 'missing offset');
  6643. assert.ok(offset < buffer.length,
  6644. 'trying to write beyond buffer length');
  6645. verifuint(value, 0xff);
  6646. }
  6647. if (offset < buffer.length) {
  6648. buffer.parent[buffer.offset + offset] = value;
  6649. }
  6650. };
  6651. function writeUInt16(buffer, value, offset, isBigEndian, noAssert) {
  6652. if (!noAssert) {
  6653. assert.ok(value !== undefined && value !== null,
  6654. 'missing value');
  6655. assert.ok(typeof (isBigEndian) === 'boolean',
  6656. 'missing or invalid endian');
  6657. assert.ok(offset !== undefined && offset !== null,
  6658. 'missing offset');
  6659. assert.ok(offset + 1 < buffer.length,
  6660. 'trying to write beyond buffer length');
  6661. verifuint(value, 0xffff);
  6662. }
  6663. for (var i = 0; i < Math.min(buffer.length - offset, 2); i++) {
  6664. buffer.parent[buffer.offset + offset + i] =
  6665. (value & (0xff << (8 * (isBigEndian ? 1 - i : i)))) >>>
  6666. (isBigEndian ? 1 - i : i) * 8;
  6667. }
  6668. }
  6669. Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) {
  6670. writeUInt16(this, value, offset, false, noAssert);
  6671. };
  6672. Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) {
  6673. writeUInt16(this, value, offset, true, noAssert);
  6674. };
  6675. function writeUInt32(buffer, value, offset, isBigEndian, noAssert) {
  6676. if (!noAssert) {
  6677. assert.ok(value !== undefined && value !== null,
  6678. 'missing value');
  6679. assert.ok(typeof (isBigEndian) === 'boolean',
  6680. 'missing or invalid endian');
  6681. assert.ok(offset !== undefined && offset !== null,
  6682. 'missing offset');
  6683. assert.ok(offset + 3 < buffer.length,
  6684. 'trying to write beyond buffer length');
  6685. verifuint(value, 0xffffffff);
  6686. }
  6687. for (var i = 0; i < Math.min(buffer.length - offset, 4); i++) {
  6688. buffer.parent[buffer.offset + offset + i] =
  6689. (value >>> (isBigEndian ? 3 - i : i) * 8) & 0xff;
  6690. }
  6691. }
  6692. Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) {
  6693. writeUInt32(this, value, offset, false, noAssert);
  6694. };
  6695. Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) {
  6696. writeUInt32(this, value, offset, true, noAssert);
  6697. };
  6698. /*
  6699. * We now move onto our friends in the signed number category. Unlike unsigned
  6700. * numbers, we're going to have to worry a bit more about how we put values into
  6701. * arrays. Since we are only worrying about signed 32-bit values, we're in
  6702. * slightly better shape. Unfortunately, we really can't do our favorite binary
  6703. * & in this system. It really seems to do the wrong thing. For example:
  6704. *
  6705. * > -32 & 0xff
  6706. * 224
  6707. *
  6708. * What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of
  6709. * this aren't treated as a signed number. Ultimately a bad thing.
  6710. *
  6711. * What we're going to want to do is basically create the unsigned equivalent of
  6712. * our representation and pass that off to the wuint* functions. To do that
  6713. * we're going to do the following:
  6714. *
  6715. * - if the value is positive
  6716. * we can pass it directly off to the equivalent wuint
  6717. * - if the value is negative
  6718. * we do the following computation:
  6719. * mb + val + 1, where
  6720. * mb is the maximum unsigned value in that byte size
  6721. * val is the Javascript negative integer
  6722. *
  6723. *
  6724. * As a concrete value, take -128. In signed 16 bits this would be 0xff80. If
  6725. * you do out the computations:
  6726. *
  6727. * 0xffff - 128 + 1
  6728. * 0xffff - 127
  6729. * 0xff80
  6730. *
  6731. * You can then encode this value as the signed version. This is really rather
  6732. * hacky, but it should work and get the job done which is our goal here.
  6733. */
  6734. /*
  6735. * A series of checks to make sure we actually have a signed 32-bit number
  6736. */
  6737. function verifsint(value, max, min) {
  6738. assert.ok(typeof (value) == 'number',
  6739. 'cannot write a non-number as a number');
  6740. assert.ok(value <= max, 'value larger than maximum allowed value');
  6741. assert.ok(value >= min, 'value smaller than minimum allowed value');
  6742. assert.ok(Math.floor(value) === value, 'value has a fractional component');
  6743. }
  6744. function verifIEEE754(value, max, min) {
  6745. assert.ok(typeof (value) == 'number',
  6746. 'cannot write a non-number as a number');
  6747. assert.ok(value <= max, 'value larger than maximum allowed value');
  6748. assert.ok(value >= min, 'value smaller than minimum allowed value');
  6749. }
  6750. Buffer.prototype.writeInt8 = function(value, offset, noAssert) {
  6751. var buffer = this;
  6752. if (!noAssert) {
  6753. assert.ok(value !== undefined && value !== null,
  6754. 'missing value');
  6755. assert.ok(offset !== undefined && offset !== null,
  6756. 'missing offset');
  6757. assert.ok(offset < buffer.length,
  6758. 'Trying to write beyond buffer length');
  6759. verifsint(value, 0x7f, -0x80);
  6760. }
  6761. if (value >= 0) {
  6762. buffer.writeUInt8(value, offset, noAssert);
  6763. } else {
  6764. buffer.writeUInt8(0xff + value + 1, offset, noAssert);
  6765. }
  6766. };
  6767. function writeInt16(buffer, value, offset, isBigEndian, noAssert) {
  6768. if (!noAssert) {
  6769. assert.ok(value !== undefined && value !== null,
  6770. 'missing value');
  6771. assert.ok(typeof (isBigEndian) === 'boolean',
  6772. 'missing or invalid endian');
  6773. assert.ok(offset !== undefined && offset !== null,
  6774. 'missing offset');
  6775. assert.ok(offset + 1 < buffer.length,
  6776. 'Trying to write beyond buffer length');
  6777. verifsint(value, 0x7fff, -0x8000);
  6778. }
  6779. if (value >= 0) {
  6780. writeUInt16(buffer, value, offset, isBigEndian, noAssert);
  6781. } else {
  6782. writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert);
  6783. }
  6784. }
  6785. Buffer.prototype.writeInt16LE = function(value, offset, noAssert) {
  6786. writeInt16(this, value, offset, false, noAssert);
  6787. };
  6788. Buffer.prototype.writeInt16BE = function(value, offset, noAssert) {
  6789. writeInt16(this, value, offset, true, noAssert);
  6790. };
  6791. function writeInt32(buffer, value, offset, isBigEndian, noAssert) {
  6792. if (!noAssert) {
  6793. assert.ok(value !== undefined && value !== null,
  6794. 'missing value');
  6795. assert.ok(typeof (isBigEndian) === 'boolean',
  6796. 'missing or invalid endian');
  6797. assert.ok(offset !== undefined && offset !== null,
  6798. 'missing offset');
  6799. assert.ok(offset + 3 < buffer.length,
  6800. 'Trying to write beyond buffer length');
  6801. verifsint(value, 0x7fffffff, -0x80000000);
  6802. }
  6803. if (value >= 0) {
  6804. writeUInt32(buffer, value, offset, isBigEndian, noAssert);
  6805. } else {
  6806. writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert);
  6807. }
  6808. }
  6809. Buffer.prototype.writeInt32LE = function(value, offset, noAssert) {
  6810. writeInt32(this, value, offset, false, noAssert);
  6811. };
  6812. Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {
  6813. writeInt32(this, value, offset, true, noAssert);
  6814. };
  6815. function writeFloat(buffer, value, offset, isBigEndian, noAssert) {
  6816. if (!noAssert) {
  6817. assert.ok(value !== undefined && value !== null,
  6818. 'missing value');
  6819. assert.ok(typeof (isBigEndian) === 'boolean',
  6820. 'missing or invalid endian');
  6821. assert.ok(offset !== undefined && offset !== null,
  6822. 'missing offset');
  6823. assert.ok(offset + 3 < buffer.length,
  6824. 'Trying to write beyond buffer length');
  6825. verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38);
  6826. }
  6827. require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
  6828. 23, 4);
  6829. }
  6830. Buffer.prototype.writeFloatLE = function(value, offset, noAssert) {
  6831. writeFloat(this, value, offset, false, noAssert);
  6832. };
  6833. Buffer.prototype.writeFloatBE = function(value, offset, noAssert) {
  6834. writeFloat(this, value, offset, true, noAssert);
  6835. };
  6836. function writeDouble(buffer, value, offset, isBigEndian, noAssert) {
  6837. if (!noAssert) {
  6838. assert.ok(value !== undefined && value !== null,
  6839. 'missing value');
  6840. assert.ok(typeof (isBigEndian) === 'boolean',
  6841. 'missing or invalid endian');
  6842. assert.ok(offset !== undefined && offset !== null,
  6843. 'missing offset');
  6844. assert.ok(offset + 7 < buffer.length,
  6845. 'Trying to write beyond buffer length');
  6846. verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308);
  6847. }
  6848. require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
  6849. 52, 8);
  6850. }
  6851. Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) {
  6852. writeDouble(this, value, offset, false, noAssert);
  6853. };
  6854. Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) {
  6855. writeDouble(this, value, offset, true, noAssert);
  6856. };
  6857. SlowBuffer.prototype.readUInt8 = Buffer.prototype.readUInt8;
  6858. SlowBuffer.prototype.readUInt16LE = Buffer.prototype.readUInt16LE;
  6859. SlowBuffer.prototype.readUInt16BE = Buffer.prototype.readUInt16BE;
  6860. SlowBuffer.prototype.readUInt32LE = Buffer.prototype.readUInt32LE;
  6861. SlowBuffer.prototype.readUInt32BE = Buffer.prototype.readUInt32BE;
  6862. SlowBuffer.prototype.readInt8 = Buffer.prototype.readInt8;
  6863. SlowBuffer.prototype.readInt16LE = Buffer.prototype.readInt16LE;
  6864. SlowBuffer.prototype.readInt16BE = Buffer.prototype.readInt16BE;
  6865. SlowBuffer.prototype.readInt32LE = Buffer.prototype.readInt32LE;
  6866. SlowBuffer.prototype.readInt32BE = Buffer.prototype.readInt32BE;
  6867. SlowBuffer.prototype.readFloatLE = Buffer.prototype.readFloatLE;
  6868. SlowBuffer.prototype.readFloatBE = Buffer.prototype.readFloatBE;
  6869. SlowBuffer.prototype.readDoubleLE = Buffer.prototype.readDoubleLE;
  6870. SlowBuffer.prototype.readDoubleBE = Buffer.prototype.readDoubleBE;
  6871. SlowBuffer.prototype.writeUInt8 = Buffer.prototype.writeUInt8;
  6872. SlowBuffer.prototype.writeUInt16LE = Buffer.prototype.writeUInt16LE;
  6873. SlowBuffer.prototype.writeUInt16BE = Buffer.prototype.writeUInt16BE;
  6874. SlowBuffer.prototype.writeUInt32LE = Buffer.prototype.writeUInt32LE;
  6875. SlowBuffer.prototype.writeUInt32BE = Buffer.prototype.writeUInt32BE;
  6876. SlowBuffer.prototype.writeInt8 = Buffer.prototype.writeInt8;
  6877. SlowBuffer.prototype.writeInt16LE = Buffer.prototype.writeInt16LE;
  6878. SlowBuffer.prototype.writeInt16BE = Buffer.prototype.writeInt16BE;
  6879. SlowBuffer.prototype.writeInt32LE = Buffer.prototype.writeInt32LE;
  6880. SlowBuffer.prototype.writeInt32BE = Buffer.prototype.writeInt32BE;
  6881. SlowBuffer.prototype.writeFloatLE = Buffer.prototype.writeFloatLE;
  6882. SlowBuffer.prototype.writeFloatBE = Buffer.prototype.writeFloatBE;
  6883. SlowBuffer.prototype.writeDoubleLE = Buffer.prototype.writeDoubleLE;
  6884. SlowBuffer.prototype.writeDoubleBE = Buffer.prototype.writeDoubleBE;
  6885. },{"assert":1,"./buffer_ieee754":5,"base64-js":7}],7:[function(require,module,exports){
  6886. (function (exports) {
  6887. 'use strict';
  6888. var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  6889. function b64ToByteArray(b64) {
  6890. var i, j, l, tmp, placeHolders, arr;
  6891. if (b64.length % 4 > 0) {
  6892. throw 'Invalid string. Length must be a multiple of 4';
  6893. }
  6894. // the number of equal signs (place holders)
  6895. // if there are two placeholders, than the two characters before it
  6896. // represent one byte
  6897. // if there is only one, then the three characters before it represent 2 bytes
  6898. // this is just a cheap hack to not do indexOf twice
  6899. placeHolders = b64.indexOf('=');
  6900. placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0;
  6901. // base64 is 4/3 + up to two characters of the original data
  6902. arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders);
  6903. // if there are placeholders, only get up to the last complete 4 chars
  6904. l = placeHolders > 0 ? b64.length - 4 : b64.length;
  6905. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  6906. tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]);
  6907. arr.push((tmp & 0xFF0000) >> 16);
  6908. arr.push((tmp & 0xFF00) >> 8);
  6909. arr.push(tmp & 0xFF);
  6910. }
  6911. if (placeHolders === 2) {
  6912. tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4);
  6913. arr.push(tmp & 0xFF);
  6914. } else if (placeHolders === 1) {
  6915. tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2);
  6916. arr.push((tmp >> 8) & 0xFF);
  6917. arr.push(tmp & 0xFF);
  6918. }
  6919. return arr;
  6920. }
  6921. function uint8ToBase64(uint8) {
  6922. var i,
  6923. extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
  6924. output = "",
  6925. temp, length;
  6926. function tripletToBase64 (num) {
  6927. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
  6928. };
  6929. // go through the array every three bytes, we'll deal with trailing stuff later
  6930. for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
  6931. temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
  6932. output += tripletToBase64(temp);
  6933. }
  6934. // pad the end with zeros, but make sure to not forget the extra bytes
  6935. switch (extraBytes) {
  6936. case 1:
  6937. temp = uint8[uint8.length - 1];
  6938. output += lookup[temp >> 2];
  6939. output += lookup[(temp << 4) & 0x3F];
  6940. output += '==';
  6941. break;
  6942. case 2:
  6943. temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]);
  6944. output += lookup[temp >> 10];
  6945. output += lookup[(temp >> 4) & 0x3F];
  6946. output += lookup[(temp << 2) & 0x3F];
  6947. output += '=';
  6948. break;
  6949. }
  6950. return output;
  6951. }
  6952. module.exports.toByteArray = b64ToByteArray;
  6953. module.exports.fromByteArray = uint8ToBase64;
  6954. }());
  6955. },{}],8:[function(require,module,exports){
  6956. exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) {
  6957. var e, m,
  6958. eLen = nBytes * 8 - mLen - 1,
  6959. eMax = (1 << eLen) - 1,
  6960. eBias = eMax >> 1,
  6961. nBits = -7,
  6962. i = isBE ? 0 : (nBytes - 1),
  6963. d = isBE ? 1 : -1,
  6964. s = buffer[offset + i];
  6965. i += d;
  6966. e = s & ((1 << (-nBits)) - 1);
  6967. s >>= (-nBits);
  6968. nBits += eLen;
  6969. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
  6970. m = e & ((1 << (-nBits)) - 1);
  6971. e >>= (-nBits);
  6972. nBits += mLen;
  6973. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
  6974. if (e === 0) {
  6975. e = 1 - eBias;
  6976. } else if (e === eMax) {
  6977. return m ? NaN : ((s ? -1 : 1) * Infinity);
  6978. } else {
  6979. m = m + Math.pow(2, mLen);
  6980. e = e - eBias;
  6981. }
  6982. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  6983. };
  6984. exports.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) {
  6985. var e, m, c,
  6986. eLen = nBytes * 8 - mLen - 1,
  6987. eMax = (1 << eLen) - 1,
  6988. eBias = eMax >> 1,
  6989. rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
  6990. i = isBE ? (nBytes - 1) : 0,
  6991. d = isBE ? -1 : 1,
  6992. s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
  6993. value = Math.abs(value);
  6994. if (isNaN(value) || value === Infinity) {
  6995. m = isNaN(value) ? 1 : 0;
  6996. e = eMax;
  6997. } else {
  6998. e = Math.floor(Math.log(value) / Math.LN2);
  6999. if (value * (c = Math.pow(2, -e)) < 1) {
  7000. e--;
  7001. c *= 2;
  7002. }
  7003. if (e + eBias >= 1) {
  7004. value += rt / c;
  7005. } else {
  7006. value += rt * Math.pow(2, 1 - eBias);
  7007. }
  7008. if (value * c >= 2) {
  7009. e++;
  7010. c /= 2;
  7011. }
  7012. if (e + eBias >= eMax) {
  7013. m = 0;
  7014. e = eMax;
  7015. } else if (e + eBias >= 1) {
  7016. m = (value * c - 1) * Math.pow(2, mLen);
  7017. e = e + eBias;
  7018. } else {
  7019. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  7020. e = 0;
  7021. }
  7022. }
  7023. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
  7024. e = (e << mLen) | m;
  7025. eLen += mLen;
  7026. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
  7027. buffer[offset + i - d] |= s * 128;
  7028. };
  7029. },{}],3:[function(require,module,exports){
  7030. function SlowBuffer (size) {
  7031. this.length = size;
  7032. };
  7033. var assert = require('assert');
  7034. exports.INSPECT_MAX_BYTES = 50;
  7035. function toHex(n) {
  7036. if (n < 16) return '0' + n.toString(16);
  7037. return n.toString(16);
  7038. }
  7039. function utf8ToBytes(str) {
  7040. var byteArray = [];
  7041. for (var i = 0; i < str.length; i++)
  7042. if (str.charCodeAt(i) <= 0x7F)
  7043. byteArray.push(str.charCodeAt(i));
  7044. else {
  7045. var h = encodeURIComponent(str.charAt(i)).substr(1).split('%');
  7046. for (var j = 0; j < h.length; j++)
  7047. byteArray.push(parseInt(h[j], 16));
  7048. }
  7049. return byteArray;
  7050. }
  7051. function asciiToBytes(str) {
  7052. var byteArray = []
  7053. for (var i = 0; i < str.length; i++ )
  7054. // Node's code seems to be doing this and not & 0x7F..
  7055. byteArray.push( str.charCodeAt(i) & 0xFF );
  7056. return byteArray;
  7057. }
  7058. function base64ToBytes(str) {
  7059. return require("base64-js").toByteArray(str);
  7060. }
  7061. SlowBuffer.byteLength = function (str, encoding) {
  7062. switch (encoding || "utf8") {
  7063. case 'hex':
  7064. return str.length / 2;
  7065. case 'utf8':
  7066. case 'utf-8':
  7067. return utf8ToBytes(str).length;
  7068. case 'ascii':
  7069. return str.length;
  7070. case 'base64':
  7071. return base64ToBytes(str).length;
  7072. default:
  7073. throw new Error('Unknown encoding');
  7074. }
  7075. };
  7076. function blitBuffer(src, dst, offset, length) {
  7077. var pos, i = 0;
  7078. while (i < length) {
  7079. if ((i+offset >= dst.length) || (i >= src.length))
  7080. break;
  7081. dst[i + offset] = src[i];
  7082. i++;
  7083. }
  7084. return i;
  7085. }
  7086. SlowBuffer.prototype.utf8Write = function (string, offset, length) {
  7087. var bytes, pos;
  7088. return SlowBuffer._charsWritten = blitBuffer(utf8ToBytes(string), this, offset, length);
  7089. };
  7090. SlowBuffer.prototype.asciiWrite = function (string, offset, length) {
  7091. var bytes, pos;
  7092. return SlowBuffer._charsWritten = blitBuffer(asciiToBytes(string), this, offset, length);
  7093. };
  7094. SlowBuffer.prototype.base64Write = function (string, offset, length) {
  7095. var bytes, pos;
  7096. return SlowBuffer._charsWritten = blitBuffer(base64ToBytes(string), this, offset, length);
  7097. };
  7098. SlowBuffer.prototype.base64Slice = function (start, end) {
  7099. var bytes = Array.prototype.slice.apply(this, arguments)
  7100. return require("base64-js").fromByteArray(bytes);
  7101. }
  7102. function decodeUtf8Char(str) {
  7103. try {
  7104. return decodeURIComponent(str);
  7105. } catch (err) {
  7106. return String.fromCharCode(0xFFFD); // UTF 8 invalid char
  7107. }
  7108. }
  7109. SlowBuffer.prototype.utf8Slice = function () {
  7110. var bytes = Array.prototype.slice.apply(this, arguments);
  7111. var res = "";
  7112. var tmp = "";
  7113. var i = 0;
  7114. while (i < bytes.length) {
  7115. if (bytes[i] <= 0x7F) {
  7116. res += decodeUtf8Char(tmp) + String.fromCharCode(bytes[i]);
  7117. tmp = "";
  7118. } else
  7119. tmp += "%" + bytes[i].toString(16);
  7120. i++;
  7121. }
  7122. return res + decodeUtf8Char(tmp);
  7123. }
  7124. SlowBuffer.prototype.asciiSlice = function () {
  7125. var bytes = Array.prototype.slice.apply(this, arguments);
  7126. var ret = "";
  7127. for (var i = 0; i < bytes.length; i++)
  7128. ret += String.fromCharCode(bytes[i]);
  7129. return ret;
  7130. }
  7131. SlowBuffer.prototype.inspect = function() {
  7132. var out = [],
  7133. len = this.length;
  7134. for (var i = 0; i < len; i++) {
  7135. out[i] = toHex(this[i]);
  7136. if (i == exports.INSPECT_MAX_BYTES) {
  7137. out[i + 1] = '...';
  7138. break;
  7139. }
  7140. }
  7141. return '<SlowBuffer ' + out.join(' ') + '>';
  7142. };
  7143. SlowBuffer.prototype.hexSlice = function(start, end) {
  7144. var len = this.length;
  7145. if (!start || start < 0) start = 0;
  7146. if (!end || end < 0 || end > len) end = len;
  7147. var out = '';
  7148. for (var i = start; i < end; i++) {
  7149. out += toHex(this[i]);
  7150. }
  7151. return out;
  7152. };
  7153. SlowBuffer.prototype.toString = function(encoding, start, end) {
  7154. encoding = String(encoding || 'utf8').toLowerCase();
  7155. start = +start || 0;
  7156. if (typeof end == 'undefined') end = this.length;
  7157. // Fastpath empty strings
  7158. if (+end == start) {
  7159. return '';
  7160. }
  7161. switch (encoding) {
  7162. case 'hex':
  7163. return this.hexSlice(start, end);
  7164. case 'utf8':
  7165. case 'utf-8':
  7166. return this.utf8Slice(start, end);
  7167. case 'ascii':
  7168. return this.asciiSlice(start, end);
  7169. case 'binary':
  7170. return this.binarySlice(start, end);
  7171. case 'base64':
  7172. return this.base64Slice(start, end);
  7173. case 'ucs2':
  7174. case 'ucs-2':
  7175. return this.ucs2Slice(start, end);
  7176. default:
  7177. throw new Error('Unknown encoding');
  7178. }
  7179. };
  7180. SlowBuffer.prototype.hexWrite = function(string, offset, length) {
  7181. offset = +offset || 0;
  7182. var remaining = this.length - offset;
  7183. if (!length) {
  7184. length = remaining;
  7185. } else {
  7186. length = +length;
  7187. if (length > remaining) {
  7188. length = remaining;
  7189. }
  7190. }
  7191. // must be an even number of digits
  7192. var strLen = string.length;
  7193. if (strLen % 2) {
  7194. throw new Error('Invalid hex string');
  7195. }
  7196. if (length > strLen / 2) {
  7197. length = strLen / 2;
  7198. }
  7199. for (var i = 0; i < length; i++) {
  7200. var byte = parseInt(string.substr(i * 2, 2), 16);
  7201. if (isNaN(byte)) throw new Error('Invalid hex string');
  7202. this[offset + i] = byte;
  7203. }
  7204. SlowBuffer._charsWritten = i * 2;
  7205. return i;
  7206. };
  7207. SlowBuffer.prototype.write = function(string, offset, length, encoding) {
  7208. // Support both (string, offset, length, encoding)
  7209. // and the legacy (string, encoding, offset, length)
  7210. if (isFinite(offset)) {
  7211. if (!isFinite(length)) {
  7212. encoding = length;
  7213. length = undefined;
  7214. }
  7215. } else { // legacy
  7216. var swap = encoding;
  7217. encoding = offset;
  7218. offset = length;
  7219. length = swap;
  7220. }
  7221. offset = +offset || 0;
  7222. var remaining = this.length - offset;
  7223. if (!length) {
  7224. length = remaining;
  7225. } else {
  7226. length = +length;
  7227. if (length > remaining) {
  7228. length = remaining;
  7229. }
  7230. }
  7231. encoding = String(encoding || 'utf8').toLowerCase();
  7232. switch (encoding) {
  7233. case 'hex':
  7234. return this.hexWrite(string, offset, length);
  7235. case 'utf8':
  7236. case 'utf-8':
  7237. return this.utf8Write(string, offset, length);
  7238. case 'ascii':
  7239. return this.asciiWrite(string, offset, length);
  7240. case 'binary':
  7241. return this.binaryWrite(string, offset, length);
  7242. case 'base64':
  7243. return this.base64Write(string, offset, length);
  7244. case 'ucs2':
  7245. case 'ucs-2':
  7246. return this.ucs2Write(string, offset, length);
  7247. default:
  7248. throw new Error('Unknown encoding');
  7249. }
  7250. };
  7251. // slice(start, end)
  7252. SlowBuffer.prototype.slice = function(start, end) {
  7253. if (end === undefined) end = this.length;
  7254. if (end > this.length) {
  7255. throw new Error('oob');
  7256. }
  7257. if (start > end) {
  7258. throw new Error('oob');
  7259. }
  7260. return new Buffer(this, end - start, +start);
  7261. };
  7262. SlowBuffer.prototype.copy = function(target, targetstart, sourcestart, sourceend) {
  7263. var temp = [];
  7264. for (var i=sourcestart; i<sourceend; i++) {
  7265. assert.ok(typeof this[i] !== 'undefined', "copying undefined buffer bytes!");
  7266. temp.push(this[i]);
  7267. }
  7268. for (var i=targetstart; i<targetstart+temp.length; i++) {
  7269. target[i] = temp[i-targetstart];
  7270. }
  7271. };
  7272. function coerce(length) {
  7273. // Coerce length to a number (possibly NaN), round up
  7274. // in case it's fractional (e.g. 123.456) then do a
  7275. // double negate to coerce a NaN to 0. Easy, right?
  7276. length = ~~Math.ceil(+length);
  7277. return length < 0 ? 0 : length;
  7278. }
  7279. // Buffer
  7280. function Buffer(subject, encoding, offset) {
  7281. if (!(this instanceof Buffer)) {
  7282. return new Buffer(subject, encoding, offset);
  7283. }
  7284. var type;
  7285. // Are we slicing?
  7286. if (typeof offset === 'number') {
  7287. this.length = coerce(encoding);
  7288. this.parent = subject;
  7289. this.offset = offset;
  7290. } else {
  7291. // Find the length
  7292. switch (type = typeof subject) {
  7293. case 'number':
  7294. this.length = coerce(subject);
  7295. break;
  7296. case 'string':
  7297. this.length = Buffer.byteLength(subject, encoding);
  7298. break;
  7299. case 'object': // Assume object is an array
  7300. this.length = coerce(subject.length);
  7301. break;
  7302. default:
  7303. throw new Error('First argument needs to be a number, ' +
  7304. 'array or string.');
  7305. }
  7306. if (this.length > Buffer.poolSize) {
  7307. // Big buffer, just alloc one.
  7308. this.parent = new SlowBuffer(this.length);
  7309. this.offset = 0;
  7310. } else {
  7311. // Small buffer.
  7312. if (!pool || pool.length - pool.used < this.length) allocPool();
  7313. this.parent = pool;
  7314. this.offset = pool.used;
  7315. pool.used += this.length;
  7316. }
  7317. // Treat array-ish objects as a byte array.
  7318. if (isArrayIsh(subject)) {
  7319. for (var i = 0; i < this.length; i++) {
  7320. this.parent[i + this.offset] = subject[i];
  7321. }
  7322. } else if (type == 'string') {
  7323. // We are a string
  7324. this.length = this.write(subject, 0, encoding);
  7325. }
  7326. }
  7327. }
  7328. function isArrayIsh(subject) {
  7329. return Array.isArray(subject) || Buffer.isBuffer(subject) ||
  7330. subject && typeof subject === 'object' &&
  7331. typeof subject.length === 'number';
  7332. }
  7333. exports.SlowBuffer = SlowBuffer;
  7334. exports.Buffer = Buffer;
  7335. Buffer.poolSize = 8 * 1024;
  7336. var pool;
  7337. function allocPool() {
  7338. pool = new SlowBuffer(Buffer.poolSize);
  7339. pool.used = 0;
  7340. }
  7341. // Static methods
  7342. Buffer.isBuffer = function isBuffer(b) {
  7343. return b instanceof Buffer || b instanceof SlowBuffer;
  7344. };
  7345. Buffer.concat = function (list, totalLength) {
  7346. if (!Array.isArray(list)) {
  7347. throw new Error("Usage: Buffer.concat(list, [totalLength])\n \
  7348. list should be an Array.");
  7349. }
  7350. if (list.length === 0) {
  7351. return new Buffer(0);
  7352. } else if (list.length === 1) {
  7353. return list[0];
  7354. }
  7355. if (typeof totalLength !== 'number') {
  7356. totalLength = 0;
  7357. for (var i = 0; i < list.length; i++) {
  7358. var buf = list[i];
  7359. totalLength += buf.length;
  7360. }
  7361. }
  7362. var buffer = new Buffer(totalLength);
  7363. var pos = 0;
  7364. for (var i = 0; i < list.length; i++) {
  7365. var buf = list[i];
  7366. buf.copy(buffer, pos);
  7367. pos += buf.length;
  7368. }
  7369. return buffer;
  7370. };
  7371. // Inspect
  7372. Buffer.prototype.inspect = function inspect() {
  7373. var out = [],
  7374. len = this.length;
  7375. for (var i = 0; i < len; i++) {
  7376. out[i] = toHex(this.parent[i + this.offset]);
  7377. if (i == exports.INSPECT_MAX_BYTES) {
  7378. out[i + 1] = '...';
  7379. break;
  7380. }
  7381. }
  7382. return '<Buffer ' + out.join(' ') + '>';
  7383. };
  7384. Buffer.prototype.get = function get(i) {
  7385. if (i < 0 || i >= this.length) throw new Error('oob');
  7386. return this.parent[this.offset + i];
  7387. };
  7388. Buffer.prototype.set = function set(i, v) {
  7389. if (i < 0 || i >= this.length) throw new Error('oob');
  7390. return this.parent[this.offset + i] = v;
  7391. };
  7392. // write(string, offset = 0, length = buffer.length-offset, encoding = 'utf8')
  7393. Buffer.prototype.write = function(string, offset, length, encoding) {
  7394. // Support both (string, offset, length, encoding)
  7395. // and the legacy (string, encoding, offset, length)
  7396. if (isFinite(offset)) {
  7397. if (!isFinite(length)) {
  7398. encoding = length;
  7399. length = undefined;
  7400. }
  7401. } else { // legacy
  7402. var swap = encoding;
  7403. encoding = offset;
  7404. offset = length;
  7405. length = swap;
  7406. }
  7407. offset = +offset || 0;
  7408. var remaining = this.length - offset;
  7409. if (!length) {
  7410. length = remaining;
  7411. } else {
  7412. length = +length;
  7413. if (length > remaining) {
  7414. length = remaining;
  7415. }
  7416. }
  7417. encoding = String(encoding || 'utf8').toLowerCase();
  7418. var ret;
  7419. switch (encoding) {
  7420. case 'hex':
  7421. ret = this.parent.hexWrite(string, this.offset + offset, length);
  7422. break;
  7423. case 'utf8':
  7424. case 'utf-8':
  7425. ret = this.parent.utf8Write(string, this.offset + offset, length);
  7426. break;
  7427. case 'ascii':
  7428. ret = this.parent.asciiWrite(string, this.offset + offset, length);
  7429. break;
  7430. case 'binary':
  7431. ret = this.parent.binaryWrite(string, this.offset + offset, length);
  7432. break;
  7433. case 'base64':
  7434. // Warning: maxLength not taken into account in base64Write
  7435. ret = this.parent.base64Write(string, this.offset + offset, length);
  7436. break;
  7437. case 'ucs2':
  7438. case 'ucs-2':
  7439. ret = this.parent.ucs2Write(string, this.offset + offset, length);
  7440. break;
  7441. default:
  7442. throw new Error('Unknown encoding');
  7443. }
  7444. Buffer._charsWritten = SlowBuffer._charsWritten;
  7445. return ret;
  7446. };
  7447. // toString(encoding, start=0, end=buffer.length)
  7448. Buffer.prototype.toString = function(encoding, start, end) {
  7449. encoding = String(encoding || 'utf8').toLowerCase();
  7450. if (typeof start == 'undefined' || start < 0) {
  7451. start = 0;
  7452. } else if (start > this.length) {
  7453. start = this.length;
  7454. }
  7455. if (typeof end == 'undefined' || end > this.length) {
  7456. end = this.length;
  7457. } else if (end < 0) {
  7458. end = 0;
  7459. }
  7460. start = start + this.offset;
  7461. end = end + this.offset;
  7462. switch (encoding) {
  7463. case 'hex':
  7464. return this.parent.hexSlice(start, end);
  7465. case 'utf8':
  7466. case 'utf-8':
  7467. return this.parent.utf8Slice(start, end);
  7468. case 'ascii':
  7469. return this.parent.asciiSlice(start, end);
  7470. case 'binary':
  7471. return this.parent.binarySlice(start, end);
  7472. case 'base64':
  7473. return this.parent.base64Slice(start, end);
  7474. case 'ucs2':
  7475. case 'ucs-2':
  7476. return this.parent.ucs2Slice(start, end);
  7477. default:
  7478. throw new Error('Unknown encoding');
  7479. }
  7480. };
  7481. // byteLength
  7482. Buffer.byteLength = SlowBuffer.byteLength;
  7483. // fill(value, start=0, end=buffer.length)
  7484. Buffer.prototype.fill = function fill(value, start, end) {
  7485. value || (value = 0);
  7486. start || (start = 0);
  7487. end || (end = this.length);
  7488. if (typeof value === 'string') {
  7489. value = value.charCodeAt(0);
  7490. }
  7491. if (!(typeof value === 'number') || isNaN(value)) {
  7492. throw new Error('value is not a number');
  7493. }
  7494. if (end < start) throw new Error('end < start');
  7495. // Fill 0 bytes; we're done
  7496. if (end === start) return 0;
  7497. if (this.length == 0) return 0;
  7498. if (start < 0 || start >= this.length) {
  7499. throw new Error('start out of bounds');
  7500. }
  7501. if (end < 0 || end > this.length) {
  7502. throw new Error('end out of bounds');
  7503. }
  7504. return this.parent.fill(value,
  7505. start + this.offset,
  7506. end + this.offset);
  7507. };
  7508. // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  7509. Buffer.prototype.copy = function(target, target_start, start, end) {
  7510. var source = this;
  7511. start || (start = 0);
  7512. end || (end = this.length);
  7513. target_start || (target_start = 0);
  7514. if (end < start) throw new Error('sourceEnd < sourceStart');
  7515. // Copy 0 bytes; we're done
  7516. if (end === start) return 0;
  7517. if (target.length == 0 || source.length == 0) return 0;
  7518. if (target_start < 0 || target_start >= target.length) {
  7519. throw new Error('targetStart out of bounds');
  7520. }
  7521. if (start < 0 || start >= source.length) {
  7522. throw new Error('sourceStart out of bounds');
  7523. }
  7524. if (end < 0 || end > source.length) {
  7525. throw new Error('sourceEnd out of bounds');
  7526. }
  7527. // Are we oob?
  7528. if (end > this.length) {
  7529. end = this.length;
  7530. }
  7531. if (target.length - target_start < end - start) {
  7532. end = target.length - target_start + start;
  7533. }
  7534. return this.parent.copy(target.parent,
  7535. target_start + target.offset,
  7536. start + this.offset,
  7537. end + this.offset);
  7538. };
  7539. // slice(start, end)
  7540. Buffer.prototype.slice = function(start, end) {
  7541. if (end === undefined) end = this.length;
  7542. if (end > this.length) throw new Error('oob');
  7543. if (start > end) throw new Error('oob');
  7544. return new Buffer(this.parent, end - start, +start + this.offset);
  7545. };
  7546. // Legacy methods for backwards compatibility.
  7547. Buffer.prototype.utf8Slice = function(start, end) {
  7548. return this.toString('utf8', start, end);
  7549. };
  7550. Buffer.prototype.binarySlice = function(start, end) {
  7551. return this.toString('binary', start, end);
  7552. };
  7553. Buffer.prototype.asciiSlice = function(start, end) {
  7554. return this.toString('ascii', start, end);
  7555. };
  7556. Buffer.prototype.utf8Write = function(string, offset) {
  7557. return this.write(string, offset, 'utf8');
  7558. };
  7559. Buffer.prototype.binaryWrite = function(string, offset) {
  7560. return this.write(string, offset, 'binary');
  7561. };
  7562. Buffer.prototype.asciiWrite = function(string, offset) {
  7563. return this.write(string, offset, 'ascii');
  7564. };
  7565. Buffer.prototype.readUInt8 = function(offset, noAssert) {
  7566. var buffer = this;
  7567. if (!noAssert) {
  7568. assert.ok(offset !== undefined && offset !== null,
  7569. 'missing offset');
  7570. assert.ok(offset < buffer.length,
  7571. 'Trying to read beyond buffer length');
  7572. }
  7573. return buffer.parent[buffer.offset + offset];
  7574. };
  7575. function readUInt16(buffer, offset, isBigEndian, noAssert) {
  7576. var val = 0;
  7577. if (!noAssert) {
  7578. assert.ok(typeof (isBigEndian) === 'boolean',
  7579. 'missing or invalid endian');
  7580. assert.ok(offset !== undefined && offset !== null,
  7581. 'missing offset');
  7582. assert.ok(offset + 1 < buffer.length,
  7583. 'Trying to read beyond buffer length');
  7584. }
  7585. if (isBigEndian) {
  7586. val = buffer.parent[buffer.offset + offset] << 8;
  7587. val |= buffer.parent[buffer.offset + offset + 1];
  7588. } else {
  7589. val = buffer.parent[buffer.offset + offset];
  7590. val |= buffer.parent[buffer.offset + offset + 1] << 8;
  7591. }
  7592. return val;
  7593. }
  7594. Buffer.prototype.readUInt16LE = function(offset, noAssert) {
  7595. return readUInt16(this, offset, false, noAssert);
  7596. };
  7597. Buffer.prototype.readUInt16BE = function(offset, noAssert) {
  7598. return readUInt16(this, offset, true, noAssert);
  7599. };
  7600. function readUInt32(buffer, offset, isBigEndian, noAssert) {
  7601. var val = 0;
  7602. if (!noAssert) {
  7603. assert.ok(typeof (isBigEndian) === 'boolean',
  7604. 'missing or invalid endian');
  7605. assert.ok(offset !== undefined && offset !== null,
  7606. 'missing offset');
  7607. assert.ok(offset + 3 < buffer.length,
  7608. 'Trying to read beyond buffer length');
  7609. }
  7610. if (isBigEndian) {
  7611. val = buffer.parent[buffer.offset + offset + 1] << 16;
  7612. val |= buffer.parent[buffer.offset + offset + 2] << 8;
  7613. val |= buffer.parent[buffer.offset + offset + 3];
  7614. val = val + (buffer.parent[buffer.offset + offset] << 24 >>> 0);
  7615. } else {
  7616. val = buffer.parent[buffer.offset + offset + 2] << 16;
  7617. val |= buffer.parent[buffer.offset + offset + 1] << 8;
  7618. val |= buffer.parent[buffer.offset + offset];
  7619. val = val + (buffer.parent[buffer.offset + offset + 3] << 24 >>> 0);
  7620. }
  7621. return val;
  7622. }
  7623. Buffer.prototype.readUInt32LE = function(offset, noAssert) {
  7624. return readUInt32(this, offset, false, noAssert);
  7625. };
  7626. Buffer.prototype.readUInt32BE = function(offset, noAssert) {
  7627. return readUInt32(this, offset, true, noAssert);
  7628. };
  7629. /*
  7630. * Signed integer types, yay team! A reminder on how two's complement actually
  7631. * works. The first bit is the signed bit, i.e. tells us whether or not the
  7632. * number should be positive or negative. If the two's complement value is
  7633. * positive, then we're done, as it's equivalent to the unsigned representation.
  7634. *
  7635. * Now if the number is positive, you're pretty much done, you can just leverage
  7636. * the unsigned translations and return those. Unfortunately, negative numbers
  7637. * aren't quite that straightforward.
  7638. *
  7639. * At first glance, one might be inclined to use the traditional formula to
  7640. * translate binary numbers between the positive and negative values in two's
  7641. * complement. (Though it doesn't quite work for the most negative value)
  7642. * Mainly:
  7643. * - invert all the bits
  7644. * - add one to the result
  7645. *
  7646. * Of course, this doesn't quite work in Javascript. Take for example the value
  7647. * of -128. This could be represented in 16 bits (big-endian) as 0xff80. But of
  7648. * course, Javascript will do the following:
  7649. *
  7650. * > ~0xff80
  7651. * -65409
  7652. *
  7653. * Whoh there, Javascript, that's not quite right. But wait, according to
  7654. * Javascript that's perfectly correct. When Javascript ends up seeing the
  7655. * constant 0xff80, it has no notion that it is actually a signed number. It
  7656. * assumes that we've input the unsigned value 0xff80. Thus, when it does the
  7657. * binary negation, it casts it into a signed value, (positive 0xff80). Then
  7658. * when you perform binary negation on that, it turns it into a negative number.
  7659. *
  7660. * Instead, we're going to have to use the following general formula, that works
  7661. * in a rather Javascript friendly way. I'm glad we don't support this kind of
  7662. * weird numbering scheme in the kernel.
  7663. *
  7664. * (BIT-MAX - (unsigned)val + 1) * -1
  7665. *
  7666. * The astute observer, may think that this doesn't make sense for 8-bit numbers
  7667. * (really it isn't necessary for them). However, when you get 16-bit numbers,
  7668. * you do. Let's go back to our prior example and see how this will look:
  7669. *
  7670. * (0xffff - 0xff80 + 1) * -1
  7671. * (0x007f + 1) * -1
  7672. * (0x0080) * -1
  7673. */
  7674. Buffer.prototype.readInt8 = function(offset, noAssert) {
  7675. var buffer = this;
  7676. var neg;
  7677. if (!noAssert) {
  7678. assert.ok(offset !== undefined && offset !== null,
  7679. 'missing offset');
  7680. assert.ok(offset < buffer.length,
  7681. 'Trying to read beyond buffer length');
  7682. }
  7683. neg = buffer.parent[buffer.offset + offset] & 0x80;
  7684. if (!neg) {
  7685. return (buffer.parent[buffer.offset + offset]);
  7686. }
  7687. return ((0xff - buffer.parent[buffer.offset + offset] + 1) * -1);
  7688. };
  7689. function readInt16(buffer, offset, isBigEndian, noAssert) {
  7690. var neg, val;
  7691. if (!noAssert) {
  7692. assert.ok(typeof (isBigEndian) === 'boolean',
  7693. 'missing or invalid endian');
  7694. assert.ok(offset !== undefined && offset !== null,
  7695. 'missing offset');
  7696. assert.ok(offset + 1 < buffer.length,
  7697. 'Trying to read beyond buffer length');
  7698. }
  7699. val = readUInt16(buffer, offset, isBigEndian, noAssert);
  7700. neg = val & 0x8000;
  7701. if (!neg) {
  7702. return val;
  7703. }
  7704. return (0xffff - val + 1) * -1;
  7705. }
  7706. Buffer.prototype.readInt16LE = function(offset, noAssert) {
  7707. return readInt16(this, offset, false, noAssert);
  7708. };
  7709. Buffer.prototype.readInt16BE = function(offset, noAssert) {
  7710. return readInt16(this, offset, true, noAssert);
  7711. };
  7712. function readInt32(buffer, offset, isBigEndian, noAssert) {
  7713. var neg, val;
  7714. if (!noAssert) {
  7715. assert.ok(typeof (isBigEndian) === 'boolean',
  7716. 'missing or invalid endian');
  7717. assert.ok(offset !== undefined && offset !== null,
  7718. 'missing offset');
  7719. assert.ok(offset + 3 < buffer.length,
  7720. 'Trying to read beyond buffer length');
  7721. }
  7722. val = readUInt32(buffer, offset, isBigEndian, noAssert);
  7723. neg = val & 0x80000000;
  7724. if (!neg) {
  7725. return (val);
  7726. }
  7727. return (0xffffffff - val + 1) * -1;
  7728. }
  7729. Buffer.prototype.readInt32LE = function(offset, noAssert) {
  7730. return readInt32(this, offset, false, noAssert);
  7731. };
  7732. Buffer.prototype.readInt32BE = function(offset, noAssert) {
  7733. return readInt32(this, offset, true, noAssert);
  7734. };
  7735. function readFloat(buffer, offset, isBigEndian, noAssert) {
  7736. if (!noAssert) {
  7737. assert.ok(typeof (isBigEndian) === 'boolean',
  7738. 'missing or invalid endian');
  7739. assert.ok(offset + 3 < buffer.length,
  7740. 'Trying to read beyond buffer length');
  7741. }
  7742. return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
  7743. 23, 4);
  7744. }
  7745. Buffer.prototype.readFloatLE = function(offset, noAssert) {
  7746. return readFloat(this, offset, false, noAssert);
  7747. };
  7748. Buffer.prototype.readFloatBE = function(offset, noAssert) {
  7749. return readFloat(this, offset, true, noAssert);
  7750. };
  7751. function readDouble(buffer, offset, isBigEndian, noAssert) {
  7752. if (!noAssert) {
  7753. assert.ok(typeof (isBigEndian) === 'boolean',
  7754. 'missing or invalid endian');
  7755. assert.ok(offset + 7 < buffer.length,
  7756. 'Trying to read beyond buffer length');
  7757. }
  7758. return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
  7759. 52, 8);
  7760. }
  7761. Buffer.prototype.readDoubleLE = function(offset, noAssert) {
  7762. return readDouble(this, offset, false, noAssert);
  7763. };
  7764. Buffer.prototype.readDoubleBE = function(offset, noAssert) {
  7765. return readDouble(this, offset, true, noAssert);
  7766. };
  7767. /*
  7768. * We have to make sure that the value is a valid integer. This means that it is
  7769. * non-negative. It has no fractional component and that it does not exceed the
  7770. * maximum allowed value.
  7771. *
  7772. * value The number to check for validity
  7773. *
  7774. * max The maximum value
  7775. */
  7776. function verifuint(value, max) {
  7777. assert.ok(typeof (value) == 'number',
  7778. 'cannot write a non-number as a number');
  7779. assert.ok(value >= 0,
  7780. 'specified a negative value for writing an unsigned value');
  7781. assert.ok(value <= max, 'value is larger than maximum value for type');
  7782. assert.ok(Math.floor(value) === value, 'value has a fractional component');
  7783. }
  7784. Buffer.prototype.writeUInt8 = function(value, offset, noAssert) {
  7785. var buffer = this;
  7786. if (!noAssert) {
  7787. assert.ok(value !== undefined && value !== null,
  7788. 'missing value');
  7789. assert.ok(offset !== undefined && offset !== null,
  7790. 'missing offset');
  7791. assert.ok(offset < buffer.length,
  7792. 'trying to write beyond buffer length');
  7793. verifuint(value, 0xff);
  7794. }
  7795. buffer.parent[buffer.offset + offset] = value;
  7796. };
  7797. function writeUInt16(buffer, value, offset, isBigEndian, noAssert) {
  7798. if (!noAssert) {
  7799. assert.ok(value !== undefined && value !== null,
  7800. 'missing value');
  7801. assert.ok(typeof (isBigEndian) === 'boolean',
  7802. 'missing or invalid endian');
  7803. assert.ok(offset !== undefined && offset !== null,
  7804. 'missing offset');
  7805. assert.ok(offset + 1 < buffer.length,
  7806. 'trying to write beyond buffer length');
  7807. verifuint(value, 0xffff);
  7808. }
  7809. if (isBigEndian) {
  7810. buffer.parent[buffer.offset + offset] = (value & 0xff00) >>> 8;
  7811. buffer.parent[buffer.offset + offset + 1] = value & 0x00ff;
  7812. } else {
  7813. buffer.parent[buffer.offset + offset + 1] = (value & 0xff00) >>> 8;
  7814. buffer.parent[buffer.offset + offset] = value & 0x00ff;
  7815. }
  7816. }
  7817. Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) {
  7818. writeUInt16(this, value, offset, false, noAssert);
  7819. };
  7820. Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) {
  7821. writeUInt16(this, value, offset, true, noAssert);
  7822. };
  7823. function writeUInt32(buffer, value, offset, isBigEndian, noAssert) {
  7824. if (!noAssert) {
  7825. assert.ok(value !== undefined && value !== null,
  7826. 'missing value');
  7827. assert.ok(typeof (isBigEndian) === 'boolean',
  7828. 'missing or invalid endian');
  7829. assert.ok(offset !== undefined && offset !== null,
  7830. 'missing offset');
  7831. assert.ok(offset + 3 < buffer.length,
  7832. 'trying to write beyond buffer length');
  7833. verifuint(value, 0xffffffff);
  7834. }
  7835. if (isBigEndian) {
  7836. buffer.parent[buffer.offset + offset] = (value >>> 24) & 0xff;
  7837. buffer.parent[buffer.offset + offset + 1] = (value >>> 16) & 0xff;
  7838. buffer.parent[buffer.offset + offset + 2] = (value >>> 8) & 0xff;
  7839. buffer.parent[buffer.offset + offset + 3] = value & 0xff;
  7840. } else {
  7841. buffer.parent[buffer.offset + offset + 3] = (value >>> 24) & 0xff;
  7842. buffer.parent[buffer.offset + offset + 2] = (value >>> 16) & 0xff;
  7843. buffer.parent[buffer.offset + offset + 1] = (value >>> 8) & 0xff;
  7844. buffer.parent[buffer.offset + offset] = value & 0xff;
  7845. }
  7846. }
  7847. Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) {
  7848. writeUInt32(this, value, offset, false, noAssert);
  7849. };
  7850. Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) {
  7851. writeUInt32(this, value, offset, true, noAssert);
  7852. };
  7853. /*
  7854. * We now move onto our friends in the signed number category. Unlike unsigned
  7855. * numbers, we're going to have to worry a bit more about how we put values into
  7856. * arrays. Since we are only worrying about signed 32-bit values, we're in
  7857. * slightly better shape. Unfortunately, we really can't do our favorite binary
  7858. * & in this system. It really seems to do the wrong thing. For example:
  7859. *
  7860. * > -32 & 0xff
  7861. * 224
  7862. *
  7863. * What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of
  7864. * this aren't treated as a signed number. Ultimately a bad thing.
  7865. *
  7866. * What we're going to want to do is basically create the unsigned equivalent of
  7867. * our representation and pass that off to the wuint* functions. To do that
  7868. * we're going to do the following:
  7869. *
  7870. * - if the value is positive
  7871. * we can pass it directly off to the equivalent wuint
  7872. * - if the value is negative
  7873. * we do the following computation:
  7874. * mb + val + 1, where
  7875. * mb is the maximum unsigned value in that byte size
  7876. * val is the Javascript negative integer
  7877. *
  7878. *
  7879. * As a concrete value, take -128. In signed 16 bits this would be 0xff80. If
  7880. * you do out the computations:
  7881. *
  7882. * 0xffff - 128 + 1
  7883. * 0xffff - 127
  7884. * 0xff80
  7885. *
  7886. * You can then encode this value as the signed version. This is really rather
  7887. * hacky, but it should work and get the job done which is our goal here.
  7888. */
  7889. /*
  7890. * A series of checks to make sure we actually have a signed 32-bit number
  7891. */
  7892. function verifsint(value, max, min) {
  7893. assert.ok(typeof (value) == 'number',
  7894. 'cannot write a non-number as a number');
  7895. assert.ok(value <= max, 'value larger than maximum allowed value');
  7896. assert.ok(value >= min, 'value smaller than minimum allowed value');
  7897. assert.ok(Math.floor(value) === value, 'value has a fractional component');
  7898. }
  7899. function verifIEEE754(value, max, min) {
  7900. assert.ok(typeof (value) == 'number',
  7901. 'cannot write a non-number as a number');
  7902. assert.ok(value <= max, 'value larger than maximum allowed value');
  7903. assert.ok(value >= min, 'value smaller than minimum allowed value');
  7904. }
  7905. Buffer.prototype.writeInt8 = function(value, offset, noAssert) {
  7906. var buffer = this;
  7907. if (!noAssert) {
  7908. assert.ok(value !== undefined && value !== null,
  7909. 'missing value');
  7910. assert.ok(offset !== undefined && offset !== null,
  7911. 'missing offset');
  7912. assert.ok(offset < buffer.length,
  7913. 'Trying to write beyond buffer length');
  7914. verifsint(value, 0x7f, -0x80);
  7915. }
  7916. if (value >= 0) {
  7917. buffer.writeUInt8(value, offset, noAssert);
  7918. } else {
  7919. buffer.writeUInt8(0xff + value + 1, offset, noAssert);
  7920. }
  7921. };
  7922. function writeInt16(buffer, value, offset, isBigEndian, noAssert) {
  7923. if (!noAssert) {
  7924. assert.ok(value !== undefined && value !== null,
  7925. 'missing value');
  7926. assert.ok(typeof (isBigEndian) === 'boolean',
  7927. 'missing or invalid endian');
  7928. assert.ok(offset !== undefined && offset !== null,
  7929. 'missing offset');
  7930. assert.ok(offset + 1 < buffer.length,
  7931. 'Trying to write beyond buffer length');
  7932. verifsint(value, 0x7fff, -0x8000);
  7933. }
  7934. if (value >= 0) {
  7935. writeUInt16(buffer, value, offset, isBigEndian, noAssert);
  7936. } else {
  7937. writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert);
  7938. }
  7939. }
  7940. Buffer.prototype.writeInt16LE = function(value, offset, noAssert) {
  7941. writeInt16(this, value, offset, false, noAssert);
  7942. };
  7943. Buffer.prototype.writeInt16BE = function(value, offset, noAssert) {
  7944. writeInt16(this, value, offset, true, noAssert);
  7945. };
  7946. function writeInt32(buffer, value, offset, isBigEndian, noAssert) {
  7947. if (!noAssert) {
  7948. assert.ok(value !== undefined && value !== null,
  7949. 'missing value');
  7950. assert.ok(typeof (isBigEndian) === 'boolean',
  7951. 'missing or invalid endian');
  7952. assert.ok(offset !== undefined && offset !== null,
  7953. 'missing offset');
  7954. assert.ok(offset + 3 < buffer.length,
  7955. 'Trying to write beyond buffer length');
  7956. verifsint(value, 0x7fffffff, -0x80000000);
  7957. }
  7958. if (value >= 0) {
  7959. writeUInt32(buffer, value, offset, isBigEndian, noAssert);
  7960. } else {
  7961. writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert);
  7962. }
  7963. }
  7964. Buffer.prototype.writeInt32LE = function(value, offset, noAssert) {
  7965. writeInt32(this, value, offset, false, noAssert);
  7966. };
  7967. Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {
  7968. writeInt32(this, value, offset, true, noAssert);
  7969. };
  7970. function writeFloat(buffer, value, offset, isBigEndian, noAssert) {
  7971. if (!noAssert) {
  7972. assert.ok(value !== undefined && value !== null,
  7973. 'missing value');
  7974. assert.ok(typeof (isBigEndian) === 'boolean',
  7975. 'missing or invalid endian');
  7976. assert.ok(offset !== undefined && offset !== null,
  7977. 'missing offset');
  7978. assert.ok(offset + 3 < buffer.length,
  7979. 'Trying to write beyond buffer length');
  7980. verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38);
  7981. }
  7982. require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
  7983. 23, 4);
  7984. }
  7985. Buffer.prototype.writeFloatLE = function(value, offset, noAssert) {
  7986. writeFloat(this, value, offset, false, noAssert);
  7987. };
  7988. Buffer.prototype.writeFloatBE = function(value, offset, noAssert) {
  7989. writeFloat(this, value, offset, true, noAssert);
  7990. };
  7991. function writeDouble(buffer, value, offset, isBigEndian, noAssert) {
  7992. if (!noAssert) {
  7993. assert.ok(value !== undefined && value !== null,
  7994. 'missing value');
  7995. assert.ok(typeof (isBigEndian) === 'boolean',
  7996. 'missing or invalid endian');
  7997. assert.ok(offset !== undefined && offset !== null,
  7998. 'missing offset');
  7999. assert.ok(offset + 7 < buffer.length,
  8000. 'Trying to write beyond buffer length');
  8001. verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308);
  8002. }
  8003. require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
  8004. 52, 8);
  8005. }
  8006. Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) {
  8007. writeDouble(this, value, offset, false, noAssert);
  8008. };
  8009. Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) {
  8010. writeDouble(this, value, offset, true, noAssert);
  8011. };
  8012. SlowBuffer.prototype.readUInt8 = Buffer.prototype.readUInt8;
  8013. SlowBuffer.prototype.readUInt16LE = Buffer.prototype.readUInt16LE;
  8014. SlowBuffer.prototype.readUInt16BE = Buffer.prototype.readUInt16BE;
  8015. SlowBuffer.prototype.readUInt32LE = Buffer.prototype.readUInt32LE;
  8016. SlowBuffer.prototype.readUInt32BE = Buffer.prototype.readUInt32BE;
  8017. SlowBuffer.prototype.readInt8 = Buffer.prototype.readInt8;
  8018. SlowBuffer.prototype.readInt16LE = Buffer.prototype.readInt16LE;
  8019. SlowBuffer.prototype.readInt16BE = Buffer.prototype.readInt16BE;
  8020. SlowBuffer.prototype.readInt32LE = Buffer.prototype.readInt32LE;
  8021. SlowBuffer.prototype.readInt32BE = Buffer.prototype.readInt32BE;
  8022. SlowBuffer.prototype.readFloatLE = Buffer.prototype.readFloatLE;
  8023. SlowBuffer.prototype.readFloatBE = Buffer.prototype.readFloatBE;
  8024. SlowBuffer.prototype.readDoubleLE = Buffer.prototype.readDoubleLE;
  8025. SlowBuffer.prototype.readDoubleBE = Buffer.prototype.readDoubleBE;
  8026. SlowBuffer.prototype.writeUInt8 = Buffer.prototype.writeUInt8;
  8027. SlowBuffer.prototype.writeUInt16LE = Buffer.prototype.writeUInt16LE;
  8028. SlowBuffer.prototype.writeUInt16BE = Buffer.prototype.writeUInt16BE;
  8029. SlowBuffer.prototype.writeUInt32LE = Buffer.prototype.writeUInt32LE;
  8030. SlowBuffer.prototype.writeUInt32BE = Buffer.prototype.writeUInt32BE;
  8031. SlowBuffer.prototype.writeInt8 = Buffer.prototype.writeInt8;
  8032. SlowBuffer.prototype.writeInt16LE = Buffer.prototype.writeInt16LE;
  8033. SlowBuffer.prototype.writeInt16BE = Buffer.prototype.writeInt16BE;
  8034. SlowBuffer.prototype.writeInt32LE = Buffer.prototype.writeInt32LE;
  8035. SlowBuffer.prototype.writeInt32BE = Buffer.prototype.writeInt32BE;
  8036. SlowBuffer.prototype.writeFloatLE = Buffer.prototype.writeFloatLE;
  8037. SlowBuffer.prototype.writeFloatBE = Buffer.prototype.writeFloatBE;
  8038. SlowBuffer.prototype.writeDoubleLE = Buffer.prototype.writeDoubleLE;
  8039. SlowBuffer.prototype.writeDoubleBE = Buffer.prototype.writeDoubleBE;
  8040. },{"assert":1,"./buffer_ieee754":8,"base64-js":9}],9:[function(require,module,exports){
  8041. (function (exports) {
  8042. 'use strict';
  8043. var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  8044. function b64ToByteArray(b64) {
  8045. var i, j, l, tmp, placeHolders, arr;
  8046. if (b64.length % 4 > 0) {
  8047. throw 'Invalid string. Length must be a multiple of 4';
  8048. }
  8049. // the number of equal signs (place holders)
  8050. // if there are two placeholders, than the two characters before it
  8051. // represent one byte
  8052. // if there is only one, then the three characters before it represent 2 bytes
  8053. // this is just a cheap hack to not do indexOf twice
  8054. placeHolders = b64.indexOf('=');
  8055. placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0;
  8056. // base64 is 4/3 + up to two characters of the original data
  8057. arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders);
  8058. // if there are placeholders, only get up to the last complete 4 chars
  8059. l = placeHolders > 0 ? b64.length - 4 : b64.length;
  8060. for (i = 0, j = 0; i < l; i += 4, j += 3) {
  8061. tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]);
  8062. arr.push((tmp & 0xFF0000) >> 16);
  8063. arr.push((tmp & 0xFF00) >> 8);
  8064. arr.push(tmp & 0xFF);
  8065. }
  8066. if (placeHolders === 2) {
  8067. tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4);
  8068. arr.push(tmp & 0xFF);
  8069. } else if (placeHolders === 1) {
  8070. tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2);
  8071. arr.push((tmp >> 8) & 0xFF);
  8072. arr.push(tmp & 0xFF);
  8073. }
  8074. return arr;
  8075. }
  8076. function uint8ToBase64(uint8) {
  8077. var i,
  8078. extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
  8079. output = "",
  8080. temp, length;
  8081. function tripletToBase64 (num) {
  8082. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
  8083. };
  8084. // go through the array every three bytes, we'll deal with trailing stuff later
  8085. for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
  8086. temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
  8087. output += tripletToBase64(temp);
  8088. }
  8089. // pad the end with zeros, but make sure to not forget the extra bytes
  8090. switch (extraBytes) {
  8091. case 1:
  8092. temp = uint8[uint8.length - 1];
  8093. output += lookup[temp >> 2];
  8094. output += lookup[(temp << 4) & 0x3F];
  8095. output += '==';
  8096. break;
  8097. case 2:
  8098. temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]);
  8099. output += lookup[temp >> 10];
  8100. output += lookup[(temp >> 4) & 0x3F];
  8101. output += lookup[(temp << 2) & 0x3F];
  8102. output += '=';
  8103. break;
  8104. }
  8105. return output;
  8106. }
  8107. module.exports.toByteArray = b64ToByteArray;
  8108. module.exports.fromByteArray = uint8ToBase64;
  8109. }());
  8110. },{}]},{},[])
  8111. ;;module.exports=require("buffer-browserify")
  8112. },{}],30:[function(require,module,exports){
  8113. // shim for using process in browser
  8114. var process = module.exports = {};
  8115. process.nextTick = (function () {
  8116. var canSetImmediate = typeof window !== 'undefined'
  8117. && window.setImmediate;
  8118. var canPost = typeof window !== 'undefined'
  8119. && window.postMessage && window.addEventListener
  8120. ;
  8121. if (canSetImmediate) {
  8122. return function (f) { return window.setImmediate(f) };
  8123. }
  8124. if (canPost) {
  8125. var queue = [];
  8126. window.addEventListener('message', function (ev) {
  8127. var source = ev.source;
  8128. if ((source === window || source === null) && ev.data === 'process-tick') {
  8129. ev.stopPropagation();
  8130. if (queue.length > 0) {
  8131. var fn = queue.shift();
  8132. fn();
  8133. }
  8134. }
  8135. }, true);
  8136. return function nextTick(fn) {
  8137. queue.push(fn);
  8138. window.postMessage('process-tick', '*');
  8139. };
  8140. }
  8141. return function nextTick(fn) {
  8142. setTimeout(fn, 0);
  8143. };
  8144. })();
  8145. process.title = 'browser';
  8146. process.browser = true;
  8147. process.env = {};
  8148. process.argv = [];
  8149. process.binding = function (name) {
  8150. throw new Error('process.binding is not supported');
  8151. }
  8152. // TODO(shtylman)
  8153. process.cwd = function () { return '/' };
  8154. process.chdir = function (dir) {
  8155. throw new Error('process.chdir is not supported');
  8156. };
  8157. },{}],31:[function(require,module,exports){
  8158. module.exports = require('./lib/urlsafe-base64');
  8159. },{"./lib/urlsafe-base64":32}],32:[function(require,module,exports){
  8160. var Buffer=require("__browserify_Buffer").Buffer;/*!
  8161. * urlsafe-base64
  8162. */
  8163. /**
  8164. * Module Dependencies
  8165. */
  8166. // None yet!
  8167. /**
  8168. * Library version.
  8169. */
  8170. exports.version = '1.0.0';
  8171. /**
  8172. * .encode
  8173. *
  8174. * return an encoded Buffer as URL Safe Base64
  8175. *
  8176. * Note: This function encodes to the RFC 4648 Spec where '+' is encoded
  8177. * as '-' and '/' is encoded as '_'. The padding character '=' is
  8178. * removed.
  8179. *
  8180. * @param {Buffer} buffer
  8181. * @return {String}
  8182. * @api public
  8183. */
  8184. exports.encode = function encode(buffer) {
  8185. return buffer.toString('base64')
  8186. .replace(/\+/g, '-') // Convert '+' to '-'
  8187. .replace(/\//g, '_') // Convert '/' to '_'
  8188. .replace(/=+$/, ''); // Remove ending '='
  8189. };
  8190. /**
  8191. * .decode
  8192. *
  8193. * return an decoded URL Safe Base64 as Buffer
  8194. *
  8195. * @param {String}
  8196. * @return {Buffer}
  8197. * @api public
  8198. */
  8199. exports.decode = function decode(base64) {
  8200. // Add removed at end '='
  8201. base64 += Array(5 - base64.length % 4).join('=');
  8202. base64 = base64
  8203. .replace(/\-/g, '+') // Convert '-' to '+'
  8204. .replace(/\_/g, '/'); // Convert '_' to '/'
  8205. return new Buffer(base64, 'base64');
  8206. };
  8207. /**
  8208. * .validate
  8209. *
  8210. * Validates a string if it is URL Safe Base64 encoded.
  8211. *
  8212. * @param {String}
  8213. * @return {Boolean}
  8214. * @api public
  8215. */
  8216. exports.validate = function validate(base64) {
  8217. return /^[A-Za-z0-9\-_]+$/.test(base64);
  8218. };
  8219. },{"__browserify_Buffer":29}]},{},[1])
  8220. (1)
  8221. });
  8222. ;