1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868 |
- (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;
- 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){
- var Buffer=require("__browserify_Buffer").Buffer;var CryptoJS = require('crypto-js/core');
- var AES = require('crypto-js/aes');
- var Utf8 = require('crypto-js/enc-utf8');
- var Latin1 = require('crypto-js/enc-latin1');
- var Hex = require('crypto-js/enc-hex');
- var Base64 = require('crypto-js/enc-base64');
- var HmacSHA256 = require('crypto-js/hmac-sha256');
- var URLBase64 = require('urlsafe-base64');
- var crypto = require('crypto');
- //lpad a string for some hex conversions
- String.prototype.lpad = function (padString, length) {
- var str = this;
- while (str.length < length) str = padString + str;
- return str;
- }
- //Makes a Base64 string a url-safe base64 string
- var urlsafe = function urlsafe(string) {
- return string.replace(/\+/g, '-').replace(/\//g, '_') //.replace(/=+$/, '')
- }
- // parse a Hex string to an Int
- var parseHex = function parseHex(hexString) {
- return parseInt('0x' + hexString);
- }
- // turn bits into number of chars in a hex string
- var hexBits = function hexBits(bits) {
- return bits / 8 * 2;
- }
- // convert base64 string to hex string
- var decode64toHex = function decode64(string) {
- var s = URLBase64.decode(string.replace(/=+$/, ''));
- return (new Buffer(s)).toString('hex');
- }
- // convert array to hex string
- var ArrayToHex = function ArrayToHex(array) {
- var hex = '';
- for (var _byte in array) {
- hex += Number(_byte).toString(16).lpad('0', 2);
- }
- return hex;
- }
- var randomHex = function (size) {
- return crypto.randomBytes(128 / 8).toString('hex')
- }
- var setIV = function setIV(iv_array) {
- if (iv_array) {
- this.ivHex = ArrayToHex(iv_array);
- } else {
- this.ivHex = randomHex(128 / 8);
- }
- this.iv = Hex.parse(this.ivHex);
- return this.ivHex;
- }
- //convert Time object or now into WordArray
- var timeBytes = function timeBytes(time) {
- if (time) {
- time = (time / 1000)
- } else {
- time = (Math.round(new Date() / 1000))
- }
- var hexTime = time.toString(16).lpad('0', '16')
- return Hex.parse(hexTime);
- }
- var fernet = function fernet(opts) {
- this.Hex = Hex;
- this.Base64 = Base64;
- this.parseHex = parseHex;
- this.decode64toHex = decode64toHex;
- this.hexBits = hexBits;
- this.urlsafe = urlsafe;
- //Sets the secret from base64 encoded value
- this.setSecret = function setSecret(secret64) {
- this.secret = new this.Secret(secret64);
- return this.secret;
- }
- this.ArrayToHex = ArrayToHex;
- this.setIV = setIV;
- this.encryptMessage = function (message, encryptionKey, iv) {
- var encrypted = AES.encrypt(message, encryptionKey, { iv: iv });
- return encrypted.ciphertext;
- }
- this.decryptMessage = function (cipherText, encryptionKey, iv) {
- var encrypted = {};
- encrypted.key = encryptionKey;
- encrypted.iv = iv;
- encrypted.ciphertext = cipherText;
- var decrypted = AES.decrypt(encrypted, encryptionKey, { iv: iv });
- return decrypted.toString(Utf8);
- }
- this.timeBytes = timeBytes;
- this.createToken = function (signingKey, time, iv, cipherText) {
- var hmac = this.createHmac(signingKey, time, iv, cipherText);
- var tokenWords = Hex.parse(this.versionHex);
- tokenWords = tokenWords.concat(time);
- tokenWords = tokenWords.concat(iv);
- tokenWords = tokenWords.concat(cipherText);
- tokenWords = tokenWords.concat(hmac);
- return urlsafe(tokenWords.toString(Base64));
- }
- this.createHmac = function createHmac(signingKey, time, iv, cipherText) {
- var hmacWords = Hex.parse(this.versionHex);
- hmacWords = hmacWords.concat(time);
- hmacWords = hmacWords.concat(iv);
- hmacWords = hmacWords.concat(cipherText);
- return HmacSHA256(hmacWords, signingKey);
- }
- this.Secret = require('./lib/secret');
- this.Token = require('./lib/token')(this);
- opts = opts || {};
- this.ttl = opts.ttl || 60;
- // because (0 || x) always equals x
- if (opts.ttl === 0) this.ttl = 0;
- this.versionHex = '80';
- this.setIV(opts.iv);
- if (opts.secret) { this.setSecret(opts.secret) }
- }
- exports = module.exports = fernet;
- fernet.call(exports)
- },{"./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){
- var f = require('../fernet');
- var Secret = function (secret64) {
- var secret = f.decode64toHex(secret64);
- if (secret.length !== f.hexBits(256)) {
- throw new Error('Secret must be 32 url-safe base64-encoded bytes.');
- }
- this.signingKeyHex = secret.slice(0, f.hexBits(128));
- this.signingKey = f.Hex.parse(this.signingKeyHex);
- this.encryptionKeyHex = secret.slice(f.hexBits(128));
- this.encryptionKey = f.Hex.parse(this.encryptionKeyHex);
- }
- exports = module.exports = Secret;
- },{"../fernet":1}],3:[function(require,module,exports){
- var fernet = require('../fernet');
- //TokenFoctory
- module = module.exports = function (parent) {
- var Token = function Token(opts) {
- opts = opts || {};
- this.secret = opts.secret || parent.secret;
- this.ttl = opts.ttl || parent.ttl;
- if (opts.ttl === 0) this.ttl = 0;
- this.message = opts.message;
- this.cipherText = opts.cipherText;
- this.token = opts.token;
- this.version = opts.version || fernet.parseHex(parent.versionHex);
- this.optsIV = opts.iv;
- this.maxClockSkew = 60;
- if (opts.time) this.setTime(Date.parse(opts.time));
- else this.setTime();
- }
- Token.prototype = {
- setIV: fernet.setIV,
- setTime: function tokenSetTime(time) {
- this.time = fernet.timeBytes(time);
- },
- toString: function tokenToString() {
- if (this.encoded) {
- return this.token
- } else {
- return this.message
- }
- },
- encode: function encodeToken(message) {
- if (!this.secret) throw (new Error("Secret not set"));
- this.encoded = true;
- this.setIV(this.optsIV); //if null will always be a fresh IV
- this.message = message || this.message;
- this.cipherText = fernet.encryptMessage(this.message, this.secret.encryptionKey, this.iv);
- this.token = fernet.createToken(this.secret.signingKey, this.time, this.iv, this.cipherText)
- return this.token;
- },
- decode: function decodeToken(token) {
- if (!this.secret) throw (new Error("Secret not set"));
- this.encoded = false;
- this.token = token || this.token;
- var tokenString = fernet.decode64toHex(this.token);
- var versionOffset = fernet.hexBits(8);
- var timeOffset = versionOffset + fernet.hexBits(64);
- var ivOffset = timeOffset + fernet.hexBits(128);
- var hmacOffset = tokenString.length - fernet.hexBits(256);
- var timeInt = fernet.parseHex(tokenString.slice(versionOffset, timeOffset));
- this.version = fernet.parseHex(tokenString.slice(0, versionOffset));
- if (this.version != 128) {
- throw new Error("Invalid version");
- }
- this.time = new Date(timeInt * 1000);
- var currentTime = new Date()
- var timeDiff = (currentTime - this.time) / 1000;
- if (this.ttl > 0) {
- if (timeDiff > this.ttl) {
- throw new Error("Invalid Token: TTL");
- }
- if (((currentTime / 1000) + this.maxClockSkew) < timeInt) {
- throw new Error("far-future timestamp");
- }
- }
- this.ivHex = tokenString.slice(timeOffset, ivOffset);
- this.iv = fernet.Hex.parse(this.ivHex);
- this.cipherTextHex = tokenString.slice(ivOffset, hmacOffset);
- this.cipherText = fernet.Hex.parse(this.cipherTextHex);
- this.hmacHex = tokenString.slice(hmacOffset);
- var decodedHmac = fernet.createHmac(this.secret.signingKey, fernet.timeBytes(this.time), this.iv, this.cipherText);
- var decodedHmacHex = decodedHmac.toString(fernet.Hex);
- var accum = 0
- for (var i = 0; i < 64; i++) {
- accum += decodedHmacHex.charCodeAt(i) ^ this.hmacHex.charCodeAt(i)
- }
- if (accum != 0) throw new Error("Invalid Token: HMAC");
- this.message = fernet.decryptMessage(this.cipherText, this.secret.encryptionKey, this.iv)
- return this.message;
- }
- }
- return Token;
- }
- //exports = module.exports = Token;
- },{"../fernet":1}],4:[function(require,module,exports){
- (function (exports) {
- 'use strict';
- var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
- function b64ToByteArray(b64) {
- var i, j, l, tmp, placeHolders, arr;
-
- if (b64.length % 4 > 0) {
- throw 'Invalid string. Length must be a multiple of 4';
- }
- // the number of equal signs (place holders)
- // if there are two placeholders, than the two characters before it
- // represent one byte
- // if there is only one, then the three characters before it represent 2 bytes
- // this is just a cheap hack to not do indexOf twice
- placeHolders = b64.indexOf('=');
- placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0;
- // base64 is 4/3 + up to two characters of the original data
- arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders);
- // if there are placeholders, only get up to the last complete 4 chars
- l = placeHolders > 0 ? b64.length - 4 : b64.length;
- for (i = 0, j = 0; i < l; i += 4, j += 3) {
- tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]);
- arr.push((tmp & 0xFF0000) >> 16);
- arr.push((tmp & 0xFF00) >> 8);
- arr.push(tmp & 0xFF);
- }
- if (placeHolders === 2) {
- tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4);
- arr.push(tmp & 0xFF);
- } else if (placeHolders === 1) {
- tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2);
- arr.push((tmp >> 8) & 0xFF);
- arr.push(tmp & 0xFF);
- }
- return arr;
- }
- function uint8ToBase64(uint8) {
- var i,
- extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
- output = "",
- temp, length;
- function tripletToBase64 (num) {
- return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
- };
- // go through the array every three bytes, we'll deal with trailing stuff later
- for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
- temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
- output += tripletToBase64(temp);
- }
- // pad the end with zeros, but make sure to not forget the extra bytes
- switch (extraBytes) {
- case 1:
- temp = uint8[uint8.length - 1];
- output += lookup[temp >> 2];
- output += lookup[(temp << 4) & 0x3F];
- output += '==';
- break;
- case 2:
- temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]);
- output += lookup[temp >> 10];
- output += lookup[(temp >> 4) & 0x3F];
- output += lookup[(temp << 2) & 0x3F];
- output += '=';
- break;
- }
- return output;
- }
- module.exports.toByteArray = b64ToByteArray;
- module.exports.fromByteArray = uint8ToBase64;
- }());
- },{}],5:[function(require,module,exports){
- // UTILITY
- var util = require('util');
- var Buffer = require("buffer").Buffer;
- var pSlice = Array.prototype.slice;
- function objectKeys(object) {
- if (Object.keys) return Object.keys(object);
- var result = [];
- for (var name in object) {
- if (Object.prototype.hasOwnProperty.call(object, name)) {
- result.push(name);
- }
- }
- return result;
- }
- // 1. The assert module provides functions that throw
- // AssertionError's when particular conditions are not met. The
- // assert module must conform to the following interface.
- var assert = module.exports = ok;
- // 2. The AssertionError is defined in assert.
- // new assert.AssertionError({ message: message,
- // actual: actual,
- // expected: expected })
- assert.AssertionError = function AssertionError(options) {
- this.name = 'AssertionError';
- this.message = options.message;
- this.actual = options.actual;
- this.expected = options.expected;
- this.operator = options.operator;
- var stackStartFunction = options.stackStartFunction || fail;
- if (Error.captureStackTrace) {
- Error.captureStackTrace(this, stackStartFunction);
- }
- };
- // assert.AssertionError instanceof Error
- util.inherits(assert.AssertionError, Error);
- function replacer(key, value) {
- if (value === undefined) {
- return '' + value;
- }
- if (typeof value === 'number' && (isNaN(value) || !isFinite(value))) {
- return value.toString();
- }
- if (typeof value === 'function' || value instanceof RegExp) {
- return value.toString();
- }
- return value;
- }
- function truncate(s, n) {
- if (typeof s == 'string') {
- return s.length < n ? s : s.slice(0, n);
- } else {
- return s;
- }
- }
- assert.AssertionError.prototype.toString = function() {
- if (this.message) {
- return [this.name + ':', this.message].join(' ');
- } else {
- return [
- this.name + ':',
- truncate(JSON.stringify(this.actual, replacer), 128),
- this.operator,
- truncate(JSON.stringify(this.expected, replacer), 128)
- ].join(' ');
- }
- };
- // At present only the three keys mentioned above are used and
- // understood by the spec. Implementations or sub modules can pass
- // other keys to the AssertionError's constructor - they will be
- // ignored.
- // 3. All of the following functions must throw an AssertionError
- // when a corresponding condition is not met, with a message that
- // may be undefined if not provided. All assertion methods provide
- // both the actual and expected values to the assertion error for
- // display purposes.
- function fail(actual, expected, message, operator, stackStartFunction) {
- throw new assert.AssertionError({
- message: message,
- actual: actual,
- expected: expected,
- operator: operator,
- stackStartFunction: stackStartFunction
- });
- }
- // EXTENSION! allows for well behaved errors defined elsewhere.
- assert.fail = fail;
- // 4. Pure assertion tests whether a value is truthy, as determined
- // by !!guard.
- // assert.ok(guard, message_opt);
- // This statement is equivalent to assert.equal(true, guard,
- // message_opt);. To test strictly for the value true, use
- // assert.strictEqual(true, guard, message_opt);.
- function ok(value, message) {
- if (!!!value) fail(value, true, message, '==', assert.ok);
- }
- assert.ok = ok;
- // 5. The equality assertion tests shallow, coercive equality with
- // ==.
- // assert.equal(actual, expected, message_opt);
- assert.equal = function equal(actual, expected, message) {
- if (actual != expected) fail(actual, expected, message, '==', assert.equal);
- };
- // 6. The non-equality assertion tests for whether two objects are not equal
- // with != assert.notEqual(actual, expected, message_opt);
- assert.notEqual = function notEqual(actual, expected, message) {
- if (actual == expected) {
- fail(actual, expected, message, '!=', assert.notEqual);
- }
- };
- // 7. The equivalence assertion tests a deep equality relation.
- // assert.deepEqual(actual, expected, message_opt);
- assert.deepEqual = function deepEqual(actual, expected, message) {
- if (!_deepEqual(actual, expected)) {
- fail(actual, expected, message, 'deepEqual', assert.deepEqual);
- }
- };
- function _deepEqual(actual, expected) {
- // 7.1. All identical values are equivalent, as determined by ===.
- if (actual === expected) {
- return true;
- } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
- if (actual.length != expected.length) return false;
- for (var i = 0; i < actual.length; i++) {
- if (actual[i] !== expected[i]) return false;
- }
- return true;
- // 7.2. If the expected value is a Date object, the actual value is
- // equivalent if it is also a Date object that refers to the same time.
- } else if (actual instanceof Date && expected instanceof Date) {
- return actual.getTime() === expected.getTime();
- // 7.3. Other pairs that do not both pass typeof value == 'object',
- // equivalence is determined by ==.
- } else if (typeof actual != 'object' && typeof expected != 'object') {
- return actual == expected;
- // 7.4. For all other Object pairs, including Array objects, equivalence is
- // determined by having the same number of owned properties (as verified
- // with Object.prototype.hasOwnProperty.call), the same set of keys
- // (although not necessarily the same order), equivalent values for every
- // corresponding key, and an identical 'prototype' property. Note: this
- // accounts for both named and indexed properties on Arrays.
- } else {
- return objEquiv(actual, expected);
- }
- }
- function isUndefinedOrNull(value) {
- return value === null || value === undefined;
- }
- function isArguments(object) {
- return Object.prototype.toString.call(object) == '[object Arguments]';
- }
- function objEquiv(a, b) {
- if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
- return false;
- // an identical 'prototype' property.
- if (a.prototype !== b.prototype) return false;
- //~~~I've managed to break Object.keys through screwy arguments passing.
- // Converting to array solves the problem.
- if (isArguments(a)) {
- if (!isArguments(b)) {
- return false;
- }
- a = pSlice.call(a);
- b = pSlice.call(b);
- return _deepEqual(a, b);
- }
- try {
- var ka = objectKeys(a),
- kb = objectKeys(b),
- key, i;
- } catch (e) {//happens when one is a string literal and the other isn't
- return false;
- }
- // having the same number of owned properties (keys incorporates
- // hasOwnProperty)
- if (ka.length != kb.length)
- return false;
- //the same set of keys (although not necessarily the same order),
- ka.sort();
- kb.sort();
- //~~~cheap key test
- for (i = ka.length - 1; i >= 0; i--) {
- if (ka[i] != kb[i])
- return false;
- }
- //equivalent values for every corresponding key, and
- //~~~possibly expensive deep test
- for (i = ka.length - 1; i >= 0; i--) {
- key = ka[i];
- if (!_deepEqual(a[key], b[key])) return false;
- }
- return true;
- }
- // 8. The non-equivalence assertion tests for any deep inequality.
- // assert.notDeepEqual(actual, expected, message_opt);
- assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
- if (_deepEqual(actual, expected)) {
- fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
- }
- };
- // 9. The strict equality assertion tests strict equality, as determined by ===.
- // assert.strictEqual(actual, expected, message_opt);
- assert.strictEqual = function strictEqual(actual, expected, message) {
- if (actual !== expected) {
- fail(actual, expected, message, '===', assert.strictEqual);
- }
- };
- // 10. The strict non-equality assertion tests for strict inequality, as
- // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
- assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
- if (actual === expected) {
- fail(actual, expected, message, '!==', assert.notStrictEqual);
- }
- };
- function expectedException(actual, expected) {
- if (!actual || !expected) {
- return false;
- }
- if (expected instanceof RegExp) {
- return expected.test(actual);
- } else if (actual instanceof expected) {
- return true;
- } else if (expected.call({}, actual) === true) {
- return true;
- }
- return false;
- }
- function _throws(shouldThrow, block, expected, message) {
- var actual;
- if (typeof expected === 'string') {
- message = expected;
- expected = null;
- }
- try {
- block();
- } catch (e) {
- actual = e;
- }
- message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
- (message ? ' ' + message : '.');
- if (shouldThrow && !actual) {
- fail('Missing expected exception' + message);
- }
- if (!shouldThrow && expectedException(actual, expected)) {
- fail('Got unwanted exception' + message);
- }
- if ((shouldThrow && actual && expected &&
- !expectedException(actual, expected)) || (!shouldThrow && actual)) {
- throw actual;
- }
- }
- // 11. Expected to throw an error:
- // assert.throws(block, Error_opt, message_opt);
- assert.throws = function(block, /*optional*/error, /*optional*/message) {
- _throws.apply(this, [true].concat(pSlice.call(arguments)));
- };
- // EXTENSION! This is annoying to write outside this module.
- assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
- _throws.apply(this, [false].concat(pSlice.call(arguments)));
- };
- assert.ifError = function(err) { if (err) {throw err;}};
- },{"buffer":9,"util":7}],6:[function(require,module,exports){
- var process=require("__browserify_process");if (!process.EventEmitter) process.EventEmitter = function () {};
- var EventEmitter = exports.EventEmitter = process.EventEmitter;
- var isArray = typeof Array.isArray === 'function'
- ? Array.isArray
- : function (xs) {
- return Object.prototype.toString.call(xs) === '[object Array]'
- }
- ;
- function indexOf (xs, x) {
- if (xs.indexOf) return xs.indexOf(x);
- for (var i = 0; i < xs.length; i++) {
- if (x === xs[i]) return i;
- }
- return -1;
- }
- // By default EventEmitters will print a warning if more than
- // 10 listeners are added to it. This is a useful default which
- // helps finding memory leaks.
- //
- // Obviously not all Emitters should be limited to 10. This function allows
- // that to be increased. Set to zero for unlimited.
- var defaultMaxListeners = 10;
- EventEmitter.prototype.setMaxListeners = function(n) {
- if (!this._events) this._events = {};
- this._events.maxListeners = n;
- };
- EventEmitter.prototype.emit = function(type) {
- // If there is no 'error' event listener then throw.
- if (type === 'error') {
- if (!this._events || !this._events.error ||
- (isArray(this._events.error) && !this._events.error.length))
- {
- if (arguments[1] instanceof Error) {
- throw arguments[1]; // Unhandled 'error' event
- } else {
- throw new Error("Uncaught, unspecified 'error' event.");
- }
- return false;
- }
- }
- if (!this._events) return false;
- var handler = this._events[type];
- if (!handler) return false;
- if (typeof handler == 'function') {
- switch (arguments.length) {
- // fast cases
- case 1:
- handler.call(this);
- break;
- case 2:
- handler.call(this, arguments[1]);
- break;
- case 3:
- handler.call(this, arguments[1], arguments[2]);
- break;
- // slower
- default:
- var args = Array.prototype.slice.call(arguments, 1);
- handler.apply(this, args);
- }
- return true;
- } else if (isArray(handler)) {
- var args = Array.prototype.slice.call(arguments, 1);
- var listeners = handler.slice();
- for (var i = 0, l = listeners.length; i < l; i++) {
- listeners[i].apply(this, args);
- }
- return true;
- } else {
- return false;
- }
- };
- // EventEmitter is defined in src/node_events.cc
- // EventEmitter.prototype.emit() is also defined there.
- EventEmitter.prototype.addListener = function(type, listener) {
- if ('function' !== typeof listener) {
- throw new Error('addListener only takes instances of Function');
- }
- if (!this._events) this._events = {};
- // To avoid recursion in the case that type == "newListeners"! Before
- // adding it to the listeners, first emit "newListeners".
- this.emit('newListener', type, listener);
- if (!this._events[type]) {
- // Optimize the case of one listener. Don't need the extra array object.
- this._events[type] = listener;
- } else if (isArray(this._events[type])) {
- // Check for listener leak
- if (!this._events[type].warned) {
- var m;
- if (this._events.maxListeners !== undefined) {
- m = this._events.maxListeners;
- } else {
- m = defaultMaxListeners;
- }
- if (m && m > 0 && this._events[type].length > m) {
- this._events[type].warned = true;
- console.error('(node) warning: possible EventEmitter memory ' +
- 'leak detected. %d listeners added. ' +
- 'Use emitter.setMaxListeners() to increase limit.',
- this._events[type].length);
- console.trace();
- }
- }
- // If we've already got an array, just append.
- this._events[type].push(listener);
- } else {
- // Adding the second element, need to change to array.
- this._events[type] = [this._events[type], listener];
- }
- return this;
- };
- EventEmitter.prototype.on = EventEmitter.prototype.addListener;
- EventEmitter.prototype.once = function(type, listener) {
- var self = this;
- self.on(type, function g() {
- self.removeListener(type, g);
- listener.apply(this, arguments);
- });
- return this;
- };
- EventEmitter.prototype.removeListener = function(type, listener) {
- if ('function' !== typeof listener) {
- throw new Error('removeListener only takes instances of Function');
- }
- // does not use listeners(), so no side effect of creating _events[type]
- if (!this._events || !this._events[type]) return this;
- var list = this._events[type];
- if (isArray(list)) {
- var i = indexOf(list, listener);
- if (i < 0) return this;
- list.splice(i, 1);
- if (list.length == 0)
- delete this._events[type];
- } else if (this._events[type] === listener) {
- delete this._events[type];
- }
- return this;
- };
- EventEmitter.prototype.removeAllListeners = function(type) {
- if (arguments.length === 0) {
- this._events = {};
- return this;
- }
- // does not use listeners(), so no side effect of creating _events[type]
- if (type && this._events && this._events[type]) this._events[type] = null;
- return this;
- };
- EventEmitter.prototype.listeners = function(type) {
- if (!this._events) this._events = {};
- if (!this._events[type]) this._events[type] = [];
- if (!isArray(this._events[type])) {
- this._events[type] = [this._events[type]];
- }
- return this._events[type];
- };
- EventEmitter.listenerCount = function(emitter, type) {
- var ret;
- if (!emitter._events || !emitter._events[type])
- ret = 0;
- else if (typeof emitter._events[type] === 'function')
- ret = 1;
- else
- ret = emitter._events[type].length;
- return ret;
- };
- },{"__browserify_process":30}],7:[function(require,module,exports){
- var events = require('events');
- exports.isArray = isArray;
- exports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'};
- exports.isRegExp = function(obj){return Object.prototype.toString.call(obj) === '[object RegExp]'};
- exports.print = function () {};
- exports.puts = function () {};
- exports.debug = function() {};
- exports.inspect = function(obj, showHidden, depth, colors) {
- var seen = [];
- var stylize = function(str, styleType) {
- // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
- var styles =
- { 'bold' : [1, 22],
- 'italic' : [3, 23],
- 'underline' : [4, 24],
- 'inverse' : [7, 27],
- 'white' : [37, 39],
- 'grey' : [90, 39],
- 'black' : [30, 39],
- 'blue' : [34, 39],
- 'cyan' : [36, 39],
- 'green' : [32, 39],
- 'magenta' : [35, 39],
- 'red' : [31, 39],
- 'yellow' : [33, 39] };
- var style =
- { 'special': 'cyan',
- 'number': 'blue',
- 'boolean': 'yellow',
- 'undefined': 'grey',
- 'null': 'bold',
- 'string': 'green',
- 'date': 'magenta',
- // "name": intentionally not styling
- 'regexp': 'red' }[styleType];
- if (style) {
- return '\u001b[' + styles[style][0] + 'm' + str +
- '\u001b[' + styles[style][1] + 'm';
- } else {
- return str;
- }
- };
- if (! colors) {
- stylize = function(str, styleType) { return str; };
- }
- function format(value, recurseTimes) {
- // Provide a hook for user-specified inspect functions.
- // Check that value is an object with an inspect function on it
- if (value && typeof value.inspect === 'function' &&
- // Filter out the util module, it's inspect function is special
- value !== exports &&
- // Also filter out any prototype objects using the circular check.
- !(value.constructor && value.constructor.prototype === value)) {
- return value.inspect(recurseTimes);
- }
- // Primitive types cannot have properties
- switch (typeof value) {
- case 'undefined':
- return stylize('undefined', 'undefined');
- case 'string':
- var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
- .replace(/'/g, "\\'")
- .replace(/\\"/g, '"') + '\'';
- return stylize(simple, 'string');
- case 'number':
- return stylize('' + value, 'number');
- case 'boolean':
- return stylize('' + value, 'boolean');
- }
- // For some reason typeof null is "object", so special case here.
- if (value === null) {
- return stylize('null', 'null');
- }
- // Look up the keys of the object.
- var visible_keys = Object_keys(value);
- var keys = showHidden ? Object_getOwnPropertyNames(value) : visible_keys;
- // Functions without properties can be shortcutted.
- if (typeof value === 'function' && keys.length === 0) {
- if (isRegExp(value)) {
- return stylize('' + value, 'regexp');
- } else {
- var name = value.name ? ': ' + value.name : '';
- return stylize('[Function' + name + ']', 'special');
- }
- }
- // Dates without properties can be shortcutted
- if (isDate(value) && keys.length === 0) {
- return stylize(value.toUTCString(), 'date');
- }
- var base, type, braces;
- // Determine the object type
- if (isArray(value)) {
- type = 'Array';
- braces = ['[', ']'];
- } else {
- type = 'Object';
- braces = ['{', '}'];
- }
- // Make functions say that they are functions
- if (typeof value === 'function') {
- var n = value.name ? ': ' + value.name : '';
- base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']';
- } else {
- base = '';
- }
- // Make dates with properties first say the date
- if (isDate(value)) {
- base = ' ' + value.toUTCString();
- }
- if (keys.length === 0) {
- return braces[0] + base + braces[1];
- }
- if (recurseTimes < 0) {
- if (isRegExp(value)) {
- return stylize('' + value, 'regexp');
- } else {
- return stylize('[Object]', 'special');
- }
- }
- seen.push(value);
- var output = keys.map(function(key) {
- var name, str;
- if (value.__lookupGetter__) {
- if (value.__lookupGetter__(key)) {
- if (value.__lookupSetter__(key)) {
- str = stylize('[Getter/Setter]', 'special');
- } else {
- str = stylize('[Getter]', 'special');
- }
- } else {
- if (value.__lookupSetter__(key)) {
- str = stylize('[Setter]', 'special');
- }
- }
- }
- if (visible_keys.indexOf(key) < 0) {
- name = '[' + key + ']';
- }
- if (!str) {
- if (seen.indexOf(value[key]) < 0) {
- if (recurseTimes === null) {
- str = format(value[key]);
- } else {
- str = format(value[key], recurseTimes - 1);
- }
- if (str.indexOf('\n') > -1) {
- if (isArray(value)) {
- str = str.split('\n').map(function(line) {
- return ' ' + line;
- }).join('\n').substr(2);
- } else {
- str = '\n' + str.split('\n').map(function(line) {
- return ' ' + line;
- }).join('\n');
- }
- }
- } else {
- str = stylize('[Circular]', 'special');
- }
- }
- if (typeof name === 'undefined') {
- if (type === 'Array' && key.match(/^\d+$/)) {
- return str;
- }
- name = JSON.stringify('' + key);
- if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
- name = name.substr(1, name.length - 2);
- name = stylize(name, 'name');
- } else {
- name = name.replace(/'/g, "\\'")
- .replace(/\\"/g, '"')
- .replace(/(^"|"$)/g, "'");
- name = stylize(name, 'string');
- }
- }
- return name + ': ' + str;
- });
- seen.pop();
- var numLinesEst = 0;
- var length = output.reduce(function(prev, cur) {
- numLinesEst++;
- if (cur.indexOf('\n') >= 0) numLinesEst++;
- return prev + cur.length + 1;
- }, 0);
- if (length > 50) {
- output = braces[0] +
- (base === '' ? '' : base + '\n ') +
- ' ' +
- output.join(',\n ') +
- ' ' +
- braces[1];
- } else {
- output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
- }
- return output;
- }
- return format(obj, (typeof depth === 'undefined' ? 2 : depth));
- };
- function isArray(ar) {
- return Array.isArray(ar) ||
- (typeof ar === 'object' && Object.prototype.toString.call(ar) === '[object Array]');
- }
- function isRegExp(re) {
- typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]';
- }
- function isDate(d) {
- return typeof d === 'object' && Object.prototype.toString.call(d) === '[object Date]';
- }
- function pad(n) {
- return n < 10 ? '0' + n.toString(10) : n.toString(10);
- }
- var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
- 'Oct', 'Nov', 'Dec'];
- // 26 Feb 16:19:34
- function timestamp() {
- var d = new Date();
- var time = [pad(d.getHours()),
- pad(d.getMinutes()),
- pad(d.getSeconds())].join(':');
- return [d.getDate(), months[d.getMonth()], time].join(' ');
- }
- exports.log = function (msg) {};
- exports.pump = null;
- var Object_keys = Object.keys || function (obj) {
- var res = [];
- for (var key in obj) res.push(key);
- return res;
- };
- var Object_getOwnPropertyNames = Object.getOwnPropertyNames || function (obj) {
- var res = [];
- for (var key in obj) {
- if (Object.hasOwnProperty.call(obj, key)) res.push(key);
- }
- return res;
- };
- var Object_create = Object.create || function (prototype, properties) {
- // from es5-shim
- var object;
- if (prototype === null) {
- object = { '__proto__' : null };
- }
- else {
- if (typeof prototype !== 'object') {
- throw new TypeError(
- 'typeof prototype[' + (typeof prototype) + '] != \'object\''
- );
- }
- var Type = function () {};
- Type.prototype = prototype;
- object = new Type();
- object.__proto__ = prototype;
- }
- if (typeof properties !== 'undefined' && Object.defineProperties) {
- Object.defineProperties(object, properties);
- }
- return object;
- };
- exports.inherits = function(ctor, superCtor) {
- ctor.super_ = superCtor;
- ctor.prototype = Object_create(superCtor.prototype, {
- constructor: {
- value: ctor,
- enumerable: false,
- writable: true,
- configurable: true
- }
- });
- };
- var formatRegExp = /%[sdj%]/g;
- exports.format = function(f) {
- if (typeof f !== 'string') {
- var objects = [];
- for (var i = 0; i < arguments.length; i++) {
- objects.push(exports.inspect(arguments[i]));
- }
- return objects.join(' ');
- }
- var i = 1;
- var args = arguments;
- var len = args.length;
- var str = String(f).replace(formatRegExp, function(x) {
- if (x === '%%') return '%';
- if (i >= len) return x;
- switch (x) {
- case '%s': return String(args[i++]);
- case '%d': return Number(args[i++]);
- case '%j': return JSON.stringify(args[i++]);
- default:
- return x;
- }
- });
- for(var x = args[i]; i < len; x = args[++i]){
- if (x === null || typeof x !== 'object') {
- str += ' ' + x;
- } else {
- str += ' ' + exports.inspect(x);
- }
- }
- return str;
- };
- },{"events":6}],8:[function(require,module,exports){
- exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) {
- var e, m,
- eLen = nBytes * 8 - mLen - 1,
- eMax = (1 << eLen) - 1,
- eBias = eMax >> 1,
- nBits = -7,
- i = isBE ? 0 : (nBytes - 1),
- d = isBE ? 1 : -1,
- s = buffer[offset + i];
- i += d;
- e = s & ((1 << (-nBits)) - 1);
- s >>= (-nBits);
- nBits += eLen;
- for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
- m = e & ((1 << (-nBits)) - 1);
- e >>= (-nBits);
- nBits += mLen;
- for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
- if (e === 0) {
- e = 1 - eBias;
- } else if (e === eMax) {
- return m ? NaN : ((s ? -1 : 1) * Infinity);
- } else {
- m = m + Math.pow(2, mLen);
- e = e - eBias;
- }
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
- };
- exports.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) {
- var e, m, c,
- eLen = nBytes * 8 - mLen - 1,
- eMax = (1 << eLen) - 1,
- eBias = eMax >> 1,
- rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
- i = isBE ? (nBytes - 1) : 0,
- d = isBE ? -1 : 1,
- s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
- value = Math.abs(value);
- if (isNaN(value) || value === Infinity) {
- m = isNaN(value) ? 1 : 0;
- e = eMax;
- } else {
- e = Math.floor(Math.log(value) / Math.LN2);
- if (value * (c = Math.pow(2, -e)) < 1) {
- e--;
- c *= 2;
- }
- if (e + eBias >= 1) {
- value += rt / c;
- } else {
- value += rt * Math.pow(2, 1 - eBias);
- }
- if (value * c >= 2) {
- e++;
- c /= 2;
- }
- if (e + eBias >= eMax) {
- m = 0;
- e = eMax;
- } else if (e + eBias >= 1) {
- m = (value * c - 1) * Math.pow(2, mLen);
- e = e + eBias;
- } else {
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
- e = 0;
- }
- }
- for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
- e = (e << mLen) | m;
- eLen += mLen;
- for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
- buffer[offset + i - d] |= s * 128;
- };
- },{}],9:[function(require,module,exports){
- var assert = require('assert');
- exports.Buffer = Buffer;
- exports.SlowBuffer = Buffer;
- Buffer.poolSize = 8192;
- exports.INSPECT_MAX_BYTES = 50;
- function Buffer(subject, encoding, offset) {
- if (!(this instanceof Buffer)) {
- return new Buffer(subject, encoding, offset);
- }
- this.parent = this;
- this.offset = 0;
- var type;
- // Are we slicing?
- if (typeof offset === 'number') {
- this.length = coerce(encoding);
- this.offset = offset;
- } else {
- // Find the length
- switch (type = typeof subject) {
- case 'number':
- this.length = coerce(subject);
- break;
- case 'string':
- this.length = Buffer.byteLength(subject, encoding);
- break;
- case 'object': // Assume object is an array
- this.length = coerce(subject.length);
- break;
- default:
- throw new Error('First argument needs to be a number, ' +
- 'array or string.');
- }
- // Treat array-ish objects as a byte array.
- if (isArrayIsh(subject)) {
- for (var i = 0; i < this.length; i++) {
- if (subject instanceof Buffer) {
- this[i] = subject.readUInt8(i);
- }
- else {
- this[i] = subject[i];
- }
- }
- } else if (type == 'string') {
- // We are a string
- this.length = this.write(subject, 0, encoding);
- } else if (type === 'number') {
- for (var i = 0; i < this.length; i++) {
- this[i] = 0;
- }
- }
- }
- }
- Buffer.prototype.get = function get(i) {
- if (i < 0 || i >= this.length) throw new Error('oob');
- return this[i];
- };
- Buffer.prototype.set = function set(i, v) {
- if (i < 0 || i >= this.length) throw new Error('oob');
- return this[i] = v;
- };
- Buffer.byteLength = function (str, encoding) {
- switch (encoding || "utf8") {
- case 'hex':
- return str.length / 2;
- case 'utf8':
- case 'utf-8':
- return utf8ToBytes(str).length;
- case 'ascii':
- case 'binary':
- return str.length;
- case 'base64':
- return base64ToBytes(str).length;
- default:
- throw new Error('Unknown encoding');
- }
- };
- Buffer.prototype.utf8Write = function (string, offset, length) {
- var bytes, pos;
- return Buffer._charsWritten = blitBuffer(utf8ToBytes(string), this, offset, length);
- };
- Buffer.prototype.asciiWrite = function (string, offset, length) {
- var bytes, pos;
- return Buffer._charsWritten = blitBuffer(asciiToBytes(string), this, offset, length);
- };
- Buffer.prototype.binaryWrite = Buffer.prototype.asciiWrite;
- Buffer.prototype.base64Write = function (string, offset, length) {
- var bytes, pos;
- return Buffer._charsWritten = blitBuffer(base64ToBytes(string), this, offset, length);
- };
- Buffer.prototype.base64Slice = function (start, end) {
- var bytes = Array.prototype.slice.apply(this, arguments)
- return require("base64-js").fromByteArray(bytes);
- };
- Buffer.prototype.utf8Slice = function () {
- var bytes = Array.prototype.slice.apply(this, arguments);
- var res = "";
- var tmp = "";
- var i = 0;
- while (i < bytes.length) {
- if (bytes[i] <= 0x7F) {
- res += decodeUtf8Char(tmp) + String.fromCharCode(bytes[i]);
- tmp = "";
- } else
- tmp += "%" + bytes[i].toString(16);
- i++;
- }
- return res + decodeUtf8Char(tmp);
- }
- Buffer.prototype.asciiSlice = function () {
- var bytes = Array.prototype.slice.apply(this, arguments);
- var ret = "";
- for (var i = 0; i < bytes.length; i++)
- ret += String.fromCharCode(bytes[i]);
- return ret;
- }
- Buffer.prototype.binarySlice = Buffer.prototype.asciiSlice;
- Buffer.prototype.inspect = function() {
- var out = [],
- len = this.length;
- for (var i = 0; i < len; i++) {
- out[i] = toHex(this[i]);
- if (i == exports.INSPECT_MAX_BYTES) {
- out[i + 1] = '...';
- break;
- }
- }
- return '<Buffer ' + out.join(' ') + '>';
- };
- Buffer.prototype.hexSlice = function(start, end) {
- var len = this.length;
- if (!start || start < 0) start = 0;
- if (!end || end < 0 || end > len) end = len;
- var out = '';
- for (var i = start; i < end; i++) {
- out += toHex(this[i]);
- }
- return out;
- };
- Buffer.prototype.toString = function(encoding, start, end) {
- encoding = String(encoding || 'utf8').toLowerCase();
- start = +start || 0;
- if (typeof end == 'undefined') end = this.length;
- // Fastpath empty strings
- if (+end == start) {
- return '';
- }
- switch (encoding) {
- case 'hex':
- return this.hexSlice(start, end);
- case 'utf8':
- case 'utf-8':
- return this.utf8Slice(start, end);
- case 'ascii':
- return this.asciiSlice(start, end);
- case 'binary':
- return this.binarySlice(start, end);
- case 'base64':
- return this.base64Slice(start, end);
- case 'ucs2':
- case 'ucs-2':
- return this.ucs2Slice(start, end);
- default:
- throw new Error('Unknown encoding');
- }
- };
- Buffer.prototype.hexWrite = function(string, offset, length) {
- offset = +offset || 0;
- var remaining = this.length - offset;
- if (!length) {
- length = remaining;
- } else {
- length = +length;
- if (length > remaining) {
- length = remaining;
- }
- }
- // must be an even number of digits
- var strLen = string.length;
- if (strLen % 2) {
- throw new Error('Invalid hex string');
- }
- if (length > strLen / 2) {
- length = strLen / 2;
- }
- for (var i = 0; i < length; i++) {
- var byte = parseInt(string.substr(i * 2, 2), 16);
- if (isNaN(byte)) throw new Error('Invalid hex string');
- this[offset + i] = byte;
- }
- Buffer._charsWritten = i * 2;
- return i;
- };
- Buffer.prototype.write = function(string, offset, length, encoding) {
- // Support both (string, offset, length, encoding)
- // and the legacy (string, encoding, offset, length)
- if (isFinite(offset)) {
- if (!isFinite(length)) {
- encoding = length;
- length = undefined;
- }
- } else { // legacy
- var swap = encoding;
- encoding = offset;
- offset = length;
- length = swap;
- }
- offset = +offset || 0;
- var remaining = this.length - offset;
- if (!length) {
- length = remaining;
- } else {
- length = +length;
- if (length > remaining) {
- length = remaining;
- }
- }
- encoding = String(encoding || 'utf8').toLowerCase();
- switch (encoding) {
- case 'hex':
- return this.hexWrite(string, offset, length);
- case 'utf8':
- case 'utf-8':
- return this.utf8Write(string, offset, length);
- case 'ascii':
- return this.asciiWrite(string, offset, length);
- case 'binary':
- return this.binaryWrite(string, offset, length);
- case 'base64':
- return this.base64Write(string, offset, length);
- case 'ucs2':
- case 'ucs-2':
- return this.ucs2Write(string, offset, length);
- default:
- throw new Error('Unknown encoding');
- }
- };
- // slice(start, end)
- Buffer.prototype.slice = function(start, end) {
- if (end === undefined) end = this.length;
- if (end > this.length) {
- throw new Error('oob');
- }
- if (start > end) {
- throw new Error('oob');
- }
- return new Buffer(this, end - start, +start);
- };
- // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
- Buffer.prototype.copy = function(target, target_start, start, end) {
- var source = this;
- start || (start = 0);
- if (end === undefined || isNaN(end)) {
- end = this.length;
- }
- target_start || (target_start = 0);
- if (end < start) throw new Error('sourceEnd < sourceStart');
- // Copy 0 bytes; we're done
- if (end === start) return 0;
- if (target.length == 0 || source.length == 0) return 0;
- if (target_start < 0 || target_start >= target.length) {
- throw new Error('targetStart out of bounds');
- }
- if (start < 0 || start >= source.length) {
- throw new Error('sourceStart out of bounds');
- }
- if (end < 0 || end > source.length) {
- throw new Error('sourceEnd out of bounds');
- }
- // Are we oob?
- if (end > this.length) {
- end = this.length;
- }
- if (target.length - target_start < end - start) {
- end = target.length - target_start + start;
- }
- var temp = [];
- for (var i=start; i<end; i++) {
- assert.ok(typeof this[i] !== 'undefined', "copying undefined buffer bytes!");
- temp.push(this[i]);
- }
- for (var i=target_start; i<target_start+temp.length; i++) {
- target[i] = temp[i-target_start];
- }
- };
- // fill(value, start=0, end=buffer.length)
- Buffer.prototype.fill = function fill(value, start, end) {
- value || (value = 0);
- start || (start = 0);
- end || (end = this.length);
- if (typeof value === 'string') {
- value = value.charCodeAt(0);
- }
- if (!(typeof value === 'number') || isNaN(value)) {
- throw new Error('value is not a number');
- }
- if (end < start) throw new Error('end < start');
- // Fill 0 bytes; we're done
- if (end === start) return 0;
- if (this.length == 0) return 0;
- if (start < 0 || start >= this.length) {
- throw new Error('start out of bounds');
- }
- if (end < 0 || end > this.length) {
- throw new Error('end out of bounds');
- }
- for (var i = start; i < end; i++) {
- this[i] = value;
- }
- }
- // Static methods
- Buffer.isBuffer = function isBuffer(b) {
- return b instanceof Buffer || b instanceof Buffer;
- };
- Buffer.concat = function (list, totalLength) {
- if (!isArray(list)) {
- throw new Error("Usage: Buffer.concat(list, [totalLength])\n \
- list should be an Array.");
- }
- if (list.length === 0) {
- return new Buffer(0);
- } else if (list.length === 1) {
- return list[0];
- }
- if (typeof totalLength !== 'number') {
- totalLength = 0;
- for (var i = 0; i < list.length; i++) {
- var buf = list[i];
- totalLength += buf.length;
- }
- }
- var buffer = new Buffer(totalLength);
- var pos = 0;
- for (var i = 0; i < list.length; i++) {
- var buf = list[i];
- buf.copy(buffer, pos);
- pos += buf.length;
- }
- return buffer;
- };
- // helpers
- function coerce(length) {
- // Coerce length to a number (possibly NaN), round up
- // in case it's fractional (e.g. 123.456) then do a
- // double negate to coerce a NaN to 0. Easy, right?
- length = ~~Math.ceil(+length);
- return length < 0 ? 0 : length;
- }
- function isArray(subject) {
- return (Array.isArray ||
- function(subject){
- return {}.toString.apply(subject) == '[object Array]'
- })
- (subject)
- }
- function isArrayIsh(subject) {
- return isArray(subject) || Buffer.isBuffer(subject) ||
- subject && typeof subject === 'object' &&
- typeof subject.length === 'number';
- }
- function toHex(n) {
- if (n < 16) return '0' + n.toString(16);
- return n.toString(16);
- }
- function utf8ToBytes(str) {
- var byteArray = [];
- for (var i = 0; i < str.length; i++)
- if (str.charCodeAt(i) <= 0x7F)
- byteArray.push(str.charCodeAt(i));
- else {
- var h = encodeURIComponent(str.charAt(i)).substr(1).split('%');
- for (var j = 0; j < h.length; j++)
- byteArray.push(parseInt(h[j], 16));
- }
- return byteArray;
- }
- function asciiToBytes(str) {
- var byteArray = []
- for (var i = 0; i < str.length; i++ )
- // Node's code seems to be doing this and not & 0x7F..
- byteArray.push( str.charCodeAt(i) & 0xFF );
- return byteArray;
- }
- function base64ToBytes(str) {
- return require("base64-js").toByteArray(str);
- }
- function blitBuffer(src, dst, offset, length) {
- var pos, i = 0;
- while (i < length) {
- if ((i+offset >= dst.length) || (i >= src.length))
- break;
- dst[i + offset] = src[i];
- i++;
- }
- return i;
- }
- function decodeUtf8Char(str) {
- try {
- return decodeURIComponent(str);
- } catch (err) {
- return String.fromCharCode(0xFFFD); // UTF 8 invalid char
- }
- }
- // read/write bit-twiddling
- Buffer.prototype.readUInt8 = function(offset, noAssert) {
- var buffer = this;
- if (!noAssert) {
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset < buffer.length,
- 'Trying to read beyond buffer length');
- }
- if (offset >= buffer.length) return;
- return buffer[offset];
- };
- function readUInt16(buffer, offset, isBigEndian, noAssert) {
- var val = 0;
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 1 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- if (offset >= buffer.length) return 0;
- if (isBigEndian) {
- val = buffer[offset] << 8;
- if (offset + 1 < buffer.length) {
- val |= buffer[offset + 1];
- }
- } else {
- val = buffer[offset];
- if (offset + 1 < buffer.length) {
- val |= buffer[offset + 1] << 8;
- }
- }
- return val;
- }
- Buffer.prototype.readUInt16LE = function(offset, noAssert) {
- return readUInt16(this, offset, false, noAssert);
- };
- Buffer.prototype.readUInt16BE = function(offset, noAssert) {
- return readUInt16(this, offset, true, noAssert);
- };
- function readUInt32(buffer, offset, isBigEndian, noAssert) {
- var val = 0;
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- if (offset >= buffer.length) return 0;
- if (isBigEndian) {
- if (offset + 1 < buffer.length)
- val = buffer[offset + 1] << 16;
- if (offset + 2 < buffer.length)
- val |= buffer[offset + 2] << 8;
- if (offset + 3 < buffer.length)
- val |= buffer[offset + 3];
- val = val + (buffer[offset] << 24 >>> 0);
- } else {
- if (offset + 2 < buffer.length)
- val = buffer[offset + 2] << 16;
- if (offset + 1 < buffer.length)
- val |= buffer[offset + 1] << 8;
- val |= buffer[offset];
- if (offset + 3 < buffer.length)
- val = val + (buffer[offset + 3] << 24 >>> 0);
- }
- return val;
- }
- Buffer.prototype.readUInt32LE = function(offset, noAssert) {
- return readUInt32(this, offset, false, noAssert);
- };
- Buffer.prototype.readUInt32BE = function(offset, noAssert) {
- return readUInt32(this, offset, true, noAssert);
- };
- /*
- * Signed integer types, yay team! A reminder on how two's complement actually
- * works. The first bit is the signed bit, i.e. tells us whether or not the
- * number should be positive or negative. If the two's complement value is
- * positive, then we're done, as it's equivalent to the unsigned representation.
- *
- * Now if the number is positive, you're pretty much done, you can just leverage
- * the unsigned translations and return those. Unfortunately, negative numbers
- * aren't quite that straightforward.
- *
- * At first glance, one might be inclined to use the traditional formula to
- * translate binary numbers between the positive and negative values in two's
- * complement. (Though it doesn't quite work for the most negative value)
- * Mainly:
- * - invert all the bits
- * - add one to the result
- *
- * Of course, this doesn't quite work in Javascript. Take for example the value
- * of -128. This could be represented in 16 bits (big-endian) as 0xff80. But of
- * course, Javascript will do the following:
- *
- * > ~0xff80
- * -65409
- *
- * Whoh there, Javascript, that's not quite right. But wait, according to
- * Javascript that's perfectly correct. When Javascript ends up seeing the
- * constant 0xff80, it has no notion that it is actually a signed number. It
- * assumes that we've input the unsigned value 0xff80. Thus, when it does the
- * binary negation, it casts it into a signed value, (positive 0xff80). Then
- * when you perform binary negation on that, it turns it into a negative number.
- *
- * Instead, we're going to have to use the following general formula, that works
- * in a rather Javascript friendly way. I'm glad we don't support this kind of
- * weird numbering scheme in the kernel.
- *
- * (BIT-MAX - (unsigned)val + 1) * -1
- *
- * The astute observer, may think that this doesn't make sense for 8-bit numbers
- * (really it isn't necessary for them). However, when you get 16-bit numbers,
- * you do. Let's go back to our prior example and see how this will look:
- *
- * (0xffff - 0xff80 + 1) * -1
- * (0x007f + 1) * -1
- * (0x0080) * -1
- */
- Buffer.prototype.readInt8 = function(offset, noAssert) {
- var buffer = this;
- var neg;
- if (!noAssert) {
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset < buffer.length,
- 'Trying to read beyond buffer length');
- }
- if (offset >= buffer.length) return;
- neg = buffer[offset] & 0x80;
- if (!neg) {
- return (buffer[offset]);
- }
- return ((0xff - buffer[offset] + 1) * -1);
- };
- function readInt16(buffer, offset, isBigEndian, noAssert) {
- var neg, val;
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 1 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- val = readUInt16(buffer, offset, isBigEndian, noAssert);
- neg = val & 0x8000;
- if (!neg) {
- return val;
- }
- return (0xffff - val + 1) * -1;
- }
- Buffer.prototype.readInt16LE = function(offset, noAssert) {
- return readInt16(this, offset, false, noAssert);
- };
- Buffer.prototype.readInt16BE = function(offset, noAssert) {
- return readInt16(this, offset, true, noAssert);
- };
- function readInt32(buffer, offset, isBigEndian, noAssert) {
- var neg, val;
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- val = readUInt32(buffer, offset, isBigEndian, noAssert);
- neg = val & 0x80000000;
- if (!neg) {
- return (val);
- }
- return (0xffffffff - val + 1) * -1;
- }
- Buffer.prototype.readInt32LE = function(offset, noAssert) {
- return readInt32(this, offset, false, noAssert);
- };
- Buffer.prototype.readInt32BE = function(offset, noAssert) {
- return readInt32(this, offset, true, noAssert);
- };
- function readFloat(buffer, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
- 23, 4);
- }
- Buffer.prototype.readFloatLE = function(offset, noAssert) {
- return readFloat(this, offset, false, noAssert);
- };
- Buffer.prototype.readFloatBE = function(offset, noAssert) {
- return readFloat(this, offset, true, noAssert);
- };
- function readDouble(buffer, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset + 7 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
- 52, 8);
- }
- Buffer.prototype.readDoubleLE = function(offset, noAssert) {
- return readDouble(this, offset, false, noAssert);
- };
- Buffer.prototype.readDoubleBE = function(offset, noAssert) {
- return readDouble(this, offset, true, noAssert);
- };
- /*
- * We have to make sure that the value is a valid integer. This means that it is
- * non-negative. It has no fractional component and that it does not exceed the
- * maximum allowed value.
- *
- * value The number to check for validity
- *
- * max The maximum value
- */
- function verifuint(value, max) {
- assert.ok(typeof (value) == 'number',
- 'cannot write a non-number as a number');
- assert.ok(value >= 0,
- 'specified a negative value for writing an unsigned value');
- assert.ok(value <= max, 'value is larger than maximum value for type');
- assert.ok(Math.floor(value) === value, 'value has a fractional component');
- }
- Buffer.prototype.writeUInt8 = function(value, offset, noAssert) {
- var buffer = this;
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset < buffer.length,
- 'trying to write beyond buffer length');
- verifuint(value, 0xff);
- }
- if (offset < buffer.length) {
- buffer[offset] = value;
- }
- };
- function writeUInt16(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 1 < buffer.length,
- 'trying to write beyond buffer length');
- verifuint(value, 0xffff);
- }
- for (var i = 0; i < Math.min(buffer.length - offset, 2); i++) {
- buffer[offset + i] =
- (value & (0xff << (8 * (isBigEndian ? 1 - i : i)))) >>>
- (isBigEndian ? 1 - i : i) * 8;
- }
- }
- Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) {
- writeUInt16(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) {
- writeUInt16(this, value, offset, true, noAssert);
- };
- function writeUInt32(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'trying to write beyond buffer length');
- verifuint(value, 0xffffffff);
- }
- for (var i = 0; i < Math.min(buffer.length - offset, 4); i++) {
- buffer[offset + i] =
- (value >>> (isBigEndian ? 3 - i : i) * 8) & 0xff;
- }
- }
- Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) {
- writeUInt32(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) {
- writeUInt32(this, value, offset, true, noAssert);
- };
- /*
- * We now move onto our friends in the signed number category. Unlike unsigned
- * numbers, we're going to have to worry a bit more about how we put values into
- * arrays. Since we are only worrying about signed 32-bit values, we're in
- * slightly better shape. Unfortunately, we really can't do our favorite binary
- * & in this system. It really seems to do the wrong thing. For example:
- *
- * > -32 & 0xff
- * 224
- *
- * What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of
- * this aren't treated as a signed number. Ultimately a bad thing.
- *
- * What we're going to want to do is basically create the unsigned equivalent of
- * our representation and pass that off to the wuint* functions. To do that
- * we're going to do the following:
- *
- * - if the value is positive
- * we can pass it directly off to the equivalent wuint
- * - if the value is negative
- * we do the following computation:
- * mb + val + 1, where
- * mb is the maximum unsigned value in that byte size
- * val is the Javascript negative integer
- *
- *
- * As a concrete value, take -128. In signed 16 bits this would be 0xff80. If
- * you do out the computations:
- *
- * 0xffff - 128 + 1
- * 0xffff - 127
- * 0xff80
- *
- * You can then encode this value as the signed version. This is really rather
- * hacky, but it should work and get the job done which is our goal here.
- */
- /*
- * A series of checks to make sure we actually have a signed 32-bit number
- */
- function verifsint(value, max, min) {
- assert.ok(typeof (value) == 'number',
- 'cannot write a non-number as a number');
- assert.ok(value <= max, 'value larger than maximum allowed value');
- assert.ok(value >= min, 'value smaller than minimum allowed value');
- assert.ok(Math.floor(value) === value, 'value has a fractional component');
- }
- function verifIEEE754(value, max, min) {
- assert.ok(typeof (value) == 'number',
- 'cannot write a non-number as a number');
- assert.ok(value <= max, 'value larger than maximum allowed value');
- assert.ok(value >= min, 'value smaller than minimum allowed value');
- }
- Buffer.prototype.writeInt8 = function(value, offset, noAssert) {
- var buffer = this;
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset < buffer.length,
- 'Trying to write beyond buffer length');
- verifsint(value, 0x7f, -0x80);
- }
- if (value >= 0) {
- buffer.writeUInt8(value, offset, noAssert);
- } else {
- buffer.writeUInt8(0xff + value + 1, offset, noAssert);
- }
- };
- function writeInt16(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 1 < buffer.length,
- 'Trying to write beyond buffer length');
- verifsint(value, 0x7fff, -0x8000);
- }
- if (value >= 0) {
- writeUInt16(buffer, value, offset, isBigEndian, noAssert);
- } else {
- writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert);
- }
- }
- Buffer.prototype.writeInt16LE = function(value, offset, noAssert) {
- writeInt16(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeInt16BE = function(value, offset, noAssert) {
- writeInt16(this, value, offset, true, noAssert);
- };
- function writeInt32(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to write beyond buffer length');
- verifsint(value, 0x7fffffff, -0x80000000);
- }
- if (value >= 0) {
- writeUInt32(buffer, value, offset, isBigEndian, noAssert);
- } else {
- writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert);
- }
- }
- Buffer.prototype.writeInt32LE = function(value, offset, noAssert) {
- writeInt32(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {
- writeInt32(this, value, offset, true, noAssert);
- };
- function writeFloat(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to write beyond buffer length');
- verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38);
- }
- require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
- 23, 4);
- }
- Buffer.prototype.writeFloatLE = function(value, offset, noAssert) {
- writeFloat(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeFloatBE = function(value, offset, noAssert) {
- writeFloat(this, value, offset, true, noAssert);
- };
- function writeDouble(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 7 < buffer.length,
- 'Trying to write beyond buffer length');
- verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308);
- }
- require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
- 52, 8);
- }
- Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) {
- writeDouble(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) {
- writeDouble(this, value, offset, true, noAssert);
- };
- },{"./buffer_ieee754":8,"assert":5,"base64-js":4}],10:[function(require,module,exports){
- var Buffer = require('buffer').Buffer;
- var intSize = 4;
- var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0);
- var chrsz = 8;
- function toArray(buf, bigEndian) {
- if ((buf.length % intSize) !== 0) {
- var len = buf.length + (intSize - (buf.length % intSize));
- buf = Buffer.concat([buf, zeroBuffer], len);
- }
- var arr = [];
- var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE;
- for (var i = 0; i < buf.length; i += intSize) {
- arr.push(fn.call(buf, i));
- }
- return arr;
- }
- function toBuffer(arr, size, bigEndian) {
- var buf = new Buffer(size);
- var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE;
- for (var i = 0; i < arr.length; i++) {
- fn.call(buf, arr[i], i * 4, true);
- }
- return buf;
- }
- function hash(buf, fn, hashSize, bigEndian) {
- if (!Buffer.isBuffer(buf)) buf = new Buffer(buf);
- var arr = fn(toArray(buf, bigEndian), buf.length * chrsz);
- return toBuffer(arr, hashSize, bigEndian);
- }
- module.exports = { hash: hash };
- },{"buffer":9}],11:[function(require,module,exports){
- var Buffer = require('buffer').Buffer
- var sha = require('./sha')
- var sha256 = require('./sha256')
- var rng = require('./rng')
- var md5 = require('./md5')
- var algorithms = {
- sha1: sha,
- sha256: sha256,
- md5: md5
- }
- var blocksize = 64
- var zeroBuffer = new Buffer(blocksize); zeroBuffer.fill(0)
- function hmac(fn, key, data) {
- if(!Buffer.isBuffer(key)) key = new Buffer(key)
- if(!Buffer.isBuffer(data)) data = new Buffer(data)
- if(key.length > blocksize) {
- key = fn(key)
- } else if(key.length < blocksize) {
- key = Buffer.concat([key, zeroBuffer], blocksize)
- }
- var ipad = new Buffer(blocksize), opad = new Buffer(blocksize)
- for(var i = 0; i < blocksize; i++) {
- ipad[i] = key[i] ^ 0x36
- opad[i] = key[i] ^ 0x5C
- }
- var hash = fn(Buffer.concat([ipad, data]))
- return fn(Buffer.concat([opad, hash]))
- }
- function hash(alg, key) {
- alg = alg || 'sha1'
- var fn = algorithms[alg]
- var bufs = []
- var length = 0
- if(!fn) error('algorithm:', alg, 'is not yet supported')
- return {
- update: function (data) {
- if(!Buffer.isBuffer(data)) data = new Buffer(data)
-
- bufs.push(data)
- length += data.length
- return this
- },
- digest: function (enc) {
- var buf = Buffer.concat(bufs)
- var r = key ? hmac(fn, key, buf) : fn(buf)
- bufs = null
- return enc ? r.toString(enc) : r
- }
- }
- }
- function error () {
- var m = [].slice.call(arguments).join(' ')
- throw new Error([
- m,
- 'we accept pull requests',
- 'http://github.com/dominictarr/crypto-browserify'
- ].join('\n'))
- }
- exports.createHash = function (alg) { return hash(alg) }
- exports.createHmac = function (alg, key) { return hash(alg, key) }
- exports.randomBytes = function(size, callback) {
- if (callback && callback.call) {
- try {
- callback.call(this, undefined, new Buffer(rng(size)))
- } catch (err) { callback(err) }
- } else {
- return new Buffer(rng(size))
- }
- }
- function each(a, f) {
- for(var i in a)
- f(a[i], i)
- }
- // the least I can do is make error messages for the rest of the node.js/crypto api.
- each(['createCredentials'
- , 'createCipher'
- , 'createCipheriv'
- , 'createDecipher'
- , 'createDecipheriv'
- , 'createSign'
- , 'createVerify'
- , 'createDiffieHellman'
- , 'pbkdf2'], function (name) {
- exports[name] = function () {
- error('sorry,', name, 'is not implemented yet')
- }
- })
- },{"./md5":12,"./rng":13,"./sha":14,"./sha256":15,"buffer":9}],12:[function(require,module,exports){
- /*
- * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
- * Digest Algorithm, as defined in RFC 1321.
- * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
- * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
- * Distributed under the BSD License
- * See http://pajhome.org.uk/crypt/md5 for more info.
- */
- var helpers = require('./helpers');
- /*
- * Perform a simple self-test to see if the VM is working
- */
- function md5_vm_test()
- {
- return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
- }
- /*
- * Calculate the MD5 of an array of little-endian words, and a bit length
- */
- function core_md5(x, len)
- {
- /* append padding */
- x[len >> 5] |= 0x80 << ((len) % 32);
- x[(((len + 64) >>> 9) << 4) + 14] = len;
- var a = 1732584193;
- var b = -271733879;
- var c = -1732584194;
- var d = 271733878;
- for(var i = 0; i < x.length; i += 16)
- {
- var olda = a;
- var oldb = b;
- var oldc = c;
- var oldd = d;
- a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
- d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
- c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
- b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
- a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
- d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
- c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
- b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
- a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
- d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
- c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
- b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
- a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
- d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
- c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
- b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
- a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
- d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
- c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
- b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
- a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
- d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
- c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
- b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
- a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
- d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
- c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
- b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
- a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
- d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
- c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
- b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
- a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
- d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
- c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
- b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
- a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
- d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
- c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
- b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
- a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
- d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
- c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
- b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
- a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
- d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
- c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
- b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
- a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
- d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
- c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
- b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
- a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
- d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
- c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
- b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
- a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
- d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
- c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
- b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
- a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
- d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
- c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
- b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
- a = safe_add(a, olda);
- b = safe_add(b, oldb);
- c = safe_add(c, oldc);
- d = safe_add(d, oldd);
- }
- return Array(a, b, c, d);
- }
- /*
- * These functions implement the four basic operations the algorithm uses.
- */
- function md5_cmn(q, a, b, x, s, t)
- {
- return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
- }
- function md5_ff(a, b, c, d, x, s, t)
- {
- return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
- }
- function md5_gg(a, b, c, d, x, s, t)
- {
- return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
- }
- function md5_hh(a, b, c, d, x, s, t)
- {
- return md5_cmn(b ^ c ^ d, a, b, x, s, t);
- }
- function md5_ii(a, b, c, d, x, s, t)
- {
- return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
- }
- /*
- * Add integers, wrapping at 2^32. This uses 16-bit operations internally
- * to work around bugs in some JS interpreters.
- */
- function safe_add(x, y)
- {
- var lsw = (x & 0xFFFF) + (y & 0xFFFF);
- var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
- return (msw << 16) | (lsw & 0xFFFF);
- }
- /*
- * Bitwise rotate a 32-bit number to the left.
- */
- function bit_rol(num, cnt)
- {
- return (num << cnt) | (num >>> (32 - cnt));
- }
- module.exports = function md5(buf) {
- return helpers.hash(buf, core_md5, 16);
- };
- },{"./helpers":10}],13:[function(require,module,exports){
- // Original code adapted from Robert Kieffer.
- // details at https://github.com/broofa/node-uuid
- (function() {
- var _global = this;
- var mathRNG, whatwgRNG;
- // NOTE: Math.random() does not guarantee "cryptographic quality"
- mathRNG = function(size) {
- var bytes = new Array(size);
- var r;
- for (var i = 0, r; i < size; i++) {
- if ((i & 0x03) == 0) r = Math.random() * 0x100000000;
- bytes[i] = r >>> ((i & 0x03) << 3) & 0xff;
- }
- return bytes;
- }
- if (_global.crypto && crypto.getRandomValues) {
- whatwgRNG = function(size) {
- var bytes = new Uint8Array(size);
- crypto.getRandomValues(bytes);
- return bytes;
- }
- }
- module.exports = whatwgRNG || mathRNG;
- }())
- },{}],14:[function(require,module,exports){
- /*
- * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
- * in FIPS PUB 180-1
- * Version 2.1a Copyright Paul Johnston 2000 - 2002.
- * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
- * Distributed under the BSD License
- * See http://pajhome.org.uk/crypt/md5 for details.
- */
- var helpers = require('./helpers');
- /*
- * Calculate the SHA-1 of an array of big-endian words, and a bit length
- */
- function core_sha1(x, len)
- {
- /* append padding */
- x[len >> 5] |= 0x80 << (24 - len % 32);
- x[((len + 64 >> 9) << 4) + 15] = len;
- var w = Array(80);
- var a = 1732584193;
- var b = -271733879;
- var c = -1732584194;
- var d = 271733878;
- var e = -1009589776;
- for(var i = 0; i < x.length; i += 16)
- {
- var olda = a;
- var oldb = b;
- var oldc = c;
- var oldd = d;
- var olde = e;
- for(var j = 0; j < 80; j++)
- {
- if(j < 16) w[j] = x[i + j];
- else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
- var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
- safe_add(safe_add(e, w[j]), sha1_kt(j)));
- e = d;
- d = c;
- c = rol(b, 30);
- b = a;
- a = t;
- }
- a = safe_add(a, olda);
- b = safe_add(b, oldb);
- c = safe_add(c, oldc);
- d = safe_add(d, oldd);
- e = safe_add(e, olde);
- }
- return Array(a, b, c, d, e);
- }
- /*
- * Perform the appropriate triplet combination function for the current
- * iteration
- */
- function sha1_ft(t, b, c, d)
- {
- if(t < 20) return (b & c) | ((~b) & d);
- if(t < 40) return b ^ c ^ d;
- if(t < 60) return (b & c) | (b & d) | (c & d);
- return b ^ c ^ d;
- }
- /*
- * Determine the appropriate additive constant for the current iteration
- */
- function sha1_kt(t)
- {
- return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
- (t < 60) ? -1894007588 : -899497514;
- }
- /*
- * Add integers, wrapping at 2^32. This uses 16-bit operations internally
- * to work around bugs in some JS interpreters.
- */
- function safe_add(x, y)
- {
- var lsw = (x & 0xFFFF) + (y & 0xFFFF);
- var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
- return (msw << 16) | (lsw & 0xFFFF);
- }
- /*
- * Bitwise rotate a 32-bit number to the left.
- */
- function rol(num, cnt)
- {
- return (num << cnt) | (num >>> (32 - cnt));
- }
- module.exports = function sha1(buf) {
- return helpers.hash(buf, core_sha1, 20, true);
- };
- },{"./helpers":10}],15:[function(require,module,exports){
- /**
- * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
- * in FIPS 180-2
- * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
- * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
- *
- */
- var helpers = require('./helpers');
- var safe_add = function(x, y) {
- var lsw = (x & 0xFFFF) + (y & 0xFFFF);
- var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
- return (msw << 16) | (lsw & 0xFFFF);
- };
- var S = function(X, n) {
- return (X >>> n) | (X << (32 - n));
- };
- var R = function(X, n) {
- return (X >>> n);
- };
- var Ch = function(x, y, z) {
- return ((x & y) ^ ((~x) & z));
- };
- var Maj = function(x, y, z) {
- return ((x & y) ^ (x & z) ^ (y & z));
- };
- var Sigma0256 = function(x) {
- return (S(x, 2) ^ S(x, 13) ^ S(x, 22));
- };
- var Sigma1256 = function(x) {
- return (S(x, 6) ^ S(x, 11) ^ S(x, 25));
- };
- var Gamma0256 = function(x) {
- return (S(x, 7) ^ S(x, 18) ^ R(x, 3));
- };
- var Gamma1256 = function(x) {
- return (S(x, 17) ^ S(x, 19) ^ R(x, 10));
- };
- var core_sha256 = function(m, l) {
- 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);
- var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19);
- var W = new Array(64);
- var a, b, c, d, e, f, g, h, i, j;
- var T1, T2;
- /* append padding */
- m[l >> 5] |= 0x80 << (24 - l % 32);
- m[((l + 64 >> 9) << 4) + 15] = l;
- for (var i = 0; i < m.length; i += 16) {
- a = HASH[0]; b = HASH[1]; c = HASH[2]; d = HASH[3]; e = HASH[4]; f = HASH[5]; g = HASH[6]; h = HASH[7];
- for (var j = 0; j < 64; j++) {
- if (j < 16) {
- W[j] = m[j + i];
- } else {
- W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);
- }
- T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);
- T2 = safe_add(Sigma0256(a), Maj(a, b, c));
- h = g; g = f; f = e; e = safe_add(d, T1); d = c; c = b; b = a; a = safe_add(T1, T2);
- }
- 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]);
- 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]);
- }
- return HASH;
- };
- module.exports = function sha256(buf) {
- return helpers.hash(buf, core_sha256, 32, true);
- };
- },{"./helpers":10}],16:[function(require,module,exports){
- ;(function (root, factory, undef) {
- if (typeof exports === "object") {
- // CommonJS
- module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core"));
- }
- else if (typeof define === "function" && define.amd) {
- // AMD
- define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory);
- }
- else {
- // Global (browser)
- factory(root.CryptoJS);
- }
- }(this, function (CryptoJS) {
- (function () {
- // Shortcuts
- var C = CryptoJS;
- var C_lib = C.lib;
- var BlockCipher = C_lib.BlockCipher;
- var C_algo = C.algo;
- // Lookup tables
- var SBOX = [];
- var INV_SBOX = [];
- var SUB_MIX_0 = [];
- var SUB_MIX_1 = [];
- var SUB_MIX_2 = [];
- var SUB_MIX_3 = [];
- var INV_SUB_MIX_0 = [];
- var INV_SUB_MIX_1 = [];
- var INV_SUB_MIX_2 = [];
- var INV_SUB_MIX_3 = [];
- // Compute lookup tables
- (function () {
- // Compute double table
- var d = [];
- for (var i = 0; i < 256; i++) {
- if (i < 128) {
- d[i] = i << 1;
- } else {
- d[i] = (i << 1) ^ 0x11b;
- }
- }
- // Walk GF(2^8)
- var x = 0;
- var xi = 0;
- for (var i = 0; i < 256; i++) {
- // Compute sbox
- var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
- sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
- SBOX[x] = sx;
- INV_SBOX[sx] = x;
- // Compute multiplication
- var x2 = d[x];
- var x4 = d[x2];
- var x8 = d[x4];
- // Compute sub bytes, mix columns tables
- var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
- SUB_MIX_0[x] = (t << 24) | (t >>> 8);
- SUB_MIX_1[x] = (t << 16) | (t >>> 16);
- SUB_MIX_2[x] = (t << 8) | (t >>> 24);
- SUB_MIX_3[x] = t;
- // Compute inv sub bytes, inv mix columns tables
- var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
- INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
- INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
- INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
- INV_SUB_MIX_3[sx] = t;
- // Compute next counter
- if (!x) {
- x = xi = 1;
- } else {
- x = x2 ^ d[d[d[x8 ^ x2]]];
- xi ^= d[d[xi]];
- }
- }
- }());
- // Precomputed Rcon lookup
- var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
- /**
- * AES block cipher algorithm.
- */
- var AES = C_algo.AES = BlockCipher.extend({
- _doReset: function () {
- // Skip reset of nRounds has been set before and key did not change
- if (this._nRounds && this._keyPriorReset === this._key) {
- return;
- }
- // Shortcuts
- var key = this._keyPriorReset = this._key;
- var keyWords = key.words;
- var keySize = key.sigBytes / 4;
- // Compute number of rounds
- var nRounds = this._nRounds = keySize + 6;
- // Compute number of key schedule rows
- var ksRows = (nRounds + 1) * 4;
- // Compute key schedule
- var keySchedule = this._keySchedule = [];
- for (var ksRow = 0; ksRow < ksRows; ksRow++) {
- if (ksRow < keySize) {
- keySchedule[ksRow] = keyWords[ksRow];
- } else {
- var t = keySchedule[ksRow - 1];
- if (!(ksRow % keySize)) {
- // Rot word
- t = (t << 8) | (t >>> 24);
- // Sub word
- t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
- // Mix Rcon
- t ^= RCON[(ksRow / keySize) | 0] << 24;
- } else if (keySize > 6 && ksRow % keySize == 4) {
- // Sub word
- t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
- }
- keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
- }
- }
- // Compute inv key schedule
- var invKeySchedule = this._invKeySchedule = [];
- for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
- var ksRow = ksRows - invKsRow;
- if (invKsRow % 4) {
- var t = keySchedule[ksRow];
- } else {
- var t = keySchedule[ksRow - 4];
- }
- if (invKsRow < 4 || ksRow <= 4) {
- invKeySchedule[invKsRow] = t;
- } else {
- invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
- INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
- }
- }
- },
- encryptBlock: function (M, offset) {
- this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
- },
- decryptBlock: function (M, offset) {
- // Swap 2nd and 4th rows
- var t = M[offset + 1];
- M[offset + 1] = M[offset + 3];
- M[offset + 3] = t;
- this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
- // Inv swap 2nd and 4th rows
- var t = M[offset + 1];
- M[offset + 1] = M[offset + 3];
- M[offset + 3] = t;
- },
- _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
- // Shortcut
- var nRounds = this._nRounds;
- // Get input, add round key
- var s0 = M[offset] ^ keySchedule[0];
- var s1 = M[offset + 1] ^ keySchedule[1];
- var s2 = M[offset + 2] ^ keySchedule[2];
- var s3 = M[offset + 3] ^ keySchedule[3];
- // Key schedule row counter
- var ksRow = 4;
- // Rounds
- for (var round = 1; round < nRounds; round++) {
- // Shift rows, sub bytes, mix columns, add round key
- 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++];
- 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++];
- 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++];
- 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++];
- // Update state
- s0 = t0;
- s1 = t1;
- s2 = t2;
- s3 = t3;
- }
- // Shift rows, sub bytes, add round key
- var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
- var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
- var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
- var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
- // Set output
- M[offset] = t0;
- M[offset + 1] = t1;
- M[offset + 2] = t2;
- M[offset + 3] = t3;
- },
- keySize: 256/32
- });
- /**
- * Shortcut functions to the cipher's object interface.
- *
- * @example
- *
- * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
- * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
- */
- C.AES = BlockCipher._createHelper(AES);
- }());
- return CryptoJS.AES;
- }));
- },{"./cipher-core":17,"./core":18,"./enc-base64":19,"./evpkdf":23,"./md5":26}],17:[function(require,module,exports){
- ;(function (root, factory) {
- if (typeof exports === "object") {
- // CommonJS
- module.exports = exports = factory(require("./core"));
- }
- else if (typeof define === "function" && define.amd) {
- // AMD
- define(["./core"], factory);
- }
- else {
- // Global (browser)
- factory(root.CryptoJS);
- }
- }(this, function (CryptoJS) {
- /**
- * Cipher core components.
- */
- CryptoJS.lib.Cipher || (function (undefined) {
- // Shortcuts
- var C = CryptoJS;
- var C_lib = C.lib;
- var Base = C_lib.Base;
- var WordArray = C_lib.WordArray;
- var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
- var C_enc = C.enc;
- var Utf8 = C_enc.Utf8;
- var Base64 = C_enc.Base64;
- var C_algo = C.algo;
- var EvpKDF = C_algo.EvpKDF;
- /**
- * Abstract base cipher template.
- *
- * @property {number} keySize This cipher's key size. Default: 4 (128 bits)
- * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
- * @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
- * @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
- */
- var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
- /**
- * Configuration options.
- *
- * @property {WordArray} iv The IV to use for this operation.
- */
- cfg: Base.extend(),
- /**
- * Creates this cipher in encryption mode.
- *
- * @param {WordArray} key The key.
- * @param {Object} cfg (Optional) The configuration options to use for this operation.
- *
- * @return {Cipher} A cipher instance.
- *
- * @static
- *
- * @example
- *
- * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
- */
- createEncryptor: function (key, cfg) {
- return this.create(this._ENC_XFORM_MODE, key, cfg);
- },
- /**
- * Creates this cipher in decryption mode.
- *
- * @param {WordArray} key The key.
- * @param {Object} cfg (Optional) The configuration options to use for this operation.
- *
- * @return {Cipher} A cipher instance.
- *
- * @static
- *
- * @example
- *
- * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
- */
- createDecryptor: function (key, cfg) {
- return this.create(this._DEC_XFORM_MODE, key, cfg);
- },
- /**
- * Initializes a newly created cipher.
- *
- * @param {number} xformMode Either the encryption or decryption transormation mode constant.
- * @param {WordArray} key The key.
- * @param {Object} cfg (Optional) The configuration options to use for this operation.
- *
- * @example
- *
- * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
- */
- init: function (xformMode, key, cfg) {
- // Apply config defaults
- this.cfg = this.cfg.extend(cfg);
- // Store transform mode and key
- this._xformMode = xformMode;
- this._key = key;
- // Set initial values
- this.reset();
- },
- /**
- * Resets this cipher to its initial state.
- *
- * @example
- *
- * cipher.reset();
- */
- reset: function () {
- // Reset data buffer
- BufferedBlockAlgorithm.reset.call(this);
- // Perform concrete-cipher logic
- this._doReset();
- },
- /**
- * Adds data to be encrypted or decrypted.
- *
- * @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
- *
- * @return {WordArray} The data after processing.
- *
- * @example
- *
- * var encrypted = cipher.process('data');
- * var encrypted = cipher.process(wordArray);
- */
- process: function (dataUpdate) {
- // Append
- this._append(dataUpdate);
- // Process available blocks
- return this._process();
- },
- /**
- * Finalizes the encryption or decryption process.
- * Note that the finalize operation is effectively a destructive, read-once operation.
- *
- * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
- *
- * @return {WordArray} The data after final processing.
- *
- * @example
- *
- * var encrypted = cipher.finalize();
- * var encrypted = cipher.finalize('data');
- * var encrypted = cipher.finalize(wordArray);
- */
- finalize: function (dataUpdate) {
- // Final data update
- if (dataUpdate) {
- this._append(dataUpdate);
- }
- // Perform concrete-cipher logic
- var finalProcessedData = this._doFinalize();
- return finalProcessedData;
- },
- keySize: 128/32,
- ivSize: 128/32,
- _ENC_XFORM_MODE: 1,
- _DEC_XFORM_MODE: 2,
- /**
- * Creates shortcut functions to a cipher's object interface.
- *
- * @param {Cipher} cipher The cipher to create a helper for.
- *
- * @return {Object} An object with encrypt and decrypt shortcut functions.
- *
- * @static
- *
- * @example
- *
- * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
- */
- _createHelper: (function () {
- function selectCipherStrategy(key) {
- if (typeof key == 'string') {
- return PasswordBasedCipher;
- } else {
- return SerializableCipher;
- }
- }
- return function (cipher) {
- return {
- encrypt: function (message, key, cfg) {
- return selectCipherStrategy(key).encrypt(cipher, message, key, cfg);
- },
- decrypt: function (ciphertext, key, cfg) {
- return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg);
- }
- };
- };
- }())
- });
- /**
- * Abstract base stream cipher template.
- *
- * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
- */
- var StreamCipher = C_lib.StreamCipher = Cipher.extend({
- _doFinalize: function () {
- // Process partial blocks
- var finalProcessedBlocks = this._process(!!'flush');
- return finalProcessedBlocks;
- },
- blockSize: 1
- });
- /**
- * Mode namespace.
- */
- var C_mode = C.mode = {};
- /**
- * Abstract base block cipher mode template.
- */
- var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({
- /**
- * Creates this mode for encryption.
- *
- * @param {Cipher} cipher A block cipher instance.
- * @param {Array} iv The IV words.
- *
- * @static
- *
- * @example
- *
- * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
- */
- createEncryptor: function (cipher, iv) {
- return this.Encryptor.create(cipher, iv);
- },
- /**
- * Creates this mode for decryption.
- *
- * @param {Cipher} cipher A block cipher instance.
- * @param {Array} iv The IV words.
- *
- * @static
- *
- * @example
- *
- * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
- */
- createDecryptor: function (cipher, iv) {
- return this.Decryptor.create(cipher, iv);
- },
- /**
- * Initializes a newly created mode.
- *
- * @param {Cipher} cipher A block cipher instance.
- * @param {Array} iv The IV words.
- *
- * @example
- *
- * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
- */
- init: function (cipher, iv) {
- this._cipher = cipher;
- this._iv = iv;
- }
- });
- /**
- * Cipher Block Chaining mode.
- */
- var CBC = C_mode.CBC = (function () {
- /**
- * Abstract base CBC mode.
- */
- var CBC = BlockCipherMode.extend();
- /**
- * CBC encryptor.
- */
- CBC.Encryptor = CBC.extend({
- /**
- * Processes the data block at offset.
- *
- * @param {Array} words The data words to operate on.
- * @param {number} offset The offset where the block starts.
- *
- * @example
- *
- * mode.processBlock(data.words, offset);
- */
- processBlock: function (words, offset) {
- // Shortcuts
- var cipher = this._cipher;
- var blockSize = cipher.blockSize;
- // XOR and encrypt
- xorBlock.call(this, words, offset, blockSize);
- cipher.encryptBlock(words, offset);
- // Remember this block to use with next block
- this._prevBlock = words.slice(offset, offset + blockSize);
- }
- });
- /**
- * CBC decryptor.
- */
- CBC.Decryptor = CBC.extend({
- /**
- * Processes the data block at offset.
- *
- * @param {Array} words The data words to operate on.
- * @param {number} offset The offset where the block starts.
- *
- * @example
- *
- * mode.processBlock(data.words, offset);
- */
- processBlock: function (words, offset) {
- // Shortcuts
- var cipher = this._cipher;
- var blockSize = cipher.blockSize;
- // Remember this block to use with next block
- var thisBlock = words.slice(offset, offset + blockSize);
- // Decrypt and XOR
- cipher.decryptBlock(words, offset);
- xorBlock.call(this, words, offset, blockSize);
- // This block becomes the previous block
- this._prevBlock = thisBlock;
- }
- });
- function xorBlock(words, offset, blockSize) {
- // Shortcut
- var iv = this._iv;
- // Choose mixing block
- if (iv) {
- var block = iv;
- // Remove IV for subsequent blocks
- this._iv = undefined;
- } else {
- var block = this._prevBlock;
- }
- // XOR blocks
- for (var i = 0; i < blockSize; i++) {
- words[offset + i] ^= block[i];
- }
- }
- return CBC;
- }());
- /**
- * Padding namespace.
- */
- var C_pad = C.pad = {};
- /**
- * PKCS #5/7 padding strategy.
- */
- var Pkcs7 = C_pad.Pkcs7 = {
- /**
- * Pads data using the algorithm defined in PKCS #5/7.
- *
- * @param {WordArray} data The data to pad.
- * @param {number} blockSize The multiple that the data should be padded to.
- *
- * @static
- *
- * @example
- *
- * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
- */
- pad: function (data, blockSize) {
- // Shortcut
- var blockSizeBytes = blockSize * 4;
- // Count padding bytes
- var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
- // Create padding word
- var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes;
- // Create padding
- var paddingWords = [];
- for (var i = 0; i < nPaddingBytes; i += 4) {
- paddingWords.push(paddingWord);
- }
- var padding = WordArray.create(paddingWords, nPaddingBytes);
- // Add padding
- data.concat(padding);
- },
- /**
- * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
- *
- * @param {WordArray} data The data to unpad.
- *
- * @static
- *
- * @example
- *
- * CryptoJS.pad.Pkcs7.unpad(wordArray);
- */
- unpad: function (data) {
- // Get number of padding bytes from last byte
- var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
- // Remove padding
- data.sigBytes -= nPaddingBytes;
- }
- };
- /**
- * Abstract base block cipher template.
- *
- * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
- */
- var BlockCipher = C_lib.BlockCipher = Cipher.extend({
- /**
- * Configuration options.
- *
- * @property {Mode} mode The block mode to use. Default: CBC
- * @property {Padding} padding The padding strategy to use. Default: Pkcs7
- */
- cfg: Cipher.cfg.extend({
- mode: CBC,
- padding: Pkcs7
- }),
- reset: function () {
- // Reset cipher
- Cipher.reset.call(this);
- // Shortcuts
- var cfg = this.cfg;
- var iv = cfg.iv;
- var mode = cfg.mode;
- // Reset block mode
- if (this._xformMode == this._ENC_XFORM_MODE) {
- var modeCreator = mode.createEncryptor;
- } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
- var modeCreator = mode.createDecryptor;
- // Keep at least one block in the buffer for unpadding
- this._minBufferSize = 1;
- }
- this._mode = modeCreator.call(mode, this, iv && iv.words);
- },
- _doProcessBlock: function (words, offset) {
- this._mode.processBlock(words, offset);
- },
- _doFinalize: function () {
- // Shortcut
- var padding = this.cfg.padding;
- // Finalize
- if (this._xformMode == this._ENC_XFORM_MODE) {
- // Pad data
- padding.pad(this._data, this.blockSize);
- // Process final blocks
- var finalProcessedBlocks = this._process(!!'flush');
- } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
- // Process final blocks
- var finalProcessedBlocks = this._process(!!'flush');
- // Unpad data
- padding.unpad(finalProcessedBlocks);
- }
- return finalProcessedBlocks;
- },
- blockSize: 128/32
- });
- /**
- * A collection of cipher parameters.
- *
- * @property {WordArray} ciphertext The raw ciphertext.
- * @property {WordArray} key The key to this ciphertext.
- * @property {WordArray} iv The IV used in the ciphering operation.
- * @property {WordArray} salt The salt used with a key derivation function.
- * @property {Cipher} algorithm The cipher algorithm.
- * @property {Mode} mode The block mode used in the ciphering operation.
- * @property {Padding} padding The padding scheme used in the ciphering operation.
- * @property {number} blockSize The block size of the cipher.
- * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
- */
- var CipherParams = C_lib.CipherParams = Base.extend({
- /**
- * Initializes a newly created cipher params object.
- *
- * @param {Object} cipherParams An object with any of the possible cipher parameters.
- *
- * @example
- *
- * var cipherParams = CryptoJS.lib.CipherParams.create({
- * ciphertext: ciphertextWordArray,
- * key: keyWordArray,
- * iv: ivWordArray,
- * salt: saltWordArray,
- * algorithm: CryptoJS.algo.AES,
- * mode: CryptoJS.mode.CBC,
- * padding: CryptoJS.pad.PKCS7,
- * blockSize: 4,
- * formatter: CryptoJS.format.OpenSSL
- * });
- */
- init: function (cipherParams) {
- this.mixIn(cipherParams);
- },
- /**
- * Converts this cipher params object to a string.
- *
- * @param {Format} formatter (Optional) The formatting strategy to use.
- *
- * @return {string} The stringified cipher params.
- *
- * @throws Error If neither the formatter nor the default formatter is set.
- *
- * @example
- *
- * var string = cipherParams + '';
- * var string = cipherParams.toString();
- * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
- */
- toString: function (formatter) {
- return (formatter || this.formatter).stringify(this);
- }
- });
- /**
- * Format namespace.
- */
- var C_format = C.format = {};
- /**
- * OpenSSL formatting strategy.
- */
- var OpenSSLFormatter = C_format.OpenSSL = {
- /**
- * Converts a cipher params object to an OpenSSL-compatible string.
- *
- * @param {CipherParams} cipherParams The cipher params object.
- *
- * @return {string} The OpenSSL-compatible string.
- *
- * @static
- *
- * @example
- *
- * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
- */
- stringify: function (cipherParams) {
- // Shortcuts
- var ciphertext = cipherParams.ciphertext;
- var salt = cipherParams.salt;
- // Format
- if (salt) {
- var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
- } else {
- var wordArray = ciphertext;
- }
- return wordArray.toString(Base64);
- },
- /**
- * Converts an OpenSSL-compatible string to a cipher params object.
- *
- * @param {string} openSSLStr The OpenSSL-compatible string.
- *
- * @return {CipherParams} The cipher params object.
- *
- * @static
- *
- * @example
- *
- * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
- */
- parse: function (openSSLStr) {
- // Parse base64
- var ciphertext = Base64.parse(openSSLStr);
- // Shortcut
- var ciphertextWords = ciphertext.words;
- // Test for salt
- if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) {
- // Extract salt
- var salt = WordArray.create(ciphertextWords.slice(2, 4));
- // Remove salt from ciphertext
- ciphertextWords.splice(0, 4);
- ciphertext.sigBytes -= 16;
- }
- return CipherParams.create({ ciphertext: ciphertext, salt: salt });
- }
- };
- /**
- * A cipher wrapper that returns ciphertext as a serializable cipher params object.
- */
- var SerializableCipher = C_lib.SerializableCipher = Base.extend({
- /**
- * Configuration options.
- *
- * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
- */
- cfg: Base.extend({
- format: OpenSSLFormatter
- }),
- /**
- * Encrypts a message.
- *
- * @param {Cipher} cipher The cipher algorithm to use.
- * @param {WordArray|string} message The message to encrypt.
- * @param {WordArray} key The key.
- * @param {Object} cfg (Optional) The configuration options to use for this operation.
- *
- * @return {CipherParams} A cipher params object.
- *
- * @static
- *
- * @example
- *
- * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
- * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
- * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
- */
- encrypt: function (cipher, message, key, cfg) {
- // Apply config defaults
- cfg = this.cfg.extend(cfg);
- // Encrypt
- var encryptor = cipher.createEncryptor(key, cfg);
- var ciphertext = encryptor.finalize(message);
- // Shortcut
- var cipherCfg = encryptor.cfg;
- // Create and return serializable cipher params
- return CipherParams.create({
- ciphertext: ciphertext,
- key: key,
- iv: cipherCfg.iv,
- algorithm: cipher,
- mode: cipherCfg.mode,
- padding: cipherCfg.padding,
- blockSize: cipher.blockSize,
- formatter: cfg.format
- });
- },
- /**
- * Decrypts serialized ciphertext.
- *
- * @param {Cipher} cipher The cipher algorithm to use.
- * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
- * @param {WordArray} key The key.
- * @param {Object} cfg (Optional) The configuration options to use for this operation.
- *
- * @return {WordArray} The plaintext.
- *
- * @static
- *
- * @example
- *
- * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
- * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
- */
- decrypt: function (cipher, ciphertext, key, cfg) {
- // Apply config defaults
- cfg = this.cfg.extend(cfg);
- // Convert string to CipherParams
- ciphertext = this._parse(ciphertext, cfg.format);
- // Decrypt
- var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
- return plaintext;
- },
- /**
- * Converts serialized ciphertext to CipherParams,
- * else assumed CipherParams already and returns ciphertext unchanged.
- *
- * @param {CipherParams|string} ciphertext The ciphertext.
- * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
- *
- * @return {CipherParams} The unserialized ciphertext.
- *
- * @static
- *
- * @example
- *
- * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
- */
- _parse: function (ciphertext, format) {
- if (typeof ciphertext == 'string') {
- return format.parse(ciphertext, this);
- } else {
- return ciphertext;
- }
- }
- });
- /**
- * Key derivation function namespace.
- */
- var C_kdf = C.kdf = {};
- /**
- * OpenSSL key derivation function.
- */
- var OpenSSLKdf = C_kdf.OpenSSL = {
- /**
- * Derives a key and IV from a password.
- *
- * @param {string} password The password to derive from.
- * @param {number} keySize The size in words of the key to generate.
- * @param {number} ivSize The size in words of the IV to generate.
- * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
- *
- * @return {CipherParams} A cipher params object with the key, IV, and salt.
- *
- * @static
- *
- * @example
- *
- * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
- * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
- */
- execute: function (password, keySize, ivSize, salt) {
- // Generate random salt
- if (!salt) {
- salt = WordArray.random(64/8);
- }
- // Derive key and IV
- var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
- // Separate key and IV
- var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
- key.sigBytes = keySize * 4;
- // Return params
- return CipherParams.create({ key: key, iv: iv, salt: salt });
- }
- };
- /**
- * A serializable cipher wrapper that derives the key from a password,
- * and returns ciphertext as a serializable cipher params object.
- */
- var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
- /**
- * Configuration options.
- *
- * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
- */
- cfg: SerializableCipher.cfg.extend({
- kdf: OpenSSLKdf
- }),
- /**
- * Encrypts a message using a password.
- *
- * @param {Cipher} cipher The cipher algorithm to use.
- * @param {WordArray|string} message The message to encrypt.
- * @param {string} password The password.
- * @param {Object} cfg (Optional) The configuration options to use for this operation.
- *
- * @return {CipherParams} A cipher params object.
- *
- * @static
- *
- * @example
- *
- * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
- * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
- */
- encrypt: function (cipher, message, password, cfg) {
- // Apply config defaults
- cfg = this.cfg.extend(cfg);
- // Derive key and other params
- var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize);
- // Add IV to config
- cfg.iv = derivedParams.iv;
- // Encrypt
- var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
- // Mix in derived params
- ciphertext.mixIn(derivedParams);
- return ciphertext;
- },
- /**
- * Decrypts serialized ciphertext using a password.
- *
- * @param {Cipher} cipher The cipher algorithm to use.
- * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
- * @param {string} password The password.
- * @param {Object} cfg (Optional) The configuration options to use for this operation.
- *
- * @return {WordArray} The plaintext.
- *
- * @static
- *
- * @example
- *
- * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
- * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
- */
- decrypt: function (cipher, ciphertext, password, cfg) {
- // Apply config defaults
- cfg = this.cfg.extend(cfg);
- // Convert string to CipherParams
- ciphertext = this._parse(ciphertext, cfg.format);
- // Derive key and other params
- var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt);
- // Add IV to config
- cfg.iv = derivedParams.iv;
- // Decrypt
- var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg);
- return plaintext;
- }
- });
- }());
- }));
- },{"./core":18}],18:[function(require,module,exports){
- ;(function (root, factory) {
- if (typeof exports === "object") {
- // CommonJS
- module.exports = exports = factory();
- }
- else if (typeof define === "function" && define.amd) {
- // AMD
- define([], factory);
- }
- else {
- // Global (browser)
- root.CryptoJS = factory();
- }
- }(this, function () {
- /**
- * CryptoJS core components.
- */
- var CryptoJS = CryptoJS || (function (Math, undefined) {
- /*
- * Local polyfil of Object.create
- */
- var create = Object.create || (function () {
- function F() {};
- return function (obj) {
- var subtype;
- F.prototype = obj;
- subtype = new F();
- F.prototype = null;
- return subtype;
- };
- }())
- /**
- * CryptoJS namespace.
- */
- var C = {};
- /**
- * Library namespace.
- */
- var C_lib = C.lib = {};
- /**
- * Base object for prototypal inheritance.
- */
- var Base = C_lib.Base = (function () {
- return {
- /**
- * Creates a new object that inherits from this object.
- *
- * @param {Object} overrides Properties to copy into the new object.
- *
- * @return {Object} The new object.
- *
- * @static
- *
- * @example
- *
- * var MyType = CryptoJS.lib.Base.extend({
- * field: 'value',
- *
- * method: function () {
- * }
- * });
- */
- extend: function (overrides) {
- // Spawn
- var subtype = create(this);
- // Augment
- if (overrides) {
- subtype.mixIn(overrides);
- }
- // Create default initializer
- if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
- subtype.init = function () {
- subtype.$super.init.apply(this, arguments);
- };
- }
- // Initializer's prototype is the subtype object
- subtype.init.prototype = subtype;
- // Reference supertype
- subtype.$super = this;
- return subtype;
- },
- /**
- * Extends this object and runs the init method.
- * Arguments to create() will be passed to init().
- *
- * @return {Object} The new object.
- *
- * @static
- *
- * @example
- *
- * var instance = MyType.create();
- */
- create: function () {
- var instance = this.extend();
- instance.init.apply(instance, arguments);
- return instance;
- },
- /**
- * Initializes a newly created object.
- * Override this method to add some logic when your objects are created.
- *
- * @example
- *
- * var MyType = CryptoJS.lib.Base.extend({
- * init: function () {
- * // ...
- * }
- * });
- */
- init: function () {
- },
- /**
- * Copies properties into this object.
- *
- * @param {Object} properties The properties to mix in.
- *
- * @example
- *
- * MyType.mixIn({
- * field: 'value'
- * });
- */
- mixIn: function (properties) {
- for (var propertyName in properties) {
- if (properties.hasOwnProperty(propertyName)) {
- this[propertyName] = properties[propertyName];
- }
- }
- // IE won't copy toString using the loop above
- if (properties.hasOwnProperty('toString')) {
- this.toString = properties.toString;
- }
- },
- /**
- * Creates a copy of this object.
- *
- * @return {Object} The clone.
- *
- * @example
- *
- * var clone = instance.clone();
- */
- clone: function () {
- return this.init.prototype.extend(this);
- }
- };
- }());
- /**
- * An array of 32-bit words.
- *
- * @property {Array} words The array of 32-bit words.
- * @property {number} sigBytes The number of significant bytes in this word array.
- */
- var WordArray = C_lib.WordArray = Base.extend({
- /**
- * Initializes a newly created word array.
- *
- * @param {Array} words (Optional) An array of 32-bit words.
- * @param {number} sigBytes (Optional) The number of significant bytes in the words.
- *
- * @example
- *
- * var wordArray = CryptoJS.lib.WordArray.create();
- * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
- * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
- */
- init: function (words, sigBytes) {
- words = this.words = words || [];
- if (sigBytes != undefined) {
- this.sigBytes = sigBytes;
- } else {
- this.sigBytes = words.length * 4;
- }
- },
- /**
- * Converts this word array to a string.
- *
- * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
- *
- * @return {string} The stringified word array.
- *
- * @example
- *
- * var string = wordArray + '';
- * var string = wordArray.toString();
- * var string = wordArray.toString(CryptoJS.enc.Utf8);
- */
- toString: function (encoder) {
- return (encoder || Hex).stringify(this);
- },
- /**
- * Concatenates a word array to this word array.
- *
- * @param {WordArray} wordArray The word array to append.
- *
- * @return {WordArray} This word array.
- *
- * @example
- *
- * wordArray1.concat(wordArray2);
- */
- concat: function (wordArray) {
- // Shortcuts
- var thisWords = this.words;
- var thatWords = wordArray.words;
- var thisSigBytes = this.sigBytes;
- var thatSigBytes = wordArray.sigBytes;
- // Clamp excess bits
- this.clamp();
- // Concat
- if (thisSigBytes % 4) {
- // Copy one byte at a time
- for (var i = 0; i < thatSigBytes; i++) {
- var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
- thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
- }
- } else {
- // Copy one word at a time
- for (var i = 0; i < thatSigBytes; i += 4) {
- thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2];
- }
- }
- this.sigBytes += thatSigBytes;
- // Chainable
- return this;
- },
- /**
- * Removes insignificant bits.
- *
- * @example
- *
- * wordArray.clamp();
- */
- clamp: function () {
- // Shortcuts
- var words = this.words;
- var sigBytes = this.sigBytes;
- // Clamp
- words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
- words.length = Math.ceil(sigBytes / 4);
- },
- /**
- * Creates a copy of this word array.
- *
- * @return {WordArray} The clone.
- *
- * @example
- *
- * var clone = wordArray.clone();
- */
- clone: function () {
- var clone = Base.clone.call(this);
- clone.words = this.words.slice(0);
- return clone;
- },
- /**
- * Creates a word array filled with random bytes.
- *
- * @param {number} nBytes The number of random bytes to generate.
- *
- * @return {WordArray} The random word array.
- *
- * @static
- *
- * @example
- *
- * var wordArray = CryptoJS.lib.WordArray.random(16);
- */
- random: function (nBytes) {
- var words = [];
- var r = (function (m_w) {
- var m_w = m_w;
- var m_z = 0x3ade68b1;
- var mask = 0xffffffff;
- return function () {
- m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
- m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
- var result = ((m_z << 0x10) + m_w) & mask;
- result /= 0x100000000;
- result += 0.5;
- return result * (Math.random() > .5 ? 1 : -1);
- }
- });
- for (var i = 0, rcache; i < nBytes; i += 4) {
- var _r = r((rcache || Math.random()) * 0x100000000);
- rcache = _r() * 0x3ade67b7;
- words.push((_r() * 0x100000000) | 0);
- }
- return new WordArray.init(words, nBytes);
- }
- });
- /**
- * Encoder namespace.
- */
- var C_enc = C.enc = {};
- /**
- * Hex encoding strategy.
- */
- var Hex = C_enc.Hex = {
- /**
- * Converts a word array to a hex string.
- *
- * @param {WordArray} wordArray The word array.
- *
- * @return {string} The hex string.
- *
- * @static
- *
- * @example
- *
- * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
- */
- stringify: function (wordArray) {
- // Shortcuts
- var words = wordArray.words;
- var sigBytes = wordArray.sigBytes;
- // Convert
- var hexChars = [];
- for (var i = 0; i < sigBytes; i++) {
- var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
- hexChars.push((bite >>> 4).toString(16));
- hexChars.push((bite & 0x0f).toString(16));
- }
- return hexChars.join('');
- },
- /**
- * Converts a hex string to a word array.
- *
- * @param {string} hexStr The hex string.
- *
- * @return {WordArray} The word array.
- *
- * @static
- *
- * @example
- *
- * var wordArray = CryptoJS.enc.Hex.parse(hexString);
- */
- parse: function (hexStr) {
- // Shortcut
- var hexStrLength = hexStr.length;
- // Convert
- var words = [];
- for (var i = 0; i < hexStrLength; i += 2) {
- words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
- }
- return new WordArray.init(words, hexStrLength / 2);
- }
- };
- /**
- * Latin1 encoding strategy.
- */
- var Latin1 = C_enc.Latin1 = {
- /**
- * Converts a word array to a Latin1 string.
- *
- * @param {WordArray} wordArray The word array.
- *
- * @return {string} The Latin1 string.
- *
- * @static
- *
- * @example
- *
- * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
- */
- stringify: function (wordArray) {
- // Shortcuts
- var words = wordArray.words;
- var sigBytes = wordArray.sigBytes;
- // Convert
- var latin1Chars = [];
- for (var i = 0; i < sigBytes; i++) {
- var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
- latin1Chars.push(String.fromCharCode(bite));
- }
- return latin1Chars.join('');
- },
- /**
- * Converts a Latin1 string to a word array.
- *
- * @param {string} latin1Str The Latin1 string.
- *
- * @return {WordArray} The word array.
- *
- * @static
- *
- * @example
- *
- * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
- */
- parse: function (latin1Str) {
- // Shortcut
- var latin1StrLength = latin1Str.length;
- // Convert
- var words = [];
- for (var i = 0; i < latin1StrLength; i++) {
- words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
- }
- return new WordArray.init(words, latin1StrLength);
- }
- };
- /**
- * UTF-8 encoding strategy.
- */
- var Utf8 = C_enc.Utf8 = {
- /**
- * Converts a word array to a UTF-8 string.
- *
- * @param {WordArray} wordArray The word array.
- *
- * @return {string} The UTF-8 string.
- *
- * @static
- *
- * @example
- *
- * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
- */
- stringify: function (wordArray) {
- try {
- return decodeURIComponent(escape(Latin1.stringify(wordArray)));
- } catch (e) {
- throw new Error('Malformed UTF-8 data');
- }
- },
- /**
- * Converts a UTF-8 string to a word array.
- *
- * @param {string} utf8Str The UTF-8 string.
- *
- * @return {WordArray} The word array.
- *
- * @static
- *
- * @example
- *
- * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
- */
- parse: function (utf8Str) {
- return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
- }
- };
- /**
- * Abstract buffered block algorithm template.
- *
- * The property blockSize must be implemented in a concrete subtype.
- *
- * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
- */
- var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
- /**
- * Resets this block algorithm's data buffer to its initial state.
- *
- * @example
- *
- * bufferedBlockAlgorithm.reset();
- */
- reset: function () {
- // Initial values
- this._data = new WordArray.init();
- this._nDataBytes = 0;
- },
- /**
- * Adds new data to this block algorithm's buffer.
- *
- * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
- *
- * @example
- *
- * bufferedBlockAlgorithm._append('data');
- * bufferedBlockAlgorithm._append(wordArray);
- */
- _append: function (data) {
- // Convert string to WordArray, else assume WordArray already
- if (typeof data == 'string') {
- data = Utf8.parse(data);
- }
- // Append
- this._data.concat(data);
- this._nDataBytes += data.sigBytes;
- },
- /**
- * Processes available data blocks.
- *
- * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
- *
- * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
- *
- * @return {WordArray} The processed data.
- *
- * @example
- *
- * var processedData = bufferedBlockAlgorithm._process();
- * var processedData = bufferedBlockAlgorithm._process(!!'flush');
- */
- _process: function (doFlush) {
- // Shortcuts
- var data = this._data;
- var dataWords = data.words;
- var dataSigBytes = data.sigBytes;
- var blockSize = this.blockSize;
- var blockSizeBytes = blockSize * 4;
- // Count blocks ready
- var nBlocksReady = dataSigBytes / blockSizeBytes;
- if (doFlush) {
- // Round up to include partial blocks
- nBlocksReady = Math.ceil(nBlocksReady);
- } else {
- // Round down to include only full blocks,
- // less the number of blocks that must remain in the buffer
- nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
- }
- // Count words ready
- var nWordsReady = nBlocksReady * blockSize;
- // Count bytes ready
- var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
- // Process blocks
- if (nWordsReady) {
- for (var offset = 0; offset < nWordsReady; offset += blockSize) {
- // Perform concrete-algorithm logic
- this._doProcessBlock(dataWords, offset);
- }
- // Remove processed words
- var processedWords = dataWords.splice(0, nWordsReady);
- data.sigBytes -= nBytesReady;
- }
- // Return processed words
- return new WordArray.init(processedWords, nBytesReady);
- },
- /**
- * Creates a copy of this object.
- *
- * @return {Object} The clone.
- *
- * @example
- *
- * var clone = bufferedBlockAlgorithm.clone();
- */
- clone: function () {
- var clone = Base.clone.call(this);
- clone._data = this._data.clone();
- return clone;
- },
- _minBufferSize: 0
- });
- /**
- * Abstract hasher template.
- *
- * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
- */
- var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
- /**
- * Configuration options.
- */
- cfg: Base.extend(),
- /**
- * Initializes a newly created hasher.
- *
- * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
- *
- * @example
- *
- * var hasher = CryptoJS.algo.SHA256.create();
- */
- init: function (cfg) {
- // Apply config defaults
- this.cfg = this.cfg.extend(cfg);
- // Set initial values
- this.reset();
- },
- /**
- * Resets this hasher to its initial state.
- *
- * @example
- *
- * hasher.reset();
- */
- reset: function () {
- // Reset data buffer
- BufferedBlockAlgorithm.reset.call(this);
- // Perform concrete-hasher logic
- this._doReset();
- },
- /**
- * Updates this hasher with a message.
- *
- * @param {WordArray|string} messageUpdate The message to append.
- *
- * @return {Hasher} This hasher.
- *
- * @example
- *
- * hasher.update('message');
- * hasher.update(wordArray);
- */
- update: function (messageUpdate) {
- // Append
- this._append(messageUpdate);
- // Update the hash
- this._process();
- // Chainable
- return this;
- },
- /**
- * Finalizes the hash computation.
- * Note that the finalize operation is effectively a destructive, read-once operation.
- *
- * @param {WordArray|string} messageUpdate (Optional) A final message update.
- *
- * @return {WordArray} The hash.
- *
- * @example
- *
- * var hash = hasher.finalize();
- * var hash = hasher.finalize('message');
- * var hash = hasher.finalize(wordArray);
- */
- finalize: function (messageUpdate) {
- // Final message update
- if (messageUpdate) {
- this._append(messageUpdate);
- }
- // Perform concrete-hasher logic
- var hash = this._doFinalize();
- return hash;
- },
- blockSize: 512/32,
- /**
- * Creates a shortcut function to a hasher's object interface.
- *
- * @param {Hasher} hasher The hasher to create a helper for.
- *
- * @return {Function} The shortcut function.
- *
- * @static
- *
- * @example
- *
- * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
- */
- _createHelper: function (hasher) {
- return function (message, cfg) {
- return new hasher.init(cfg).finalize(message);
- };
- },
- /**
- * Creates a shortcut function to the HMAC's object interface.
- *
- * @param {Hasher} hasher The hasher to use in this HMAC helper.
- *
- * @return {Function} The shortcut function.
- *
- * @static
- *
- * @example
- *
- * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
- */
- _createHmacHelper: function (hasher) {
- return function (message, key) {
- return new C_algo.HMAC.init(hasher, key).finalize(message);
- };
- }
- });
- /**
- * Algorithm namespace.
- */
- var C_algo = C.algo = {};
- return C;
- }(Math));
- return CryptoJS;
- }));
- },{}],19:[function(require,module,exports){
- ;(function (root, factory) {
- if (typeof exports === "object") {
- // CommonJS
- module.exports = exports = factory(require("./core"));
- }
- else if (typeof define === "function" && define.amd) {
- // AMD
- define(["./core"], factory);
- }
- else {
- // Global (browser)
- factory(root.CryptoJS);
- }
- }(this, function (CryptoJS) {
- (function () {
- // Shortcuts
- var C = CryptoJS;
- var C_lib = C.lib;
- var WordArray = C_lib.WordArray;
- var C_enc = C.enc;
- /**
- * Base64 encoding strategy.
- */
- var Base64 = C_enc.Base64 = {
- /**
- * Converts a word array to a Base64 string.
- *
- * @param {WordArray} wordArray The word array.
- *
- * @return {string} The Base64 string.
- *
- * @static
- *
- * @example
- *
- * var base64String = CryptoJS.enc.Base64.stringify(wordArray);
- */
- stringify: function (wordArray) {
- // Shortcuts
- var words = wordArray.words;
- var sigBytes = wordArray.sigBytes;
- var map = this._map;
- // Clamp excess bits
- wordArray.clamp();
- // Convert
- var base64Chars = [];
- for (var i = 0; i < sigBytes; i += 3) {
- var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
- var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
- var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
- var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
- for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
- base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
- }
- }
- // Add padding
- var paddingChar = map.charAt(64);
- if (paddingChar) {
- while (base64Chars.length % 4) {
- base64Chars.push(paddingChar);
- }
- }
- return base64Chars.join('');
- },
- /**
- * Converts a Base64 string to a word array.
- *
- * @param {string} base64Str The Base64 string.
- *
- * @return {WordArray} The word array.
- *
- * @static
- *
- * @example
- *
- * var wordArray = CryptoJS.enc.Base64.parse(base64String);
- */
- parse: function (base64Str) {
- // Shortcuts
- var base64StrLength = base64Str.length;
- var map = this._map;
- var reverseMap = this._reverseMap;
- if (!reverseMap) {
- reverseMap = this._reverseMap = [];
- for (var j = 0; j < map.length; j++) {
- reverseMap[map.charCodeAt(j)] = j;
- }
- }
- // Ignore padding
- var paddingChar = map.charAt(64);
- if (paddingChar) {
- var paddingIndex = base64Str.indexOf(paddingChar);
- if (paddingIndex !== -1) {
- base64StrLength = paddingIndex;
- }
- }
- // Convert
- return parseLoop(base64Str, base64StrLength, reverseMap);
- },
- _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
- };
- function parseLoop(base64Str, base64StrLength, reverseMap) {
- var words = [];
- var nBytes = 0;
- for (var i = 0; i < base64StrLength; i++) {
- if (i % 4) {
- var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2);
- var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2);
- words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8);
- nBytes++;
- }
- }
- return WordArray.create(words, nBytes);
- }
- }());
- return CryptoJS.enc.Base64;
- }));
- },{"./core":18}],20:[function(require,module,exports){
- ;(function (root, factory) {
- if (typeof exports === "object") {
- // CommonJS
- module.exports = exports = factory(require("./core"));
- }
- else if (typeof define === "function" && define.amd) {
- // AMD
- define(["./core"], factory);
- }
- else {
- // Global (browser)
- factory(root.CryptoJS);
- }
- }(this, function (CryptoJS) {
- return CryptoJS.enc.Hex;
- }));
- },{"./core":18}],21:[function(require,module,exports){
- ;(function (root, factory) {
- if (typeof exports === "object") {
- // CommonJS
- module.exports = exports = factory(require("./core"));
- }
- else if (typeof define === "function" && define.amd) {
- // AMD
- define(["./core"], factory);
- }
- else {
- // Global (browser)
- factory(root.CryptoJS);
- }
- }(this, function (CryptoJS) {
- return CryptoJS.enc.Latin1;
- }));
- },{"./core":18}],22:[function(require,module,exports){
- ;(function (root, factory) {
- if (typeof exports === "object") {
- // CommonJS
- module.exports = exports = factory(require("./core"));
- }
- else if (typeof define === "function" && define.amd) {
- // AMD
- define(["./core"], factory);
- }
- else {
- // Global (browser)
- factory(root.CryptoJS);
- }
- }(this, function (CryptoJS) {
- return CryptoJS.enc.Utf8;
- }));
- },{"./core":18}],23:[function(require,module,exports){
- ;(function (root, factory, undef) {
- if (typeof exports === "object") {
- // CommonJS
- module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac"));
- }
- else if (typeof define === "function" && define.amd) {
- // AMD
- define(["./core", "./sha1", "./hmac"], factory);
- }
- else {
- // Global (browser)
- factory(root.CryptoJS);
- }
- }(this, function (CryptoJS) {
- (function () {
- // Shortcuts
- var C = CryptoJS;
- var C_lib = C.lib;
- var Base = C_lib.Base;
- var WordArray = C_lib.WordArray;
- var C_algo = C.algo;
- var MD5 = C_algo.MD5;
- /**
- * This key derivation function is meant to conform with EVP_BytesToKey.
- * www.openssl.org/docs/crypto/EVP_BytesToKey.html
- */
- var EvpKDF = C_algo.EvpKDF = Base.extend({
- /**
- * Configuration options.
- *
- * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
- * @property {Hasher} hasher The hash algorithm to use. Default: MD5
- * @property {number} iterations The number of iterations to perform. Default: 1
- */
- cfg: Base.extend({
- keySize: 128/32,
- hasher: MD5,
- iterations: 1
- }),
- /**
- * Initializes a newly created key derivation function.
- *
- * @param {Object} cfg (Optional) The configuration options to use for the derivation.
- *
- * @example
- *
- * var kdf = CryptoJS.algo.EvpKDF.create();
- * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
- * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
- */
- init: function (cfg) {
- this.cfg = this.cfg.extend(cfg);
- },
- /**
- * Derives a key from a password.
- *
- * @param {WordArray|string} password The password.
- * @param {WordArray|string} salt A salt.
- *
- * @return {WordArray} The derived key.
- *
- * @example
- *
- * var key = kdf.compute(password, salt);
- */
- compute: function (password, salt) {
- // Shortcut
- var cfg = this.cfg;
- // Init hasher
- var hasher = cfg.hasher.create();
- // Initial values
- var derivedKey = WordArray.create();
- // Shortcuts
- var derivedKeyWords = derivedKey.words;
- var keySize = cfg.keySize;
- var iterations = cfg.iterations;
- // Generate key
- while (derivedKeyWords.length < keySize) {
- if (block) {
- hasher.update(block);
- }
- var block = hasher.update(password).finalize(salt);
- hasher.reset();
- // Iterations
- for (var i = 1; i < iterations; i++) {
- block = hasher.finalize(block);
- hasher.reset();
- }
- derivedKey.concat(block);
- }
- derivedKey.sigBytes = keySize * 4;
- return derivedKey;
- }
- });
- /**
- * Derives a key from a password.
- *
- * @param {WordArray|string} password The password.
- * @param {WordArray|string} salt A salt.
- * @param {Object} cfg (Optional) The configuration options to use for this computation.
- *
- * @return {WordArray} The derived key.
- *
- * @static
- *
- * @example
- *
- * var key = CryptoJS.EvpKDF(password, salt);
- * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
- * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
- */
- C.EvpKDF = function (password, salt, cfg) {
- return EvpKDF.create(cfg).compute(password, salt);
- };
- }());
- return CryptoJS.EvpKDF;
- }));
- },{"./core":18,"./hmac":25,"./sha1":27}],24:[function(require,module,exports){
- ;(function (root, factory, undef) {
- if (typeof exports === "object") {
- // CommonJS
- module.exports = exports = factory(require("./core"), require("./sha256"), require("./hmac"));
- }
- else if (typeof define === "function" && define.amd) {
- // AMD
- define(["./core", "./sha256", "./hmac"], factory);
- }
- else {
- // Global (browser)
- factory(root.CryptoJS);
- }
- }(this, function (CryptoJS) {
- return CryptoJS.HmacSHA256;
- }));
- },{"./core":18,"./hmac":25,"./sha256":28}],25:[function(require,module,exports){
- ;(function (root, factory) {
- if (typeof exports === "object") {
- // CommonJS
- module.exports = exports = factory(require("./core"));
- }
- else if (typeof define === "function" && define.amd) {
- // AMD
- define(["./core"], factory);
- }
- else {
- // Global (browser)
- factory(root.CryptoJS);
- }
- }(this, function (CryptoJS) {
- (function () {
- // Shortcuts
- var C = CryptoJS;
- var C_lib = C.lib;
- var Base = C_lib.Base;
- var C_enc = C.enc;
- var Utf8 = C_enc.Utf8;
- var C_algo = C.algo;
- /**
- * HMAC algorithm.
- */
- var HMAC = C_algo.HMAC = Base.extend({
- /**
- * Initializes a newly created HMAC.
- *
- * @param {Hasher} hasher The hash algorithm to use.
- * @param {WordArray|string} key The secret key.
- *
- * @example
- *
- * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
- */
- init: function (hasher, key) {
- // Init hasher
- hasher = this._hasher = new hasher.init();
- // Convert string to WordArray, else assume WordArray already
- if (typeof key == 'string') {
- key = Utf8.parse(key);
- }
- // Shortcuts
- var hasherBlockSize = hasher.blockSize;
- var hasherBlockSizeBytes = hasherBlockSize * 4;
- // Allow arbitrary length keys
- if (key.sigBytes > hasherBlockSizeBytes) {
- key = hasher.finalize(key);
- }
- // Clamp excess bits
- key.clamp();
- // Clone key for inner and outer pads
- var oKey = this._oKey = key.clone();
- var iKey = this._iKey = key.clone();
- // Shortcuts
- var oKeyWords = oKey.words;
- var iKeyWords = iKey.words;
- // XOR keys with pad constants
- for (var i = 0; i < hasherBlockSize; i++) {
- oKeyWords[i] ^= 0x5c5c5c5c;
- iKeyWords[i] ^= 0x36363636;
- }
- oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
- // Set initial values
- this.reset();
- },
- /**
- * Resets this HMAC to its initial state.
- *
- * @example
- *
- * hmacHasher.reset();
- */
- reset: function () {
- // Shortcut
- var hasher = this._hasher;
- // Reset
- hasher.reset();
- hasher.update(this._iKey);
- },
- /**
- * Updates this HMAC with a message.
- *
- * @param {WordArray|string} messageUpdate The message to append.
- *
- * @return {HMAC} This HMAC instance.
- *
- * @example
- *
- * hmacHasher.update('message');
- * hmacHasher.update(wordArray);
- */
- update: function (messageUpdate) {
- this._hasher.update(messageUpdate);
- // Chainable
- return this;
- },
- /**
- * Finalizes the HMAC computation.
- * Note that the finalize operation is effectively a destructive, read-once operation.
- *
- * @param {WordArray|string} messageUpdate (Optional) A final message update.
- *
- * @return {WordArray} The HMAC.
- *
- * @example
- *
- * var hmac = hmacHasher.finalize();
- * var hmac = hmacHasher.finalize('message');
- * var hmac = hmacHasher.finalize(wordArray);
- */
- finalize: function (messageUpdate) {
- // Shortcut
- var hasher = this._hasher;
- // Compute HMAC
- var innerHash = hasher.finalize(messageUpdate);
- hasher.reset();
- var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
- return hmac;
- }
- });
- }());
- }));
- },{"./core":18}],26:[function(require,module,exports){
- ;(function (root, factory) {
- if (typeof exports === "object") {
- // CommonJS
- module.exports = exports = factory(require("./core"));
- }
- else if (typeof define === "function" && define.amd) {
- // AMD
- define(["./core"], factory);
- }
- else {
- // Global (browser)
- factory(root.CryptoJS);
- }
- }(this, function (CryptoJS) {
- (function (Math) {
- // Shortcuts
- var C = CryptoJS;
- var C_lib = C.lib;
- var WordArray = C_lib.WordArray;
- var Hasher = C_lib.Hasher;
- var C_algo = C.algo;
- // Constants table
- var T = [];
- // Compute constants
- (function () {
- for (var i = 0; i < 64; i++) {
- T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
- }
- }());
- /**
- * MD5 hash algorithm.
- */
- var MD5 = C_algo.MD5 = Hasher.extend({
- _doReset: function () {
- this._hash = new WordArray.init([
- 0x67452301, 0xefcdab89,
- 0x98badcfe, 0x10325476
- ]);
- },
- _doProcessBlock: function (M, offset) {
- // Swap endian
- for (var i = 0; i < 16; i++) {
- // Shortcuts
- var offset_i = offset + i;
- var M_offset_i = M[offset_i];
- M[offset_i] = (
- (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
- (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
- );
- }
- // Shortcuts
- var H = this._hash.words;
- var M_offset_0 = M[offset + 0];
- var M_offset_1 = M[offset + 1];
- var M_offset_2 = M[offset + 2];
- var M_offset_3 = M[offset + 3];
- var M_offset_4 = M[offset + 4];
- var M_offset_5 = M[offset + 5];
- var M_offset_6 = M[offset + 6];
- var M_offset_7 = M[offset + 7];
- var M_offset_8 = M[offset + 8];
- var M_offset_9 = M[offset + 9];
- var M_offset_10 = M[offset + 10];
- var M_offset_11 = M[offset + 11];
- var M_offset_12 = M[offset + 12];
- var M_offset_13 = M[offset + 13];
- var M_offset_14 = M[offset + 14];
- var M_offset_15 = M[offset + 15];
- // Working varialbes
- var a = H[0];
- var b = H[1];
- var c = H[2];
- var d = H[3];
- // Computation
- a = FF(a, b, c, d, M_offset_0, 7, T[0]);
- d = FF(d, a, b, c, M_offset_1, 12, T[1]);
- c = FF(c, d, a, b, M_offset_2, 17, T[2]);
- b = FF(b, c, d, a, M_offset_3, 22, T[3]);
- a = FF(a, b, c, d, M_offset_4, 7, T[4]);
- d = FF(d, a, b, c, M_offset_5, 12, T[5]);
- c = FF(c, d, a, b, M_offset_6, 17, T[6]);
- b = FF(b, c, d, a, M_offset_7, 22, T[7]);
- a = FF(a, b, c, d, M_offset_8, 7, T[8]);
- d = FF(d, a, b, c, M_offset_9, 12, T[9]);
- c = FF(c, d, a, b, M_offset_10, 17, T[10]);
- b = FF(b, c, d, a, M_offset_11, 22, T[11]);
- a = FF(a, b, c, d, M_offset_12, 7, T[12]);
- d = FF(d, a, b, c, M_offset_13, 12, T[13]);
- c = FF(c, d, a, b, M_offset_14, 17, T[14]);
- b = FF(b, c, d, a, M_offset_15, 22, T[15]);
- a = GG(a, b, c, d, M_offset_1, 5, T[16]);
- d = GG(d, a, b, c, M_offset_6, 9, T[17]);
- c = GG(c, d, a, b, M_offset_11, 14, T[18]);
- b = GG(b, c, d, a, M_offset_0, 20, T[19]);
- a = GG(a, b, c, d, M_offset_5, 5, T[20]);
- d = GG(d, a, b, c, M_offset_10, 9, T[21]);
- c = GG(c, d, a, b, M_offset_15, 14, T[22]);
- b = GG(b, c, d, a, M_offset_4, 20, T[23]);
- a = GG(a, b, c, d, M_offset_9, 5, T[24]);
- d = GG(d, a, b, c, M_offset_14, 9, T[25]);
- c = GG(c, d, a, b, M_offset_3, 14, T[26]);
- b = GG(b, c, d, a, M_offset_8, 20, T[27]);
- a = GG(a, b, c, d, M_offset_13, 5, T[28]);
- d = GG(d, a, b, c, M_offset_2, 9, T[29]);
- c = GG(c, d, a, b, M_offset_7, 14, T[30]);
- b = GG(b, c, d, a, M_offset_12, 20, T[31]);
- a = HH(a, b, c, d, M_offset_5, 4, T[32]);
- d = HH(d, a, b, c, M_offset_8, 11, T[33]);
- c = HH(c, d, a, b, M_offset_11, 16, T[34]);
- b = HH(b, c, d, a, M_offset_14, 23, T[35]);
- a = HH(a, b, c, d, M_offset_1, 4, T[36]);
- d = HH(d, a, b, c, M_offset_4, 11, T[37]);
- c = HH(c, d, a, b, M_offset_7, 16, T[38]);
- b = HH(b, c, d, a, M_offset_10, 23, T[39]);
- a = HH(a, b, c, d, M_offset_13, 4, T[40]);
- d = HH(d, a, b, c, M_offset_0, 11, T[41]);
- c = HH(c, d, a, b, M_offset_3, 16, T[42]);
- b = HH(b, c, d, a, M_offset_6, 23, T[43]);
- a = HH(a, b, c, d, M_offset_9, 4, T[44]);
- d = HH(d, a, b, c, M_offset_12, 11, T[45]);
- c = HH(c, d, a, b, M_offset_15, 16, T[46]);
- b = HH(b, c, d, a, M_offset_2, 23, T[47]);
- a = II(a, b, c, d, M_offset_0, 6, T[48]);
- d = II(d, a, b, c, M_offset_7, 10, T[49]);
- c = II(c, d, a, b, M_offset_14, 15, T[50]);
- b = II(b, c, d, a, M_offset_5, 21, T[51]);
- a = II(a, b, c, d, M_offset_12, 6, T[52]);
- d = II(d, a, b, c, M_offset_3, 10, T[53]);
- c = II(c, d, a, b, M_offset_10, 15, T[54]);
- b = II(b, c, d, a, M_offset_1, 21, T[55]);
- a = II(a, b, c, d, M_offset_8, 6, T[56]);
- d = II(d, a, b, c, M_offset_15, 10, T[57]);
- c = II(c, d, a, b, M_offset_6, 15, T[58]);
- b = II(b, c, d, a, M_offset_13, 21, T[59]);
- a = II(a, b, c, d, M_offset_4, 6, T[60]);
- d = II(d, a, b, c, M_offset_11, 10, T[61]);
- c = II(c, d, a, b, M_offset_2, 15, T[62]);
- b = II(b, c, d, a, M_offset_9, 21, T[63]);
- // Intermediate hash value
- H[0] = (H[0] + a) | 0;
- H[1] = (H[1] + b) | 0;
- H[2] = (H[2] + c) | 0;
- H[3] = (H[3] + d) | 0;
- },
- _doFinalize: function () {
- // Shortcuts
- var data = this._data;
- var dataWords = data.words;
- var nBitsTotal = this._nDataBytes * 8;
- var nBitsLeft = data.sigBytes * 8;
- // Add padding
- dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
- var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
- var nBitsTotalL = nBitsTotal;
- dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
- (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
- (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
- );
- dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
- (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
- (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
- );
- data.sigBytes = (dataWords.length + 1) * 4;
- // Hash final blocks
- this._process();
- // Shortcuts
- var hash = this._hash;
- var H = hash.words;
- // Swap endian
- for (var i = 0; i < 4; i++) {
- // Shortcut
- var H_i = H[i];
- H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
- (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
- }
- // Return final computed hash
- return hash;
- },
- clone: function () {
- var clone = Hasher.clone.call(this);
- clone._hash = this._hash.clone();
- return clone;
- }
- });
- function FF(a, b, c, d, x, s, t) {
- var n = a + ((b & c) | (~b & d)) + x + t;
- return ((n << s) | (n >>> (32 - s))) + b;
- }
- function GG(a, b, c, d, x, s, t) {
- var n = a + ((b & d) | (c & ~d)) + x + t;
- return ((n << s) | (n >>> (32 - s))) + b;
- }
- function HH(a, b, c, d, x, s, t) {
- var n = a + (b ^ c ^ d) + x + t;
- return ((n << s) | (n >>> (32 - s))) + b;
- }
- function II(a, b, c, d, x, s, t) {
- var n = a + (c ^ (b | ~d)) + x + t;
- return ((n << s) | (n >>> (32 - s))) + b;
- }
- /**
- * Shortcut function to the hasher's object interface.
- *
- * @param {WordArray|string} message The message to hash.
- *
- * @return {WordArray} The hash.
- *
- * @static
- *
- * @example
- *
- * var hash = CryptoJS.MD5('message');
- * var hash = CryptoJS.MD5(wordArray);
- */
- C.MD5 = Hasher._createHelper(MD5);
- /**
- * Shortcut function to the HMAC's object interface.
- *
- * @param {WordArray|string} message The message to hash.
- * @param {WordArray|string} key The secret key.
- *
- * @return {WordArray} The HMAC.
- *
- * @static
- *
- * @example
- *
- * var hmac = CryptoJS.HmacMD5(message, key);
- */
- C.HmacMD5 = Hasher._createHmacHelper(MD5);
- }(Math));
- return CryptoJS.MD5;
- }));
- },{"./core":18}],27:[function(require,module,exports){
- ;(function (root, factory) {
- if (typeof exports === "object") {
- // CommonJS
- module.exports = exports = factory(require("./core"));
- }
- else if (typeof define === "function" && define.amd) {
- // AMD
- define(["./core"], factory);
- }
- else {
- // Global (browser)
- factory(root.CryptoJS);
- }
- }(this, function (CryptoJS) {
- (function () {
- // Shortcuts
- var C = CryptoJS;
- var C_lib = C.lib;
- var WordArray = C_lib.WordArray;
- var Hasher = C_lib.Hasher;
- var C_algo = C.algo;
- // Reusable object
- var W = [];
- /**
- * SHA-1 hash algorithm.
- */
- var SHA1 = C_algo.SHA1 = Hasher.extend({
- _doReset: function () {
- this._hash = new WordArray.init([
- 0x67452301, 0xefcdab89,
- 0x98badcfe, 0x10325476,
- 0xc3d2e1f0
- ]);
- },
- _doProcessBlock: function (M, offset) {
- // Shortcut
- var H = this._hash.words;
- // Working variables
- var a = H[0];
- var b = H[1];
- var c = H[2];
- var d = H[3];
- var e = H[4];
- // Computation
- for (var i = 0; i < 80; i++) {
- if (i < 16) {
- W[i] = M[offset + i] | 0;
- } else {
- var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
- W[i] = (n << 1) | (n >>> 31);
- }
- var t = ((a << 5) | (a >>> 27)) + e + W[i];
- if (i < 20) {
- t += ((b & c) | (~b & d)) + 0x5a827999;
- } else if (i < 40) {
- t += (b ^ c ^ d) + 0x6ed9eba1;
- } else if (i < 60) {
- t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
- } else /* if (i < 80) */ {
- t += (b ^ c ^ d) - 0x359d3e2a;
- }
- e = d;
- d = c;
- c = (b << 30) | (b >>> 2);
- b = a;
- a = t;
- }
- // Intermediate hash value
- H[0] = (H[0] + a) | 0;
- H[1] = (H[1] + b) | 0;
- H[2] = (H[2] + c) | 0;
- H[3] = (H[3] + d) | 0;
- H[4] = (H[4] + e) | 0;
- },
- _doFinalize: function () {
- // Shortcuts
- var data = this._data;
- var dataWords = data.words;
- var nBitsTotal = this._nDataBytes * 8;
- var nBitsLeft = data.sigBytes * 8;
- // Add padding
- dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
- dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
- dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
- data.sigBytes = dataWords.length * 4;
- // Hash final blocks
- this._process();
- // Return final computed hash
- return this._hash;
- },
- clone: function () {
- var clone = Hasher.clone.call(this);
- clone._hash = this._hash.clone();
- return clone;
- }
- });
- /**
- * Shortcut function to the hasher's object interface.
- *
- * @param {WordArray|string} message The message to hash.
- *
- * @return {WordArray} The hash.
- *
- * @static
- *
- * @example
- *
- * var hash = CryptoJS.SHA1('message');
- * var hash = CryptoJS.SHA1(wordArray);
- */
- C.SHA1 = Hasher._createHelper(SHA1);
- /**
- * Shortcut function to the HMAC's object interface.
- *
- * @param {WordArray|string} message The message to hash.
- * @param {WordArray|string} key The secret key.
- *
- * @return {WordArray} The HMAC.
- *
- * @static
- *
- * @example
- *
- * var hmac = CryptoJS.HmacSHA1(message, key);
- */
- C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
- }());
- return CryptoJS.SHA1;
- }));
- },{"./core":18}],28:[function(require,module,exports){
- ;(function (root, factory) {
- if (typeof exports === "object") {
- // CommonJS
- module.exports = exports = factory(require("./core"));
- }
- else if (typeof define === "function" && define.amd) {
- // AMD
- define(["./core"], factory);
- }
- else {
- // Global (browser)
- factory(root.CryptoJS);
- }
- }(this, function (CryptoJS) {
- (function (Math) {
- // Shortcuts
- var C = CryptoJS;
- var C_lib = C.lib;
- var WordArray = C_lib.WordArray;
- var Hasher = C_lib.Hasher;
- var C_algo = C.algo;
- // Initialization and round constants tables
- var H = [];
- var K = [];
- // Compute constants
- (function () {
- function isPrime(n) {
- var sqrtN = Math.sqrt(n);
- for (var factor = 2; factor <= sqrtN; factor++) {
- if (!(n % factor)) {
- return false;
- }
- }
- return true;
- }
- function getFractionalBits(n) {
- return ((n - (n | 0)) * 0x100000000) | 0;
- }
- var n = 2;
- var nPrime = 0;
- while (nPrime < 64) {
- if (isPrime(n)) {
- if (nPrime < 8) {
- H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
- }
- K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
- nPrime++;
- }
- n++;
- }
- }());
- // Reusable object
- var W = [];
- /**
- * SHA-256 hash algorithm.
- */
- var SHA256 = C_algo.SHA256 = Hasher.extend({
- _doReset: function () {
- this._hash = new WordArray.init(H.slice(0));
- },
- _doProcessBlock: function (M, offset) {
- // Shortcut
- var H = this._hash.words;
- // Working variables
- var a = H[0];
- var b = H[1];
- var c = H[2];
- var d = H[3];
- var e = H[4];
- var f = H[5];
- var g = H[6];
- var h = H[7];
- // Computation
- for (var i = 0; i < 64; i++) {
- if (i < 16) {
- W[i] = M[offset + i] | 0;
- } else {
- var gamma0x = W[i - 15];
- var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^
- ((gamma0x << 14) | (gamma0x >>> 18)) ^
- (gamma0x >>> 3);
- var gamma1x = W[i - 2];
- var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^
- ((gamma1x << 13) | (gamma1x >>> 19)) ^
- (gamma1x >>> 10);
- W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
- }
- var ch = (e & f) ^ (~e & g);
- var maj = (a & b) ^ (a & c) ^ (b & c);
- var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22));
- var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25));
- var t1 = h + sigma1 + ch + K[i] + W[i];
- var t2 = sigma0 + maj;
- h = g;
- g = f;
- f = e;
- e = (d + t1) | 0;
- d = c;
- c = b;
- b = a;
- a = (t1 + t2) | 0;
- }
- // Intermediate hash value
- H[0] = (H[0] + a) | 0;
- H[1] = (H[1] + b) | 0;
- H[2] = (H[2] + c) | 0;
- H[3] = (H[3] + d) | 0;
- H[4] = (H[4] + e) | 0;
- H[5] = (H[5] + f) | 0;
- H[6] = (H[6] + g) | 0;
- H[7] = (H[7] + h) | 0;
- },
- _doFinalize: function () {
- // Shortcuts
- var data = this._data;
- var dataWords = data.words;
- var nBitsTotal = this._nDataBytes * 8;
- var nBitsLeft = data.sigBytes * 8;
- // Add padding
- dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
- dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
- dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
- data.sigBytes = dataWords.length * 4;
- // Hash final blocks
- this._process();
- // Return final computed hash
- return this._hash;
- },
- clone: function () {
- var clone = Hasher.clone.call(this);
- clone._hash = this._hash.clone();
- return clone;
- }
- });
- /**
- * Shortcut function to the hasher's object interface.
- *
- * @param {WordArray|string} message The message to hash.
- *
- * @return {WordArray} The hash.
- *
- * @static
- *
- * @example
- *
- * var hash = CryptoJS.SHA256('message');
- * var hash = CryptoJS.SHA256(wordArray);
- */
- C.SHA256 = Hasher._createHelper(SHA256);
- /**
- * Shortcut function to the HMAC's object interface.
- *
- * @param {WordArray|string} message The message to hash.
- * @param {WordArray|string} key The secret key.
- *
- * @return {WordArray} The HMAC.
- *
- * @static
- *
- * @example
- *
- * var hmac = CryptoJS.HmacSHA256(message, key);
- */
- C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
- }(Math));
- return CryptoJS.SHA256;
- }));
- },{"./core":18}],29:[function(require,module,exports){
- 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){
- // UTILITY
- var util = require('util');
- var Buffer = require("buffer").Buffer;
- var pSlice = Array.prototype.slice;
- function objectKeys(object) {
- if (Object.keys) return Object.keys(object);
- var result = [];
- for (var name in object) {
- if (Object.prototype.hasOwnProperty.call(object, name)) {
- result.push(name);
- }
- }
- return result;
- }
- // 1. The assert module provides functions that throw
- // AssertionError's when particular conditions are not met. The
- // assert module must conform to the following interface.
- var assert = module.exports = ok;
- // 2. The AssertionError is defined in assert.
- // new assert.AssertionError({ message: message,
- // actual: actual,
- // expected: expected })
- assert.AssertionError = function AssertionError(options) {
- this.name = 'AssertionError';
- this.message = options.message;
- this.actual = options.actual;
- this.expected = options.expected;
- this.operator = options.operator;
- var stackStartFunction = options.stackStartFunction || fail;
- if (Error.captureStackTrace) {
- Error.captureStackTrace(this, stackStartFunction);
- }
- };
- util.inherits(assert.AssertionError, Error);
- function replacer(key, value) {
- if (value === undefined) {
- return '' + value;
- }
- if (typeof value === 'number' && (isNaN(value) || !isFinite(value))) {
- return value.toString();
- }
- if (typeof value === 'function' || value instanceof RegExp) {
- return value.toString();
- }
- return value;
- }
- function truncate(s, n) {
- if (typeof s == 'string') {
- return s.length < n ? s : s.slice(0, n);
- } else {
- return s;
- }
- }
- assert.AssertionError.prototype.toString = function() {
- if (this.message) {
- return [this.name + ':', this.message].join(' ');
- } else {
- return [
- this.name + ':',
- truncate(JSON.stringify(this.actual, replacer), 128),
- this.operator,
- truncate(JSON.stringify(this.expected, replacer), 128)
- ].join(' ');
- }
- };
- // assert.AssertionError instanceof Error
- assert.AssertionError.__proto__ = Error.prototype;
- // At present only the three keys mentioned above are used and
- // understood by the spec. Implementations or sub modules can pass
- // other keys to the AssertionError's constructor - they will be
- // ignored.
- // 3. All of the following functions must throw an AssertionError
- // when a corresponding condition is not met, with a message that
- // may be undefined if not provided. All assertion methods provide
- // both the actual and expected values to the assertion error for
- // display purposes.
- function fail(actual, expected, message, operator, stackStartFunction) {
- throw new assert.AssertionError({
- message: message,
- actual: actual,
- expected: expected,
- operator: operator,
- stackStartFunction: stackStartFunction
- });
- }
- // EXTENSION! allows for well behaved errors defined elsewhere.
- assert.fail = fail;
- // 4. Pure assertion tests whether a value is truthy, as determined
- // by !!guard.
- // assert.ok(guard, message_opt);
- // This statement is equivalent to assert.equal(true, guard,
- // message_opt);. To test strictly for the value true, use
- // assert.strictEqual(true, guard, message_opt);.
- function ok(value, message) {
- if (!!!value) fail(value, true, message, '==', assert.ok);
- }
- assert.ok = ok;
- // 5. The equality assertion tests shallow, coercive equality with
- // ==.
- // assert.equal(actual, expected, message_opt);
- assert.equal = function equal(actual, expected, message) {
- if (actual != expected) fail(actual, expected, message, '==', assert.equal);
- };
- // 6. The non-equality assertion tests for whether two objects are not equal
- // with != assert.notEqual(actual, expected, message_opt);
- assert.notEqual = function notEqual(actual, expected, message) {
- if (actual == expected) {
- fail(actual, expected, message, '!=', assert.notEqual);
- }
- };
- // 7. The equivalence assertion tests a deep equality relation.
- // assert.deepEqual(actual, expected, message_opt);
- assert.deepEqual = function deepEqual(actual, expected, message) {
- if (!_deepEqual(actual, expected)) {
- fail(actual, expected, message, 'deepEqual', assert.deepEqual);
- }
- };
- function _deepEqual(actual, expected) {
- // 7.1. All identical values are equivalent, as determined by ===.
- if (actual === expected) {
- return true;
- } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
- if (actual.length != expected.length) return false;
- for (var i = 0; i < actual.length; i++) {
- if (actual[i] !== expected[i]) return false;
- }
- return true;
- // 7.2. If the expected value is a Date object, the actual value is
- // equivalent if it is also a Date object that refers to the same time.
- } else if (actual instanceof Date && expected instanceof Date) {
- return actual.getTime() === expected.getTime();
- // 7.3. Other pairs that do not both pass typeof value == 'object',
- // equivalence is determined by ==.
- } else if (typeof actual != 'object' && typeof expected != 'object') {
- return actual == expected;
- // 7.4. For all other Object pairs, including Array objects, equivalence is
- // determined by having the same number of owned properties (as verified
- // with Object.prototype.hasOwnProperty.call), the same set of keys
- // (although not necessarily the same order), equivalent values for every
- // corresponding key, and an identical 'prototype' property. Note: this
- // accounts for both named and indexed properties on Arrays.
- } else {
- return objEquiv(actual, expected);
- }
- }
- function isUndefinedOrNull(value) {
- return value === null || value === undefined;
- }
- function isArguments(object) {
- return Object.prototype.toString.call(object) == '[object Arguments]';
- }
- function objEquiv(a, b) {
- if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
- return false;
- // an identical 'prototype' property.
- if (a.prototype !== b.prototype) return false;
- //~~~I've managed to break Object.keys through screwy arguments passing.
- // Converting to array solves the problem.
- if (isArguments(a)) {
- if (!isArguments(b)) {
- return false;
- }
- a = pSlice.call(a);
- b = pSlice.call(b);
- return _deepEqual(a, b);
- }
- try {
- var ka = objectKeys(a),
- kb = objectKeys(b),
- key, i;
- } catch (e) {//happens when one is a string literal and the other isn't
- return false;
- }
- // having the same number of owned properties (keys incorporates
- // hasOwnProperty)
- if (ka.length != kb.length)
- return false;
- //the same set of keys (although not necessarily the same order),
- ka.sort();
- kb.sort();
- //~~~cheap key test
- for (i = ka.length - 1; i >= 0; i--) {
- if (ka[i] != kb[i])
- return false;
- }
- //equivalent values for every corresponding key, and
- //~~~possibly expensive deep test
- for (i = ka.length - 1; i >= 0; i--) {
- key = ka[i];
- if (!_deepEqual(a[key], b[key])) return false;
- }
- return true;
- }
- // 8. The non-equivalence assertion tests for any deep inequality.
- // assert.notDeepEqual(actual, expected, message_opt);
- assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
- if (_deepEqual(actual, expected)) {
- fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
- }
- };
- // 9. The strict equality assertion tests strict equality, as determined by ===.
- // assert.strictEqual(actual, expected, message_opt);
- assert.strictEqual = function strictEqual(actual, expected, message) {
- if (actual !== expected) {
- fail(actual, expected, message, '===', assert.strictEqual);
- }
- };
- // 10. The strict non-equality assertion tests for strict inequality, as
- // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
- assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
- if (actual === expected) {
- fail(actual, expected, message, '!==', assert.notStrictEqual);
- }
- };
- function expectedException(actual, expected) {
- if (!actual || !expected) {
- return false;
- }
- if (expected instanceof RegExp) {
- return expected.test(actual);
- } else if (actual instanceof expected) {
- return true;
- } else if (expected.call({}, actual) === true) {
- return true;
- }
- return false;
- }
- function _throws(shouldThrow, block, expected, message) {
- var actual;
- if (typeof expected === 'string') {
- message = expected;
- expected = null;
- }
- try {
- block();
- } catch (e) {
- actual = e;
- }
- message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
- (message ? ' ' + message : '.');
- if (shouldThrow && !actual) {
- fail('Missing expected exception' + message);
- }
- if (!shouldThrow && expectedException(actual, expected)) {
- fail('Got unwanted exception' + message);
- }
- if ((shouldThrow && actual && expected &&
- !expectedException(actual, expected)) || (!shouldThrow && actual)) {
- throw actual;
- }
- }
- // 11. Expected to throw an error:
- // assert.throws(block, Error_opt, message_opt);
- assert.throws = function(block, /*optional*/error, /*optional*/message) {
- _throws.apply(this, [true].concat(pSlice.call(arguments)));
- };
- // EXTENSION! This is annoying to write outside this module.
- assert.doesNotThrow = function(block, /*optional*/error, /*optional*/message) {
- _throws.apply(this, [false].concat(pSlice.call(arguments)));
- };
- assert.ifError = function(err) { if (err) {throw err;}};
- },{"util":2,"buffer":3}],2:[function(require,module,exports){
- var events = require('events');
- exports.isArray = isArray;
- exports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'};
- exports.isRegExp = function(obj){return Object.prototype.toString.call(obj) === '[object RegExp]'};
- exports.print = function () {};
- exports.puts = function () {};
- exports.debug = function() {};
- exports.inspect = function(obj, showHidden, depth, colors) {
- var seen = [];
- var stylize = function(str, styleType) {
- // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
- var styles =
- { 'bold' : [1, 22],
- 'italic' : [3, 23],
- 'underline' : [4, 24],
- 'inverse' : [7, 27],
- 'white' : [37, 39],
- 'grey' : [90, 39],
- 'black' : [30, 39],
- 'blue' : [34, 39],
- 'cyan' : [36, 39],
- 'green' : [32, 39],
- 'magenta' : [35, 39],
- 'red' : [31, 39],
- 'yellow' : [33, 39] };
- var style =
- { 'special': 'cyan',
- 'number': 'blue',
- 'boolean': 'yellow',
- 'undefined': 'grey',
- 'null': 'bold',
- 'string': 'green',
- 'date': 'magenta',
- // "name": intentionally not styling
- 'regexp': 'red' }[styleType];
- if (style) {
- return '\033[' + styles[style][0] + 'm' + str +
- '\033[' + styles[style][1] + 'm';
- } else {
- return str;
- }
- };
- if (! colors) {
- stylize = function(str, styleType) { return str; };
- }
- function format(value, recurseTimes) {
- // Provide a hook for user-specified inspect functions.
- // Check that value is an object with an inspect function on it
- if (value && typeof value.inspect === 'function' &&
- // Filter out the util module, it's inspect function is special
- value !== exports &&
- // Also filter out any prototype objects using the circular check.
- !(value.constructor && value.constructor.prototype === value)) {
- return value.inspect(recurseTimes);
- }
- // Primitive types cannot have properties
- switch (typeof value) {
- case 'undefined':
- return stylize('undefined', 'undefined');
- case 'string':
- var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
- .replace(/'/g, "\\'")
- .replace(/\\"/g, '"') + '\'';
- return stylize(simple, 'string');
- case 'number':
- return stylize('' + value, 'number');
- case 'boolean':
- return stylize('' + value, 'boolean');
- }
- // For some reason typeof null is "object", so special case here.
- if (value === null) {
- return stylize('null', 'null');
- }
- // Look up the keys of the object.
- var visible_keys = Object_keys(value);
- var keys = showHidden ? Object_getOwnPropertyNames(value) : visible_keys;
- // Functions without properties can be shortcutted.
- if (typeof value === 'function' && keys.length === 0) {
- if (isRegExp(value)) {
- return stylize('' + value, 'regexp');
- } else {
- var name = value.name ? ': ' + value.name : '';
- return stylize('[Function' + name + ']', 'special');
- }
- }
- // Dates without properties can be shortcutted
- if (isDate(value) && keys.length === 0) {
- return stylize(value.toUTCString(), 'date');
- }
- var base, type, braces;
- // Determine the object type
- if (isArray(value)) {
- type = 'Array';
- braces = ['[', ']'];
- } else {
- type = 'Object';
- braces = ['{', '}'];
- }
- // Make functions say that they are functions
- if (typeof value === 'function') {
- var n = value.name ? ': ' + value.name : '';
- base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']';
- } else {
- base = '';
- }
- // Make dates with properties first say the date
- if (isDate(value)) {
- base = ' ' + value.toUTCString();
- }
- if (keys.length === 0) {
- return braces[0] + base + braces[1];
- }
- if (recurseTimes < 0) {
- if (isRegExp(value)) {
- return stylize('' + value, 'regexp');
- } else {
- return stylize('[Object]', 'special');
- }
- }
- seen.push(value);
- var output = keys.map(function(key) {
- var name, str;
- if (value.__lookupGetter__) {
- if (value.__lookupGetter__(key)) {
- if (value.__lookupSetter__(key)) {
- str = stylize('[Getter/Setter]', 'special');
- } else {
- str = stylize('[Getter]', 'special');
- }
- } else {
- if (value.__lookupSetter__(key)) {
- str = stylize('[Setter]', 'special');
- }
- }
- }
- if (visible_keys.indexOf(key) < 0) {
- name = '[' + key + ']';
- }
- if (!str) {
- if (seen.indexOf(value[key]) < 0) {
- if (recurseTimes === null) {
- str = format(value[key]);
- } else {
- str = format(value[key], recurseTimes - 1);
- }
- if (str.indexOf('\n') > -1) {
- if (isArray(value)) {
- str = str.split('\n').map(function(line) {
- return ' ' + line;
- }).join('\n').substr(2);
- } else {
- str = '\n' + str.split('\n').map(function(line) {
- return ' ' + line;
- }).join('\n');
- }
- }
- } else {
- str = stylize('[Circular]', 'special');
- }
- }
- if (typeof name === 'undefined') {
- if (type === 'Array' && key.match(/^\d+$/)) {
- return str;
- }
- name = JSON.stringify('' + key);
- if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
- name = name.substr(1, name.length - 2);
- name = stylize(name, 'name');
- } else {
- name = name.replace(/'/g, "\\'")
- .replace(/\\"/g, '"')
- .replace(/(^"|"$)/g, "'");
- name = stylize(name, 'string');
- }
- }
- return name + ': ' + str;
- });
- seen.pop();
- var numLinesEst = 0;
- var length = output.reduce(function(prev, cur) {
- numLinesEst++;
- if (cur.indexOf('\n') >= 0) numLinesEst++;
- return prev + cur.length + 1;
- }, 0);
- if (length > 50) {
- output = braces[0] +
- (base === '' ? '' : base + '\n ') +
- ' ' +
- output.join(',\n ') +
- ' ' +
- braces[1];
- } else {
- output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
- }
- return output;
- }
- return format(obj, (typeof depth === 'undefined' ? 2 : depth));
- };
- function isArray(ar) {
- return ar instanceof Array ||
- Array.isArray(ar) ||
- (ar && ar !== Object.prototype && isArray(ar.__proto__));
- }
- function isRegExp(re) {
- return re instanceof RegExp ||
- (typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]');
- }
- function isDate(d) {
- if (d instanceof Date) return true;
- if (typeof d !== 'object') return false;
- var properties = Date.prototype && Object_getOwnPropertyNames(Date.prototype);
- var proto = d.__proto__ && Object_getOwnPropertyNames(d.__proto__);
- return JSON.stringify(proto) === JSON.stringify(properties);
- }
- function pad(n) {
- return n < 10 ? '0' + n.toString(10) : n.toString(10);
- }
- var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
- 'Oct', 'Nov', 'Dec'];
- // 26 Feb 16:19:34
- function timestamp() {
- var d = new Date();
- var time = [pad(d.getHours()),
- pad(d.getMinutes()),
- pad(d.getSeconds())].join(':');
- return [d.getDate(), months[d.getMonth()], time].join(' ');
- }
- exports.log = function (msg) {};
- exports.pump = null;
- var Object_keys = Object.keys || function (obj) {
- var res = [];
- for (var key in obj) res.push(key);
- return res;
- };
- var Object_getOwnPropertyNames = Object.getOwnPropertyNames || function (obj) {
- var res = [];
- for (var key in obj) {
- if (Object.hasOwnProperty.call(obj, key)) res.push(key);
- }
- return res;
- };
- var Object_create = Object.create || function (prototype, properties) {
- // from es5-shim
- var object;
- if (prototype === null) {
- object = { '__proto__' : null };
- }
- else {
- if (typeof prototype !== 'object') {
- throw new TypeError(
- 'typeof prototype[' + (typeof prototype) + '] != \'object\''
- );
- }
- var Type = function () {};
- Type.prototype = prototype;
- object = new Type();
- object.__proto__ = prototype;
- }
- if (typeof properties !== 'undefined' && Object.defineProperties) {
- Object.defineProperties(object, properties);
- }
- return object;
- };
- exports.inherits = function(ctor, superCtor) {
- ctor.super_ = superCtor;
- ctor.prototype = Object_create(superCtor.prototype, {
- constructor: {
- value: ctor,
- enumerable: false,
- writable: true,
- configurable: true
- }
- });
- };
- var formatRegExp = /%[sdj%]/g;
- exports.format = function(f) {
- if (typeof f !== 'string') {
- var objects = [];
- for (var i = 0; i < arguments.length; i++) {
- objects.push(exports.inspect(arguments[i]));
- }
- return objects.join(' ');
- }
- var i = 1;
- var args = arguments;
- var len = args.length;
- var str = String(f).replace(formatRegExp, function(x) {
- if (x === '%%') return '%';
- if (i >= len) return x;
- switch (x) {
- case '%s': return String(args[i++]);
- case '%d': return Number(args[i++]);
- case '%j': return JSON.stringify(args[i++]);
- default:
- return x;
- }
- });
- for(var x = args[i]; i < len; x = args[++i]){
- if (x === null || typeof x !== 'object') {
- str += ' ' + x;
- } else {
- str += ' ' + exports.inspect(x);
- }
- }
- return str;
- };
- },{"events":4}],5:[function(require,module,exports){
- exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) {
- var e, m,
- eLen = nBytes * 8 - mLen - 1,
- eMax = (1 << eLen) - 1,
- eBias = eMax >> 1,
- nBits = -7,
- i = isBE ? 0 : (nBytes - 1),
- d = isBE ? 1 : -1,
- s = buffer[offset + i];
- i += d;
- e = s & ((1 << (-nBits)) - 1);
- s >>= (-nBits);
- nBits += eLen;
- for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
- m = e & ((1 << (-nBits)) - 1);
- e >>= (-nBits);
- nBits += mLen;
- for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
- if (e === 0) {
- e = 1 - eBias;
- } else if (e === eMax) {
- return m ? NaN : ((s ? -1 : 1) * Infinity);
- } else {
- m = m + Math.pow(2, mLen);
- e = e - eBias;
- }
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
- };
- exports.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) {
- var e, m, c,
- eLen = nBytes * 8 - mLen - 1,
- eMax = (1 << eLen) - 1,
- eBias = eMax >> 1,
- rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
- i = isBE ? (nBytes - 1) : 0,
- d = isBE ? -1 : 1,
- s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
- value = Math.abs(value);
- if (isNaN(value) || value === Infinity) {
- m = isNaN(value) ? 1 : 0;
- e = eMax;
- } else {
- e = Math.floor(Math.log(value) / Math.LN2);
- if (value * (c = Math.pow(2, -e)) < 1) {
- e--;
- c *= 2;
- }
- if (e + eBias >= 1) {
- value += rt / c;
- } else {
- value += rt * Math.pow(2, 1 - eBias);
- }
- if (value * c >= 2) {
- e++;
- c /= 2;
- }
- if (e + eBias >= eMax) {
- m = 0;
- e = eMax;
- } else if (e + eBias >= 1) {
- m = (value * c - 1) * Math.pow(2, mLen);
- e = e + eBias;
- } else {
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
- e = 0;
- }
- }
- for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
- e = (e << mLen) | m;
- eLen += mLen;
- for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
- buffer[offset + i - d] |= s * 128;
- };
- },{}],6:[function(require,module,exports){
- // shim for using process in browser
- var process = module.exports = {};
- process.nextTick = (function () {
- var canSetImmediate = typeof window !== 'undefined'
- && window.setImmediate;
- var canPost = typeof window !== 'undefined'
- && window.postMessage && window.addEventListener
- ;
- if (canSetImmediate) {
- return function (f) { return window.setImmediate(f) };
- }
- if (canPost) {
- var queue = [];
- window.addEventListener('message', function (ev) {
- if (ev.source === window && ev.data === 'process-tick') {
- ev.stopPropagation();
- if (queue.length > 0) {
- var fn = queue.shift();
- fn();
- }
- }
- }, true);
- return function nextTick(fn) {
- queue.push(fn);
- window.postMessage('process-tick', '*');
- };
- }
- return function nextTick(fn) {
- setTimeout(fn, 0);
- };
- })();
- process.title = 'browser';
- process.browser = true;
- process.env = {};
- process.argv = [];
- process.binding = function (name) {
- throw new Error('process.binding is not supported');
- }
- // TODO(shtylman)
- process.cwd = function () { return '/' };
- process.chdir = function (dir) {
- throw new Error('process.chdir is not supported');
- };
- },{}],4:[function(require,module,exports){
- (function(process){if (!process.EventEmitter) process.EventEmitter = function () {};
- var EventEmitter = exports.EventEmitter = process.EventEmitter;
- var isArray = typeof Array.isArray === 'function'
- ? Array.isArray
- : function (xs) {
- return Object.prototype.toString.call(xs) === '[object Array]'
- }
- ;
- function indexOf (xs, x) {
- if (xs.indexOf) return xs.indexOf(x);
- for (var i = 0; i < xs.length; i++) {
- if (x === xs[i]) return i;
- }
- return -1;
- }
- // By default EventEmitters will print a warning if more than
- // 10 listeners are added to it. This is a useful default which
- // helps finding memory leaks.
- //
- // Obviously not all Emitters should be limited to 10. This function allows
- // that to be increased. Set to zero for unlimited.
- var defaultMaxListeners = 10;
- EventEmitter.prototype.setMaxListeners = function(n) {
- if (!this._events) this._events = {};
- this._events.maxListeners = n;
- };
- EventEmitter.prototype.emit = function(type) {
- // If there is no 'error' event listener then throw.
- if (type === 'error') {
- if (!this._events || !this._events.error ||
- (isArray(this._events.error) && !this._events.error.length))
- {
- if (arguments[1] instanceof Error) {
- throw arguments[1]; // Unhandled 'error' event
- } else {
- throw new Error("Uncaught, unspecified 'error' event.");
- }
- return false;
- }
- }
- if (!this._events) return false;
- var handler = this._events[type];
- if (!handler) return false;
- if (typeof handler == 'function') {
- switch (arguments.length) {
- // fast cases
- case 1:
- handler.call(this);
- break;
- case 2:
- handler.call(this, arguments[1]);
- break;
- case 3:
- handler.call(this, arguments[1], arguments[2]);
- break;
- // slower
- default:
- var args = Array.prototype.slice.call(arguments, 1);
- handler.apply(this, args);
- }
- return true;
- } else if (isArray(handler)) {
- var args = Array.prototype.slice.call(arguments, 1);
- var listeners = handler.slice();
- for (var i = 0, l = listeners.length; i < l; i++) {
- listeners[i].apply(this, args);
- }
- return true;
- } else {
- return false;
- }
- };
- // EventEmitter is defined in src/node_events.cc
- // EventEmitter.prototype.emit() is also defined there.
- EventEmitter.prototype.addListener = function(type, listener) {
- if ('function' !== typeof listener) {
- throw new Error('addListener only takes instances of Function');
- }
- if (!this._events) this._events = {};
- // To avoid recursion in the case that type == "newListeners"! Before
- // adding it to the listeners, first emit "newListeners".
- this.emit('newListener', type, listener);
- if (!this._events[type]) {
- // Optimize the case of one listener. Don't need the extra array object.
- this._events[type] = listener;
- } else if (isArray(this._events[type])) {
- // Check for listener leak
- if (!this._events[type].warned) {
- var m;
- if (this._events.maxListeners !== undefined) {
- m = this._events.maxListeners;
- } else {
- m = defaultMaxListeners;
- }
- if (m && m > 0 && this._events[type].length > m) {
- this._events[type].warned = true;
- console.error('(node) warning: possible EventEmitter memory ' +
- 'leak detected. %d listeners added. ' +
- 'Use emitter.setMaxListeners() to increase limit.',
- this._events[type].length);
- console.trace();
- }
- }
- // If we've already got an array, just append.
- this._events[type].push(listener);
- } else {
- // Adding the second element, need to change to array.
- this._events[type] = [this._events[type], listener];
- }
- return this;
- };
- EventEmitter.prototype.on = EventEmitter.prototype.addListener;
- EventEmitter.prototype.once = function(type, listener) {
- var self = this;
- self.on(type, function g() {
- self.removeListener(type, g);
- listener.apply(this, arguments);
- });
- return this;
- };
- EventEmitter.prototype.removeListener = function(type, listener) {
- if ('function' !== typeof listener) {
- throw new Error('removeListener only takes instances of Function');
- }
- // does not use listeners(), so no side effect of creating _events[type]
- if (!this._events || !this._events[type]) return this;
- var list = this._events[type];
- if (isArray(list)) {
- var i = indexOf(list, listener);
- if (i < 0) return this;
- list.splice(i, 1);
- if (list.length == 0)
- delete this._events[type];
- } else if (this._events[type] === listener) {
- delete this._events[type];
- }
- return this;
- };
- EventEmitter.prototype.removeAllListeners = function(type) {
- if (arguments.length === 0) {
- this._events = {};
- return this;
- }
- // does not use listeners(), so no side effect of creating _events[type]
- if (type && this._events && this._events[type]) this._events[type] = null;
- return this;
- };
- EventEmitter.prototype.listeners = function(type) {
- if (!this._events) this._events = {};
- if (!this._events[type]) this._events[type] = [];
- if (!isArray(this._events[type])) {
- this._events[type] = [this._events[type]];
- }
- return this._events[type];
- };
- })(require("__browserify_process"))
- },{"__browserify_process":6}],"buffer-browserify":[function(require,module,exports){
- module.exports=require('q9TxCC');
- },{}],"q9TxCC":[function(require,module,exports){
- function SlowBuffer (size) {
- this.length = size;
- };
- var assert = require('assert');
- exports.INSPECT_MAX_BYTES = 50;
- function toHex(n) {
- if (n < 16) return '0' + n.toString(16);
- return n.toString(16);
- }
- function utf8ToBytes(str) {
- var byteArray = [];
- for (var i = 0; i < str.length; i++)
- if (str.charCodeAt(i) <= 0x7F)
- byteArray.push(str.charCodeAt(i));
- else {
- var h = encodeURIComponent(str.charAt(i)).substr(1).split('%');
- for (var j = 0; j < h.length; j++)
- byteArray.push(parseInt(h[j], 16));
- }
- return byteArray;
- }
- function asciiToBytes(str) {
- var byteArray = []
- for (var i = 0; i < str.length; i++ )
- // Node's code seems to be doing this and not & 0x7F..
- byteArray.push( str.charCodeAt(i) & 0xFF );
- return byteArray;
- }
- function base64ToBytes(str) {
- return require("base64-js").toByteArray(str);
- }
- SlowBuffer.byteLength = function (str, encoding) {
- switch (encoding || "utf8") {
- case 'hex':
- return str.length / 2;
- case 'utf8':
- case 'utf-8':
- return utf8ToBytes(str).length;
- case 'ascii':
- case 'binary':
- return str.length;
- case 'base64':
- return base64ToBytes(str).length;
- default:
- throw new Error('Unknown encoding');
- }
- };
- function blitBuffer(src, dst, offset, length) {
- var pos, i = 0;
- while (i < length) {
- if ((i+offset >= dst.length) || (i >= src.length))
- break;
- dst[i + offset] = src[i];
- i++;
- }
- return i;
- }
- SlowBuffer.prototype.utf8Write = function (string, offset, length) {
- var bytes, pos;
- return SlowBuffer._charsWritten = blitBuffer(utf8ToBytes(string), this, offset, length);
- };
- SlowBuffer.prototype.asciiWrite = function (string, offset, length) {
- var bytes, pos;
- return SlowBuffer._charsWritten = blitBuffer(asciiToBytes(string), this, offset, length);
- };
- SlowBuffer.prototype.binaryWrite = SlowBuffer.prototype.asciiWrite;
- SlowBuffer.prototype.base64Write = function (string, offset, length) {
- var bytes, pos;
- return SlowBuffer._charsWritten = blitBuffer(base64ToBytes(string), this, offset, length);
- };
- SlowBuffer.prototype.base64Slice = function (start, end) {
- var bytes = Array.prototype.slice.apply(this, arguments)
- return require("base64-js").fromByteArray(bytes);
- }
- function decodeUtf8Char(str) {
- try {
- return decodeURIComponent(str);
- } catch (err) {
- return String.fromCharCode(0xFFFD); // UTF 8 invalid char
- }
- }
- SlowBuffer.prototype.utf8Slice = function () {
- var bytes = Array.prototype.slice.apply(this, arguments);
- var res = "";
- var tmp = "";
- var i = 0;
- while (i < bytes.length) {
- if (bytes[i] <= 0x7F) {
- res += decodeUtf8Char(tmp) + String.fromCharCode(bytes[i]);
- tmp = "";
- } else
- tmp += "%" + bytes[i].toString(16);
- i++;
- }
- return res + decodeUtf8Char(tmp);
- }
- SlowBuffer.prototype.asciiSlice = function () {
- var bytes = Array.prototype.slice.apply(this, arguments);
- var ret = "";
- for (var i = 0; i < bytes.length; i++)
- ret += String.fromCharCode(bytes[i]);
- return ret;
- }
- SlowBuffer.prototype.binarySlice = SlowBuffer.prototype.asciiSlice;
- SlowBuffer.prototype.inspect = function() {
- var out = [],
- len = this.length;
- for (var i = 0; i < len; i++) {
- out[i] = toHex(this[i]);
- if (i == exports.INSPECT_MAX_BYTES) {
- out[i + 1] = '...';
- break;
- }
- }
- return '<SlowBuffer ' + out.join(' ') + '>';
- };
- SlowBuffer.prototype.hexSlice = function(start, end) {
- var len = this.length;
- if (!start || start < 0) start = 0;
- if (!end || end < 0 || end > len) end = len;
- var out = '';
- for (var i = start; i < end; i++) {
- out += toHex(this[i]);
- }
- return out;
- };
- SlowBuffer.prototype.toString = function(encoding, start, end) {
- encoding = String(encoding || 'utf8').toLowerCase();
- start = +start || 0;
- if (typeof end == 'undefined') end = this.length;
- // Fastpath empty strings
- if (+end == start) {
- return '';
- }
- switch (encoding) {
- case 'hex':
- return this.hexSlice(start, end);
- case 'utf8':
- case 'utf-8':
- return this.utf8Slice(start, end);
- case 'ascii':
- return this.asciiSlice(start, end);
- case 'binary':
- return this.binarySlice(start, end);
- case 'base64':
- return this.base64Slice(start, end);
- case 'ucs2':
- case 'ucs-2':
- return this.ucs2Slice(start, end);
- default:
- throw new Error('Unknown encoding');
- }
- };
- SlowBuffer.prototype.hexWrite = function(string, offset, length) {
- offset = +offset || 0;
- var remaining = this.length - offset;
- if (!length) {
- length = remaining;
- } else {
- length = +length;
- if (length > remaining) {
- length = remaining;
- }
- }
- // must be an even number of digits
- var strLen = string.length;
- if (strLen % 2) {
- throw new Error('Invalid hex string');
- }
- if (length > strLen / 2) {
- length = strLen / 2;
- }
- for (var i = 0; i < length; i++) {
- var byte = parseInt(string.substr(i * 2, 2), 16);
- if (isNaN(byte)) throw new Error('Invalid hex string');
- this[offset + i] = byte;
- }
- SlowBuffer._charsWritten = i * 2;
- return i;
- };
- SlowBuffer.prototype.write = function(string, offset, length, encoding) {
- // Support both (string, offset, length, encoding)
- // and the legacy (string, encoding, offset, length)
- if (isFinite(offset)) {
- if (!isFinite(length)) {
- encoding = length;
- length = undefined;
- }
- } else { // legacy
- var swap = encoding;
- encoding = offset;
- offset = length;
- length = swap;
- }
- offset = +offset || 0;
- var remaining = this.length - offset;
- if (!length) {
- length = remaining;
- } else {
- length = +length;
- if (length > remaining) {
- length = remaining;
- }
- }
- encoding = String(encoding || 'utf8').toLowerCase();
- switch (encoding) {
- case 'hex':
- return this.hexWrite(string, offset, length);
- case 'utf8':
- case 'utf-8':
- return this.utf8Write(string, offset, length);
- case 'ascii':
- return this.asciiWrite(string, offset, length);
- case 'binary':
- return this.binaryWrite(string, offset, length);
- case 'base64':
- return this.base64Write(string, offset, length);
- case 'ucs2':
- case 'ucs-2':
- return this.ucs2Write(string, offset, length);
- default:
- throw new Error('Unknown encoding');
- }
- };
- // slice(start, end)
- SlowBuffer.prototype.slice = function(start, end) {
- if (end === undefined) end = this.length;
- if (end > this.length) {
- throw new Error('oob');
- }
- if (start > end) {
- throw new Error('oob');
- }
- return new Buffer(this, end - start, +start);
- };
- SlowBuffer.prototype.copy = function(target, targetstart, sourcestart, sourceend) {
- var temp = [];
- for (var i=sourcestart; i<sourceend; i++) {
- assert.ok(typeof this[i] !== 'undefined', "copying undefined buffer bytes!");
- temp.push(this[i]);
- }
- for (var i=targetstart; i<targetstart+temp.length; i++) {
- target[i] = temp[i-targetstart];
- }
- };
- SlowBuffer.prototype.fill = function(value, start, end) {
- if (end > this.length) {
- throw new Error('oob');
- }
- if (start > end) {
- throw new Error('oob');
- }
- for (var i = start; i < end; i++) {
- this[i] = value;
- }
- }
- function coerce(length) {
- // Coerce length to a number (possibly NaN), round up
- // in case it's fractional (e.g. 123.456) then do a
- // double negate to coerce a NaN to 0. Easy, right?
- length = ~~Math.ceil(+length);
- return length < 0 ? 0 : length;
- }
- // Buffer
- function Buffer(subject, encoding, offset) {
- if (!(this instanceof Buffer)) {
- return new Buffer(subject, encoding, offset);
- }
- var type;
- // Are we slicing?
- if (typeof offset === 'number') {
- this.length = coerce(encoding);
- this.parent = subject;
- this.offset = offset;
- } else {
- // Find the length
- switch (type = typeof subject) {
- case 'number':
- this.length = coerce(subject);
- break;
- case 'string':
- this.length = Buffer.byteLength(subject, encoding);
- break;
- case 'object': // Assume object is an array
- this.length = coerce(subject.length);
- break;
- default:
- throw new Error('First argument needs to be a number, ' +
- 'array or string.');
- }
- if (this.length > Buffer.poolSize) {
- // Big buffer, just alloc one.
- this.parent = new SlowBuffer(this.length);
- this.offset = 0;
- } else {
- // Small buffer.
- if (!pool || pool.length - pool.used < this.length) allocPool();
- this.parent = pool;
- this.offset = pool.used;
- pool.used += this.length;
- }
- // Treat array-ish objects as a byte array.
- if (isArrayIsh(subject)) {
- for (var i = 0; i < this.length; i++) {
- if (subject instanceof Buffer) {
- this.parent[i + this.offset] = subject.readUInt8(i);
- }
- else {
- this.parent[i + this.offset] = subject[i];
- }
- }
- } else if (type == 'string') {
- // We are a string
- this.length = this.write(subject, 0, encoding);
- }
- }
- }
- function isArrayIsh(subject) {
- return Array.isArray(subject) || Buffer.isBuffer(subject) ||
- subject && typeof subject === 'object' &&
- typeof subject.length === 'number';
- }
- exports.SlowBuffer = SlowBuffer;
- exports.Buffer = Buffer;
- Buffer.poolSize = 8 * 1024;
- var pool;
- function allocPool() {
- pool = new SlowBuffer(Buffer.poolSize);
- pool.used = 0;
- }
- // Static methods
- Buffer.isBuffer = function isBuffer(b) {
- return b instanceof Buffer || b instanceof SlowBuffer;
- };
- Buffer.concat = function (list, totalLength) {
- if (!Array.isArray(list)) {
- throw new Error("Usage: Buffer.concat(list, [totalLength])\n \
- list should be an Array.");
- }
- if (list.length === 0) {
- return new Buffer(0);
- } else if (list.length === 1) {
- return list[0];
- }
- if (typeof totalLength !== 'number') {
- totalLength = 0;
- for (var i = 0; i < list.length; i++) {
- var buf = list[i];
- totalLength += buf.length;
- }
- }
- var buffer = new Buffer(totalLength);
- var pos = 0;
- for (var i = 0; i < list.length; i++) {
- var buf = list[i];
- buf.copy(buffer, pos);
- pos += buf.length;
- }
- return buffer;
- };
- // Inspect
- Buffer.prototype.inspect = function inspect() {
- var out = [],
- len = this.length;
- for (var i = 0; i < len; i++) {
- out[i] = toHex(this.parent[i + this.offset]);
- if (i == exports.INSPECT_MAX_BYTES) {
- out[i + 1] = '...';
- break;
- }
- }
- return '<Buffer ' + out.join(' ') + '>';
- };
- Buffer.prototype.get = function get(i) {
- if (i < 0 || i >= this.length) throw new Error('oob');
- return this.parent[this.offset + i];
- };
- Buffer.prototype.set = function set(i, v) {
- if (i < 0 || i >= this.length) throw new Error('oob');
- return this.parent[this.offset + i] = v;
- };
- // write(string, offset = 0, length = buffer.length-offset, encoding = 'utf8')
- Buffer.prototype.write = function(string, offset, length, encoding) {
- // Support both (string, offset, length, encoding)
- // and the legacy (string, encoding, offset, length)
- if (isFinite(offset)) {
- if (!isFinite(length)) {
- encoding = length;
- length = undefined;
- }
- } else { // legacy
- var swap = encoding;
- encoding = offset;
- offset = length;
- length = swap;
- }
- offset = +offset || 0;
- var remaining = this.length - offset;
- if (!length) {
- length = remaining;
- } else {
- length = +length;
- if (length > remaining) {
- length = remaining;
- }
- }
- encoding = String(encoding || 'utf8').toLowerCase();
- var ret;
- switch (encoding) {
- case 'hex':
- ret = this.parent.hexWrite(string, this.offset + offset, length);
- break;
- case 'utf8':
- case 'utf-8':
- ret = this.parent.utf8Write(string, this.offset + offset, length);
- break;
- case 'ascii':
- ret = this.parent.asciiWrite(string, this.offset + offset, length);
- break;
- case 'binary':
- ret = this.parent.binaryWrite(string, this.offset + offset, length);
- break;
- case 'base64':
- // Warning: maxLength not taken into account in base64Write
- ret = this.parent.base64Write(string, this.offset + offset, length);
- break;
- case 'ucs2':
- case 'ucs-2':
- ret = this.parent.ucs2Write(string, this.offset + offset, length);
- break;
- default:
- throw new Error('Unknown encoding');
- }
- Buffer._charsWritten = SlowBuffer._charsWritten;
- return ret;
- };
- // toString(encoding, start=0, end=buffer.length)
- Buffer.prototype.toString = function(encoding, start, end) {
- encoding = String(encoding || 'utf8').toLowerCase();
- if (typeof start == 'undefined' || start < 0) {
- start = 0;
- } else if (start > this.length) {
- start = this.length;
- }
- if (typeof end == 'undefined' || end > this.length) {
- end = this.length;
- } else if (end < 0) {
- end = 0;
- }
- start = start + this.offset;
- end = end + this.offset;
- switch (encoding) {
- case 'hex':
- return this.parent.hexSlice(start, end);
- case 'utf8':
- case 'utf-8':
- return this.parent.utf8Slice(start, end);
- case 'ascii':
- return this.parent.asciiSlice(start, end);
- case 'binary':
- return this.parent.binarySlice(start, end);
- case 'base64':
- return this.parent.base64Slice(start, end);
- case 'ucs2':
- case 'ucs-2':
- return this.parent.ucs2Slice(start, end);
- default:
- throw new Error('Unknown encoding');
- }
- };
- // byteLength
- Buffer.byteLength = SlowBuffer.byteLength;
- // fill(value, start=0, end=buffer.length)
- Buffer.prototype.fill = function fill(value, start, end) {
- value || (value = 0);
- start || (start = 0);
- end || (end = this.length);
- if (typeof value === 'string') {
- value = value.charCodeAt(0);
- }
- if (!(typeof value === 'number') || isNaN(value)) {
- throw new Error('value is not a number');
- }
- if (end < start) throw new Error('end < start');
- // Fill 0 bytes; we're done
- if (end === start) return 0;
- if (this.length == 0) return 0;
- if (start < 0 || start >= this.length) {
- throw new Error('start out of bounds');
- }
- if (end < 0 || end > this.length) {
- throw new Error('end out of bounds');
- }
- return this.parent.fill(value,
- start + this.offset,
- end + this.offset);
- };
- // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
- Buffer.prototype.copy = function(target, target_start, start, end) {
- var source = this;
- start || (start = 0);
- end || (end = this.length);
- target_start || (target_start = 0);
- if (end < start) throw new Error('sourceEnd < sourceStart');
- // Copy 0 bytes; we're done
- if (end === start) return 0;
- if (target.length == 0 || source.length == 0) return 0;
- if (target_start < 0 || target_start >= target.length) {
- throw new Error('targetStart out of bounds');
- }
- if (start < 0 || start >= source.length) {
- throw new Error('sourceStart out of bounds');
- }
- if (end < 0 || end > source.length) {
- throw new Error('sourceEnd out of bounds');
- }
- // Are we oob?
- if (end > this.length) {
- end = this.length;
- }
- if (target.length - target_start < end - start) {
- end = target.length - target_start + start;
- }
- return this.parent.copy(target.parent,
- target_start + target.offset,
- start + this.offset,
- end + this.offset);
- };
- // slice(start, end)
- Buffer.prototype.slice = function(start, end) {
- if (end === undefined) end = this.length;
- if (end > this.length) throw new Error('oob');
- if (start > end) throw new Error('oob');
- return new Buffer(this.parent, end - start, +start + this.offset);
- };
- // Legacy methods for backwards compatibility.
- Buffer.prototype.utf8Slice = function(start, end) {
- return this.toString('utf8', start, end);
- };
- Buffer.prototype.binarySlice = function(start, end) {
- return this.toString('binary', start, end);
- };
- Buffer.prototype.asciiSlice = function(start, end) {
- return this.toString('ascii', start, end);
- };
- Buffer.prototype.utf8Write = function(string, offset) {
- return this.write(string, offset, 'utf8');
- };
- Buffer.prototype.binaryWrite = function(string, offset) {
- return this.write(string, offset, 'binary');
- };
- Buffer.prototype.asciiWrite = function(string, offset) {
- return this.write(string, offset, 'ascii');
- };
- Buffer.prototype.readUInt8 = function(offset, noAssert) {
- var buffer = this;
- if (!noAssert) {
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset < buffer.length,
- 'Trying to read beyond buffer length');
- }
- if (offset >= buffer.length) return;
- return buffer.parent[buffer.offset + offset];
- };
- function readUInt16(buffer, offset, isBigEndian, noAssert) {
- var val = 0;
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 1 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- if (offset >= buffer.length) return 0;
- if (isBigEndian) {
- val = buffer.parent[buffer.offset + offset] << 8;
- if (offset + 1 < buffer.length) {
- val |= buffer.parent[buffer.offset + offset + 1];
- }
- } else {
- val = buffer.parent[buffer.offset + offset];
- if (offset + 1 < buffer.length) {
- val |= buffer.parent[buffer.offset + offset + 1] << 8;
- }
- }
- return val;
- }
- Buffer.prototype.readUInt16LE = function(offset, noAssert) {
- return readUInt16(this, offset, false, noAssert);
- };
- Buffer.prototype.readUInt16BE = function(offset, noAssert) {
- return readUInt16(this, offset, true, noAssert);
- };
- function readUInt32(buffer, offset, isBigEndian, noAssert) {
- var val = 0;
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- if (offset >= buffer.length) return 0;
- if (isBigEndian) {
- if (offset + 1 < buffer.length)
- val = buffer.parent[buffer.offset + offset + 1] << 16;
- if (offset + 2 < buffer.length)
- val |= buffer.parent[buffer.offset + offset + 2] << 8;
- if (offset + 3 < buffer.length)
- val |= buffer.parent[buffer.offset + offset + 3];
- val = val + (buffer.parent[buffer.offset + offset] << 24 >>> 0);
- } else {
- if (offset + 2 < buffer.length)
- val = buffer.parent[buffer.offset + offset + 2] << 16;
- if (offset + 1 < buffer.length)
- val |= buffer.parent[buffer.offset + offset + 1] << 8;
- val |= buffer.parent[buffer.offset + offset];
- if (offset + 3 < buffer.length)
- val = val + (buffer.parent[buffer.offset + offset + 3] << 24 >>> 0);
- }
- return val;
- }
- Buffer.prototype.readUInt32LE = function(offset, noAssert) {
- return readUInt32(this, offset, false, noAssert);
- };
- Buffer.prototype.readUInt32BE = function(offset, noAssert) {
- return readUInt32(this, offset, true, noAssert);
- };
- /*
- * Signed integer types, yay team! A reminder on how two's complement actually
- * works. The first bit is the signed bit, i.e. tells us whether or not the
- * number should be positive or negative. If the two's complement value is
- * positive, then we're done, as it's equivalent to the unsigned representation.
- *
- * Now if the number is positive, you're pretty much done, you can just leverage
- * the unsigned translations and return those. Unfortunately, negative numbers
- * aren't quite that straightforward.
- *
- * At first glance, one might be inclined to use the traditional formula to
- * translate binary numbers between the positive and negative values in two's
- * complement. (Though it doesn't quite work for the most negative value)
- * Mainly:
- * - invert all the bits
- * - add one to the result
- *
- * Of course, this doesn't quite work in Javascript. Take for example the value
- * of -128. This could be represented in 16 bits (big-endian) as 0xff80. But of
- * course, Javascript will do the following:
- *
- * > ~0xff80
- * -65409
- *
- * Whoh there, Javascript, that's not quite right. But wait, according to
- * Javascript that's perfectly correct. When Javascript ends up seeing the
- * constant 0xff80, it has no notion that it is actually a signed number. It
- * assumes that we've input the unsigned value 0xff80. Thus, when it does the
- * binary negation, it casts it into a signed value, (positive 0xff80). Then
- * when you perform binary negation on that, it turns it into a negative number.
- *
- * Instead, we're going to have to use the following general formula, that works
- * in a rather Javascript friendly way. I'm glad we don't support this kind of
- * weird numbering scheme in the kernel.
- *
- * (BIT-MAX - (unsigned)val + 1) * -1
- *
- * The astute observer, may think that this doesn't make sense for 8-bit numbers
- * (really it isn't necessary for them). However, when you get 16-bit numbers,
- * you do. Let's go back to our prior example and see how this will look:
- *
- * (0xffff - 0xff80 + 1) * -1
- * (0x007f + 1) * -1
- * (0x0080) * -1
- */
- Buffer.prototype.readInt8 = function(offset, noAssert) {
- var buffer = this;
- var neg;
- if (!noAssert) {
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset < buffer.length,
- 'Trying to read beyond buffer length');
- }
- if (offset >= buffer.length) return;
- neg = buffer.parent[buffer.offset + offset] & 0x80;
- if (!neg) {
- return (buffer.parent[buffer.offset + offset]);
- }
- return ((0xff - buffer.parent[buffer.offset + offset] + 1) * -1);
- };
- function readInt16(buffer, offset, isBigEndian, noAssert) {
- var neg, val;
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 1 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- val = readUInt16(buffer, offset, isBigEndian, noAssert);
- neg = val & 0x8000;
- if (!neg) {
- return val;
- }
- return (0xffff - val + 1) * -1;
- }
- Buffer.prototype.readInt16LE = function(offset, noAssert) {
- return readInt16(this, offset, false, noAssert);
- };
- Buffer.prototype.readInt16BE = function(offset, noAssert) {
- return readInt16(this, offset, true, noAssert);
- };
- function readInt32(buffer, offset, isBigEndian, noAssert) {
- var neg, val;
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- val = readUInt32(buffer, offset, isBigEndian, noAssert);
- neg = val & 0x80000000;
- if (!neg) {
- return (val);
- }
- return (0xffffffff - val + 1) * -1;
- }
- Buffer.prototype.readInt32LE = function(offset, noAssert) {
- return readInt32(this, offset, false, noAssert);
- };
- Buffer.prototype.readInt32BE = function(offset, noAssert) {
- return readInt32(this, offset, true, noAssert);
- };
- function readFloat(buffer, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
- 23, 4);
- }
- Buffer.prototype.readFloatLE = function(offset, noAssert) {
- return readFloat(this, offset, false, noAssert);
- };
- Buffer.prototype.readFloatBE = function(offset, noAssert) {
- return readFloat(this, offset, true, noAssert);
- };
- function readDouble(buffer, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset + 7 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
- 52, 8);
- }
- Buffer.prototype.readDoubleLE = function(offset, noAssert) {
- return readDouble(this, offset, false, noAssert);
- };
- Buffer.prototype.readDoubleBE = function(offset, noAssert) {
- return readDouble(this, offset, true, noAssert);
- };
- /*
- * We have to make sure that the value is a valid integer. This means that it is
- * non-negative. It has no fractional component and that it does not exceed the
- * maximum allowed value.
- *
- * value The number to check for validity
- *
- * max The maximum value
- */
- function verifuint(value, max) {
- assert.ok(typeof (value) == 'number',
- 'cannot write a non-number as a number');
- assert.ok(value >= 0,
- 'specified a negative value for writing an unsigned value');
- assert.ok(value <= max, 'value is larger than maximum value for type');
- assert.ok(Math.floor(value) === value, 'value has a fractional component');
- }
- Buffer.prototype.writeUInt8 = function(value, offset, noAssert) {
- var buffer = this;
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset < buffer.length,
- 'trying to write beyond buffer length');
- verifuint(value, 0xff);
- }
- if (offset < buffer.length) {
- buffer.parent[buffer.offset + offset] = value;
- }
- };
- function writeUInt16(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 1 < buffer.length,
- 'trying to write beyond buffer length');
- verifuint(value, 0xffff);
- }
- for (var i = 0; i < Math.min(buffer.length - offset, 2); i++) {
- buffer.parent[buffer.offset + offset + i] =
- (value & (0xff << (8 * (isBigEndian ? 1 - i : i)))) >>>
- (isBigEndian ? 1 - i : i) * 8;
- }
- }
- Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) {
- writeUInt16(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) {
- writeUInt16(this, value, offset, true, noAssert);
- };
- function writeUInt32(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'trying to write beyond buffer length');
- verifuint(value, 0xffffffff);
- }
- for (var i = 0; i < Math.min(buffer.length - offset, 4); i++) {
- buffer.parent[buffer.offset + offset + i] =
- (value >>> (isBigEndian ? 3 - i : i) * 8) & 0xff;
- }
- }
- Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) {
- writeUInt32(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) {
- writeUInt32(this, value, offset, true, noAssert);
- };
- /*
- * We now move onto our friends in the signed number category. Unlike unsigned
- * numbers, we're going to have to worry a bit more about how we put values into
- * arrays. Since we are only worrying about signed 32-bit values, we're in
- * slightly better shape. Unfortunately, we really can't do our favorite binary
- * & in this system. It really seems to do the wrong thing. For example:
- *
- * > -32 & 0xff
- * 224
- *
- * What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of
- * this aren't treated as a signed number. Ultimately a bad thing.
- *
- * What we're going to want to do is basically create the unsigned equivalent of
- * our representation and pass that off to the wuint* functions. To do that
- * we're going to do the following:
- *
- * - if the value is positive
- * we can pass it directly off to the equivalent wuint
- * - if the value is negative
- * we do the following computation:
- * mb + val + 1, where
- * mb is the maximum unsigned value in that byte size
- * val is the Javascript negative integer
- *
- *
- * As a concrete value, take -128. In signed 16 bits this would be 0xff80. If
- * you do out the computations:
- *
- * 0xffff - 128 + 1
- * 0xffff - 127
- * 0xff80
- *
- * You can then encode this value as the signed version. This is really rather
- * hacky, but it should work and get the job done which is our goal here.
- */
- /*
- * A series of checks to make sure we actually have a signed 32-bit number
- */
- function verifsint(value, max, min) {
- assert.ok(typeof (value) == 'number',
- 'cannot write a non-number as a number');
- assert.ok(value <= max, 'value larger than maximum allowed value');
- assert.ok(value >= min, 'value smaller than minimum allowed value');
- assert.ok(Math.floor(value) === value, 'value has a fractional component');
- }
- function verifIEEE754(value, max, min) {
- assert.ok(typeof (value) == 'number',
- 'cannot write a non-number as a number');
- assert.ok(value <= max, 'value larger than maximum allowed value');
- assert.ok(value >= min, 'value smaller than minimum allowed value');
- }
- Buffer.prototype.writeInt8 = function(value, offset, noAssert) {
- var buffer = this;
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset < buffer.length,
- 'Trying to write beyond buffer length');
- verifsint(value, 0x7f, -0x80);
- }
- if (value >= 0) {
- buffer.writeUInt8(value, offset, noAssert);
- } else {
- buffer.writeUInt8(0xff + value + 1, offset, noAssert);
- }
- };
- function writeInt16(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 1 < buffer.length,
- 'Trying to write beyond buffer length');
- verifsint(value, 0x7fff, -0x8000);
- }
- if (value >= 0) {
- writeUInt16(buffer, value, offset, isBigEndian, noAssert);
- } else {
- writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert);
- }
- }
- Buffer.prototype.writeInt16LE = function(value, offset, noAssert) {
- writeInt16(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeInt16BE = function(value, offset, noAssert) {
- writeInt16(this, value, offset, true, noAssert);
- };
- function writeInt32(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to write beyond buffer length');
- verifsint(value, 0x7fffffff, -0x80000000);
- }
- if (value >= 0) {
- writeUInt32(buffer, value, offset, isBigEndian, noAssert);
- } else {
- writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert);
- }
- }
- Buffer.prototype.writeInt32LE = function(value, offset, noAssert) {
- writeInt32(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {
- writeInt32(this, value, offset, true, noAssert);
- };
- function writeFloat(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to write beyond buffer length');
- verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38);
- }
- require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
- 23, 4);
- }
- Buffer.prototype.writeFloatLE = function(value, offset, noAssert) {
- writeFloat(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeFloatBE = function(value, offset, noAssert) {
- writeFloat(this, value, offset, true, noAssert);
- };
- function writeDouble(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 7 < buffer.length,
- 'Trying to write beyond buffer length');
- verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308);
- }
- require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
- 52, 8);
- }
- Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) {
- writeDouble(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) {
- writeDouble(this, value, offset, true, noAssert);
- };
- SlowBuffer.prototype.readUInt8 = Buffer.prototype.readUInt8;
- SlowBuffer.prototype.readUInt16LE = Buffer.prototype.readUInt16LE;
- SlowBuffer.prototype.readUInt16BE = Buffer.prototype.readUInt16BE;
- SlowBuffer.prototype.readUInt32LE = Buffer.prototype.readUInt32LE;
- SlowBuffer.prototype.readUInt32BE = Buffer.prototype.readUInt32BE;
- SlowBuffer.prototype.readInt8 = Buffer.prototype.readInt8;
- SlowBuffer.prototype.readInt16LE = Buffer.prototype.readInt16LE;
- SlowBuffer.prototype.readInt16BE = Buffer.prototype.readInt16BE;
- SlowBuffer.prototype.readInt32LE = Buffer.prototype.readInt32LE;
- SlowBuffer.prototype.readInt32BE = Buffer.prototype.readInt32BE;
- SlowBuffer.prototype.readFloatLE = Buffer.prototype.readFloatLE;
- SlowBuffer.prototype.readFloatBE = Buffer.prototype.readFloatBE;
- SlowBuffer.prototype.readDoubleLE = Buffer.prototype.readDoubleLE;
- SlowBuffer.prototype.readDoubleBE = Buffer.prototype.readDoubleBE;
- SlowBuffer.prototype.writeUInt8 = Buffer.prototype.writeUInt8;
- SlowBuffer.prototype.writeUInt16LE = Buffer.prototype.writeUInt16LE;
- SlowBuffer.prototype.writeUInt16BE = Buffer.prototype.writeUInt16BE;
- SlowBuffer.prototype.writeUInt32LE = Buffer.prototype.writeUInt32LE;
- SlowBuffer.prototype.writeUInt32BE = Buffer.prototype.writeUInt32BE;
- SlowBuffer.prototype.writeInt8 = Buffer.prototype.writeInt8;
- SlowBuffer.prototype.writeInt16LE = Buffer.prototype.writeInt16LE;
- SlowBuffer.prototype.writeInt16BE = Buffer.prototype.writeInt16BE;
- SlowBuffer.prototype.writeInt32LE = Buffer.prototype.writeInt32LE;
- SlowBuffer.prototype.writeInt32BE = Buffer.prototype.writeInt32BE;
- SlowBuffer.prototype.writeFloatLE = Buffer.prototype.writeFloatLE;
- SlowBuffer.prototype.writeFloatBE = Buffer.prototype.writeFloatBE;
- SlowBuffer.prototype.writeDoubleLE = Buffer.prototype.writeDoubleLE;
- SlowBuffer.prototype.writeDoubleBE = Buffer.prototype.writeDoubleBE;
- },{"assert":1,"./buffer_ieee754":5,"base64-js":7}],7:[function(require,module,exports){
- (function (exports) {
- 'use strict';
- var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
- function b64ToByteArray(b64) {
- var i, j, l, tmp, placeHolders, arr;
-
- if (b64.length % 4 > 0) {
- throw 'Invalid string. Length must be a multiple of 4';
- }
- // the number of equal signs (place holders)
- // if there are two placeholders, than the two characters before it
- // represent one byte
- // if there is only one, then the three characters before it represent 2 bytes
- // this is just a cheap hack to not do indexOf twice
- placeHolders = b64.indexOf('=');
- placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0;
- // base64 is 4/3 + up to two characters of the original data
- arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders);
- // if there are placeholders, only get up to the last complete 4 chars
- l = placeHolders > 0 ? b64.length - 4 : b64.length;
- for (i = 0, j = 0; i < l; i += 4, j += 3) {
- tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]);
- arr.push((tmp & 0xFF0000) >> 16);
- arr.push((tmp & 0xFF00) >> 8);
- arr.push(tmp & 0xFF);
- }
- if (placeHolders === 2) {
- tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4);
- arr.push(tmp & 0xFF);
- } else if (placeHolders === 1) {
- tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2);
- arr.push((tmp >> 8) & 0xFF);
- arr.push(tmp & 0xFF);
- }
- return arr;
- }
- function uint8ToBase64(uint8) {
- var i,
- extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
- output = "",
- temp, length;
- function tripletToBase64 (num) {
- return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
- };
- // go through the array every three bytes, we'll deal with trailing stuff later
- for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
- temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
- output += tripletToBase64(temp);
- }
- // pad the end with zeros, but make sure to not forget the extra bytes
- switch (extraBytes) {
- case 1:
- temp = uint8[uint8.length - 1];
- output += lookup[temp >> 2];
- output += lookup[(temp << 4) & 0x3F];
- output += '==';
- break;
- case 2:
- temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]);
- output += lookup[temp >> 10];
- output += lookup[(temp >> 4) & 0x3F];
- output += lookup[(temp << 2) & 0x3F];
- output += '=';
- break;
- }
- return output;
- }
- module.exports.toByteArray = b64ToByteArray;
- module.exports.fromByteArray = uint8ToBase64;
- }());
- },{}],8:[function(require,module,exports){
- exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) {
- var e, m,
- eLen = nBytes * 8 - mLen - 1,
- eMax = (1 << eLen) - 1,
- eBias = eMax >> 1,
- nBits = -7,
- i = isBE ? 0 : (nBytes - 1),
- d = isBE ? 1 : -1,
- s = buffer[offset + i];
- i += d;
- e = s & ((1 << (-nBits)) - 1);
- s >>= (-nBits);
- nBits += eLen;
- for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
- m = e & ((1 << (-nBits)) - 1);
- e >>= (-nBits);
- nBits += mLen;
- for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
- if (e === 0) {
- e = 1 - eBias;
- } else if (e === eMax) {
- return m ? NaN : ((s ? -1 : 1) * Infinity);
- } else {
- m = m + Math.pow(2, mLen);
- e = e - eBias;
- }
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
- };
- exports.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) {
- var e, m, c,
- eLen = nBytes * 8 - mLen - 1,
- eMax = (1 << eLen) - 1,
- eBias = eMax >> 1,
- rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
- i = isBE ? (nBytes - 1) : 0,
- d = isBE ? -1 : 1,
- s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
- value = Math.abs(value);
- if (isNaN(value) || value === Infinity) {
- m = isNaN(value) ? 1 : 0;
- e = eMax;
- } else {
- e = Math.floor(Math.log(value) / Math.LN2);
- if (value * (c = Math.pow(2, -e)) < 1) {
- e--;
- c *= 2;
- }
- if (e + eBias >= 1) {
- value += rt / c;
- } else {
- value += rt * Math.pow(2, 1 - eBias);
- }
- if (value * c >= 2) {
- e++;
- c /= 2;
- }
- if (e + eBias >= eMax) {
- m = 0;
- e = eMax;
- } else if (e + eBias >= 1) {
- m = (value * c - 1) * Math.pow(2, mLen);
- e = e + eBias;
- } else {
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
- e = 0;
- }
- }
- for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
- e = (e << mLen) | m;
- eLen += mLen;
- for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
- buffer[offset + i - d] |= s * 128;
- };
- },{}],3:[function(require,module,exports){
- function SlowBuffer (size) {
- this.length = size;
- };
- var assert = require('assert');
- exports.INSPECT_MAX_BYTES = 50;
- function toHex(n) {
- if (n < 16) return '0' + n.toString(16);
- return n.toString(16);
- }
- function utf8ToBytes(str) {
- var byteArray = [];
- for (var i = 0; i < str.length; i++)
- if (str.charCodeAt(i) <= 0x7F)
- byteArray.push(str.charCodeAt(i));
- else {
- var h = encodeURIComponent(str.charAt(i)).substr(1).split('%');
- for (var j = 0; j < h.length; j++)
- byteArray.push(parseInt(h[j], 16));
- }
- return byteArray;
- }
- function asciiToBytes(str) {
- var byteArray = []
- for (var i = 0; i < str.length; i++ )
- // Node's code seems to be doing this and not & 0x7F..
- byteArray.push( str.charCodeAt(i) & 0xFF );
- return byteArray;
- }
- function base64ToBytes(str) {
- return require("base64-js").toByteArray(str);
- }
- SlowBuffer.byteLength = function (str, encoding) {
- switch (encoding || "utf8") {
- case 'hex':
- return str.length / 2;
- case 'utf8':
- case 'utf-8':
- return utf8ToBytes(str).length;
- case 'ascii':
- return str.length;
- case 'base64':
- return base64ToBytes(str).length;
- default:
- throw new Error('Unknown encoding');
- }
- };
- function blitBuffer(src, dst, offset, length) {
- var pos, i = 0;
- while (i < length) {
- if ((i+offset >= dst.length) || (i >= src.length))
- break;
- dst[i + offset] = src[i];
- i++;
- }
- return i;
- }
- SlowBuffer.prototype.utf8Write = function (string, offset, length) {
- var bytes, pos;
- return SlowBuffer._charsWritten = blitBuffer(utf8ToBytes(string), this, offset, length);
- };
- SlowBuffer.prototype.asciiWrite = function (string, offset, length) {
- var bytes, pos;
- return SlowBuffer._charsWritten = blitBuffer(asciiToBytes(string), this, offset, length);
- };
- SlowBuffer.prototype.base64Write = function (string, offset, length) {
- var bytes, pos;
- return SlowBuffer._charsWritten = blitBuffer(base64ToBytes(string), this, offset, length);
- };
- SlowBuffer.prototype.base64Slice = function (start, end) {
- var bytes = Array.prototype.slice.apply(this, arguments)
- return require("base64-js").fromByteArray(bytes);
- }
- function decodeUtf8Char(str) {
- try {
- return decodeURIComponent(str);
- } catch (err) {
- return String.fromCharCode(0xFFFD); // UTF 8 invalid char
- }
- }
- SlowBuffer.prototype.utf8Slice = function () {
- var bytes = Array.prototype.slice.apply(this, arguments);
- var res = "";
- var tmp = "";
- var i = 0;
- while (i < bytes.length) {
- if (bytes[i] <= 0x7F) {
- res += decodeUtf8Char(tmp) + String.fromCharCode(bytes[i]);
- tmp = "";
- } else
- tmp += "%" + bytes[i].toString(16);
- i++;
- }
- return res + decodeUtf8Char(tmp);
- }
- SlowBuffer.prototype.asciiSlice = function () {
- var bytes = Array.prototype.slice.apply(this, arguments);
- var ret = "";
- for (var i = 0; i < bytes.length; i++)
- ret += String.fromCharCode(bytes[i]);
- return ret;
- }
- SlowBuffer.prototype.inspect = function() {
- var out = [],
- len = this.length;
- for (var i = 0; i < len; i++) {
- out[i] = toHex(this[i]);
- if (i == exports.INSPECT_MAX_BYTES) {
- out[i + 1] = '...';
- break;
- }
- }
- return '<SlowBuffer ' + out.join(' ') + '>';
- };
- SlowBuffer.prototype.hexSlice = function(start, end) {
- var len = this.length;
- if (!start || start < 0) start = 0;
- if (!end || end < 0 || end > len) end = len;
- var out = '';
- for (var i = start; i < end; i++) {
- out += toHex(this[i]);
- }
- return out;
- };
- SlowBuffer.prototype.toString = function(encoding, start, end) {
- encoding = String(encoding || 'utf8').toLowerCase();
- start = +start || 0;
- if (typeof end == 'undefined') end = this.length;
- // Fastpath empty strings
- if (+end == start) {
- return '';
- }
- switch (encoding) {
- case 'hex':
- return this.hexSlice(start, end);
- case 'utf8':
- case 'utf-8':
- return this.utf8Slice(start, end);
- case 'ascii':
- return this.asciiSlice(start, end);
- case 'binary':
- return this.binarySlice(start, end);
- case 'base64':
- return this.base64Slice(start, end);
- case 'ucs2':
- case 'ucs-2':
- return this.ucs2Slice(start, end);
- default:
- throw new Error('Unknown encoding');
- }
- };
- SlowBuffer.prototype.hexWrite = function(string, offset, length) {
- offset = +offset || 0;
- var remaining = this.length - offset;
- if (!length) {
- length = remaining;
- } else {
- length = +length;
- if (length > remaining) {
- length = remaining;
- }
- }
- // must be an even number of digits
- var strLen = string.length;
- if (strLen % 2) {
- throw new Error('Invalid hex string');
- }
- if (length > strLen / 2) {
- length = strLen / 2;
- }
- for (var i = 0; i < length; i++) {
- var byte = parseInt(string.substr(i * 2, 2), 16);
- if (isNaN(byte)) throw new Error('Invalid hex string');
- this[offset + i] = byte;
- }
- SlowBuffer._charsWritten = i * 2;
- return i;
- };
- SlowBuffer.prototype.write = function(string, offset, length, encoding) {
- // Support both (string, offset, length, encoding)
- // and the legacy (string, encoding, offset, length)
- if (isFinite(offset)) {
- if (!isFinite(length)) {
- encoding = length;
- length = undefined;
- }
- } else { // legacy
- var swap = encoding;
- encoding = offset;
- offset = length;
- length = swap;
- }
- offset = +offset || 0;
- var remaining = this.length - offset;
- if (!length) {
- length = remaining;
- } else {
- length = +length;
- if (length > remaining) {
- length = remaining;
- }
- }
- encoding = String(encoding || 'utf8').toLowerCase();
- switch (encoding) {
- case 'hex':
- return this.hexWrite(string, offset, length);
- case 'utf8':
- case 'utf-8':
- return this.utf8Write(string, offset, length);
- case 'ascii':
- return this.asciiWrite(string, offset, length);
- case 'binary':
- return this.binaryWrite(string, offset, length);
- case 'base64':
- return this.base64Write(string, offset, length);
- case 'ucs2':
- case 'ucs-2':
- return this.ucs2Write(string, offset, length);
- default:
- throw new Error('Unknown encoding');
- }
- };
- // slice(start, end)
- SlowBuffer.prototype.slice = function(start, end) {
- if (end === undefined) end = this.length;
- if (end > this.length) {
- throw new Error('oob');
- }
- if (start > end) {
- throw new Error('oob');
- }
- return new Buffer(this, end - start, +start);
- };
- SlowBuffer.prototype.copy = function(target, targetstart, sourcestart, sourceend) {
- var temp = [];
- for (var i=sourcestart; i<sourceend; i++) {
- assert.ok(typeof this[i] !== 'undefined', "copying undefined buffer bytes!");
- temp.push(this[i]);
- }
- for (var i=targetstart; i<targetstart+temp.length; i++) {
- target[i] = temp[i-targetstart];
- }
- };
- function coerce(length) {
- // Coerce length to a number (possibly NaN), round up
- // in case it's fractional (e.g. 123.456) then do a
- // double negate to coerce a NaN to 0. Easy, right?
- length = ~~Math.ceil(+length);
- return length < 0 ? 0 : length;
- }
- // Buffer
- function Buffer(subject, encoding, offset) {
- if (!(this instanceof Buffer)) {
- return new Buffer(subject, encoding, offset);
- }
- var type;
- // Are we slicing?
- if (typeof offset === 'number') {
- this.length = coerce(encoding);
- this.parent = subject;
- this.offset = offset;
- } else {
- // Find the length
- switch (type = typeof subject) {
- case 'number':
- this.length = coerce(subject);
- break;
- case 'string':
- this.length = Buffer.byteLength(subject, encoding);
- break;
- case 'object': // Assume object is an array
- this.length = coerce(subject.length);
- break;
- default:
- throw new Error('First argument needs to be a number, ' +
- 'array or string.');
- }
- if (this.length > Buffer.poolSize) {
- // Big buffer, just alloc one.
- this.parent = new SlowBuffer(this.length);
- this.offset = 0;
- } else {
- // Small buffer.
- if (!pool || pool.length - pool.used < this.length) allocPool();
- this.parent = pool;
- this.offset = pool.used;
- pool.used += this.length;
- }
- // Treat array-ish objects as a byte array.
- if (isArrayIsh(subject)) {
- for (var i = 0; i < this.length; i++) {
- this.parent[i + this.offset] = subject[i];
- }
- } else if (type == 'string') {
- // We are a string
- this.length = this.write(subject, 0, encoding);
- }
- }
- }
- function isArrayIsh(subject) {
- return Array.isArray(subject) || Buffer.isBuffer(subject) ||
- subject && typeof subject === 'object' &&
- typeof subject.length === 'number';
- }
- exports.SlowBuffer = SlowBuffer;
- exports.Buffer = Buffer;
- Buffer.poolSize = 8 * 1024;
- var pool;
- function allocPool() {
- pool = new SlowBuffer(Buffer.poolSize);
- pool.used = 0;
- }
- // Static methods
- Buffer.isBuffer = function isBuffer(b) {
- return b instanceof Buffer || b instanceof SlowBuffer;
- };
- Buffer.concat = function (list, totalLength) {
- if (!Array.isArray(list)) {
- throw new Error("Usage: Buffer.concat(list, [totalLength])\n \
- list should be an Array.");
- }
- if (list.length === 0) {
- return new Buffer(0);
- } else if (list.length === 1) {
- return list[0];
- }
- if (typeof totalLength !== 'number') {
- totalLength = 0;
- for (var i = 0; i < list.length; i++) {
- var buf = list[i];
- totalLength += buf.length;
- }
- }
- var buffer = new Buffer(totalLength);
- var pos = 0;
- for (var i = 0; i < list.length; i++) {
- var buf = list[i];
- buf.copy(buffer, pos);
- pos += buf.length;
- }
- return buffer;
- };
- // Inspect
- Buffer.prototype.inspect = function inspect() {
- var out = [],
- len = this.length;
- for (var i = 0; i < len; i++) {
- out[i] = toHex(this.parent[i + this.offset]);
- if (i == exports.INSPECT_MAX_BYTES) {
- out[i + 1] = '...';
- break;
- }
- }
- return '<Buffer ' + out.join(' ') + '>';
- };
- Buffer.prototype.get = function get(i) {
- if (i < 0 || i >= this.length) throw new Error('oob');
- return this.parent[this.offset + i];
- };
- Buffer.prototype.set = function set(i, v) {
- if (i < 0 || i >= this.length) throw new Error('oob');
- return this.parent[this.offset + i] = v;
- };
- // write(string, offset = 0, length = buffer.length-offset, encoding = 'utf8')
- Buffer.prototype.write = function(string, offset, length, encoding) {
- // Support both (string, offset, length, encoding)
- // and the legacy (string, encoding, offset, length)
- if (isFinite(offset)) {
- if (!isFinite(length)) {
- encoding = length;
- length = undefined;
- }
- } else { // legacy
- var swap = encoding;
- encoding = offset;
- offset = length;
- length = swap;
- }
- offset = +offset || 0;
- var remaining = this.length - offset;
- if (!length) {
- length = remaining;
- } else {
- length = +length;
- if (length > remaining) {
- length = remaining;
- }
- }
- encoding = String(encoding || 'utf8').toLowerCase();
- var ret;
- switch (encoding) {
- case 'hex':
- ret = this.parent.hexWrite(string, this.offset + offset, length);
- break;
- case 'utf8':
- case 'utf-8':
- ret = this.parent.utf8Write(string, this.offset + offset, length);
- break;
- case 'ascii':
- ret = this.parent.asciiWrite(string, this.offset + offset, length);
- break;
- case 'binary':
- ret = this.parent.binaryWrite(string, this.offset + offset, length);
- break;
- case 'base64':
- // Warning: maxLength not taken into account in base64Write
- ret = this.parent.base64Write(string, this.offset + offset, length);
- break;
- case 'ucs2':
- case 'ucs-2':
- ret = this.parent.ucs2Write(string, this.offset + offset, length);
- break;
- default:
- throw new Error('Unknown encoding');
- }
- Buffer._charsWritten = SlowBuffer._charsWritten;
- return ret;
- };
- // toString(encoding, start=0, end=buffer.length)
- Buffer.prototype.toString = function(encoding, start, end) {
- encoding = String(encoding || 'utf8').toLowerCase();
- if (typeof start == 'undefined' || start < 0) {
- start = 0;
- } else if (start > this.length) {
- start = this.length;
- }
- if (typeof end == 'undefined' || end > this.length) {
- end = this.length;
- } else if (end < 0) {
- end = 0;
- }
- start = start + this.offset;
- end = end + this.offset;
- switch (encoding) {
- case 'hex':
- return this.parent.hexSlice(start, end);
- case 'utf8':
- case 'utf-8':
- return this.parent.utf8Slice(start, end);
- case 'ascii':
- return this.parent.asciiSlice(start, end);
- case 'binary':
- return this.parent.binarySlice(start, end);
- case 'base64':
- return this.parent.base64Slice(start, end);
- case 'ucs2':
- case 'ucs-2':
- return this.parent.ucs2Slice(start, end);
- default:
- throw new Error('Unknown encoding');
- }
- };
- // byteLength
- Buffer.byteLength = SlowBuffer.byteLength;
- // fill(value, start=0, end=buffer.length)
- Buffer.prototype.fill = function fill(value, start, end) {
- value || (value = 0);
- start || (start = 0);
- end || (end = this.length);
- if (typeof value === 'string') {
- value = value.charCodeAt(0);
- }
- if (!(typeof value === 'number') || isNaN(value)) {
- throw new Error('value is not a number');
- }
- if (end < start) throw new Error('end < start');
- // Fill 0 bytes; we're done
- if (end === start) return 0;
- if (this.length == 0) return 0;
- if (start < 0 || start >= this.length) {
- throw new Error('start out of bounds');
- }
- if (end < 0 || end > this.length) {
- throw new Error('end out of bounds');
- }
- return this.parent.fill(value,
- start + this.offset,
- end + this.offset);
- };
- // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
- Buffer.prototype.copy = function(target, target_start, start, end) {
- var source = this;
- start || (start = 0);
- end || (end = this.length);
- target_start || (target_start = 0);
- if (end < start) throw new Error('sourceEnd < sourceStart');
- // Copy 0 bytes; we're done
- if (end === start) return 0;
- if (target.length == 0 || source.length == 0) return 0;
- if (target_start < 0 || target_start >= target.length) {
- throw new Error('targetStart out of bounds');
- }
- if (start < 0 || start >= source.length) {
- throw new Error('sourceStart out of bounds');
- }
- if (end < 0 || end > source.length) {
- throw new Error('sourceEnd out of bounds');
- }
- // Are we oob?
- if (end > this.length) {
- end = this.length;
- }
- if (target.length - target_start < end - start) {
- end = target.length - target_start + start;
- }
- return this.parent.copy(target.parent,
- target_start + target.offset,
- start + this.offset,
- end + this.offset);
- };
- // slice(start, end)
- Buffer.prototype.slice = function(start, end) {
- if (end === undefined) end = this.length;
- if (end > this.length) throw new Error('oob');
- if (start > end) throw new Error('oob');
- return new Buffer(this.parent, end - start, +start + this.offset);
- };
- // Legacy methods for backwards compatibility.
- Buffer.prototype.utf8Slice = function(start, end) {
- return this.toString('utf8', start, end);
- };
- Buffer.prototype.binarySlice = function(start, end) {
- return this.toString('binary', start, end);
- };
- Buffer.prototype.asciiSlice = function(start, end) {
- return this.toString('ascii', start, end);
- };
- Buffer.prototype.utf8Write = function(string, offset) {
- return this.write(string, offset, 'utf8');
- };
- Buffer.prototype.binaryWrite = function(string, offset) {
- return this.write(string, offset, 'binary');
- };
- Buffer.prototype.asciiWrite = function(string, offset) {
- return this.write(string, offset, 'ascii');
- };
- Buffer.prototype.readUInt8 = function(offset, noAssert) {
- var buffer = this;
- if (!noAssert) {
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset < buffer.length,
- 'Trying to read beyond buffer length');
- }
- return buffer.parent[buffer.offset + offset];
- };
- function readUInt16(buffer, offset, isBigEndian, noAssert) {
- var val = 0;
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 1 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- if (isBigEndian) {
- val = buffer.parent[buffer.offset + offset] << 8;
- val |= buffer.parent[buffer.offset + offset + 1];
- } else {
- val = buffer.parent[buffer.offset + offset];
- val |= buffer.parent[buffer.offset + offset + 1] << 8;
- }
- return val;
- }
- Buffer.prototype.readUInt16LE = function(offset, noAssert) {
- return readUInt16(this, offset, false, noAssert);
- };
- Buffer.prototype.readUInt16BE = function(offset, noAssert) {
- return readUInt16(this, offset, true, noAssert);
- };
- function readUInt32(buffer, offset, isBigEndian, noAssert) {
- var val = 0;
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- if (isBigEndian) {
- val = buffer.parent[buffer.offset + offset + 1] << 16;
- val |= buffer.parent[buffer.offset + offset + 2] << 8;
- val |= buffer.parent[buffer.offset + offset + 3];
- val = val + (buffer.parent[buffer.offset + offset] << 24 >>> 0);
- } else {
- val = buffer.parent[buffer.offset + offset + 2] << 16;
- val |= buffer.parent[buffer.offset + offset + 1] << 8;
- val |= buffer.parent[buffer.offset + offset];
- val = val + (buffer.parent[buffer.offset + offset + 3] << 24 >>> 0);
- }
- return val;
- }
- Buffer.prototype.readUInt32LE = function(offset, noAssert) {
- return readUInt32(this, offset, false, noAssert);
- };
- Buffer.prototype.readUInt32BE = function(offset, noAssert) {
- return readUInt32(this, offset, true, noAssert);
- };
- /*
- * Signed integer types, yay team! A reminder on how two's complement actually
- * works. The first bit is the signed bit, i.e. tells us whether or not the
- * number should be positive or negative. If the two's complement value is
- * positive, then we're done, as it's equivalent to the unsigned representation.
- *
- * Now if the number is positive, you're pretty much done, you can just leverage
- * the unsigned translations and return those. Unfortunately, negative numbers
- * aren't quite that straightforward.
- *
- * At first glance, one might be inclined to use the traditional formula to
- * translate binary numbers between the positive and negative values in two's
- * complement. (Though it doesn't quite work for the most negative value)
- * Mainly:
- * - invert all the bits
- * - add one to the result
- *
- * Of course, this doesn't quite work in Javascript. Take for example the value
- * of -128. This could be represented in 16 bits (big-endian) as 0xff80. But of
- * course, Javascript will do the following:
- *
- * > ~0xff80
- * -65409
- *
- * Whoh there, Javascript, that's not quite right. But wait, according to
- * Javascript that's perfectly correct. When Javascript ends up seeing the
- * constant 0xff80, it has no notion that it is actually a signed number. It
- * assumes that we've input the unsigned value 0xff80. Thus, when it does the
- * binary negation, it casts it into a signed value, (positive 0xff80). Then
- * when you perform binary negation on that, it turns it into a negative number.
- *
- * Instead, we're going to have to use the following general formula, that works
- * in a rather Javascript friendly way. I'm glad we don't support this kind of
- * weird numbering scheme in the kernel.
- *
- * (BIT-MAX - (unsigned)val + 1) * -1
- *
- * The astute observer, may think that this doesn't make sense for 8-bit numbers
- * (really it isn't necessary for them). However, when you get 16-bit numbers,
- * you do. Let's go back to our prior example and see how this will look:
- *
- * (0xffff - 0xff80 + 1) * -1
- * (0x007f + 1) * -1
- * (0x0080) * -1
- */
- Buffer.prototype.readInt8 = function(offset, noAssert) {
- var buffer = this;
- var neg;
- if (!noAssert) {
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset < buffer.length,
- 'Trying to read beyond buffer length');
- }
- neg = buffer.parent[buffer.offset + offset] & 0x80;
- if (!neg) {
- return (buffer.parent[buffer.offset + offset]);
- }
- return ((0xff - buffer.parent[buffer.offset + offset] + 1) * -1);
- };
- function readInt16(buffer, offset, isBigEndian, noAssert) {
- var neg, val;
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 1 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- val = readUInt16(buffer, offset, isBigEndian, noAssert);
- neg = val & 0x8000;
- if (!neg) {
- return val;
- }
- return (0xffff - val + 1) * -1;
- }
- Buffer.prototype.readInt16LE = function(offset, noAssert) {
- return readInt16(this, offset, false, noAssert);
- };
- Buffer.prototype.readInt16BE = function(offset, noAssert) {
- return readInt16(this, offset, true, noAssert);
- };
- function readInt32(buffer, offset, isBigEndian, noAssert) {
- var neg, val;
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- val = readUInt32(buffer, offset, isBigEndian, noAssert);
- neg = val & 0x80000000;
- if (!neg) {
- return (val);
- }
- return (0xffffffff - val + 1) * -1;
- }
- Buffer.prototype.readInt32LE = function(offset, noAssert) {
- return readInt32(this, offset, false, noAssert);
- };
- Buffer.prototype.readInt32BE = function(offset, noAssert) {
- return readInt32(this, offset, true, noAssert);
- };
- function readFloat(buffer, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
- 23, 4);
- }
- Buffer.prototype.readFloatLE = function(offset, noAssert) {
- return readFloat(this, offset, false, noAssert);
- };
- Buffer.prototype.readFloatBE = function(offset, noAssert) {
- return readFloat(this, offset, true, noAssert);
- };
- function readDouble(buffer, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset + 7 < buffer.length,
- 'Trying to read beyond buffer length');
- }
- return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
- 52, 8);
- }
- Buffer.prototype.readDoubleLE = function(offset, noAssert) {
- return readDouble(this, offset, false, noAssert);
- };
- Buffer.prototype.readDoubleBE = function(offset, noAssert) {
- return readDouble(this, offset, true, noAssert);
- };
- /*
- * We have to make sure that the value is a valid integer. This means that it is
- * non-negative. It has no fractional component and that it does not exceed the
- * maximum allowed value.
- *
- * value The number to check for validity
- *
- * max The maximum value
- */
- function verifuint(value, max) {
- assert.ok(typeof (value) == 'number',
- 'cannot write a non-number as a number');
- assert.ok(value >= 0,
- 'specified a negative value for writing an unsigned value');
- assert.ok(value <= max, 'value is larger than maximum value for type');
- assert.ok(Math.floor(value) === value, 'value has a fractional component');
- }
- Buffer.prototype.writeUInt8 = function(value, offset, noAssert) {
- var buffer = this;
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset < buffer.length,
- 'trying to write beyond buffer length');
- verifuint(value, 0xff);
- }
- buffer.parent[buffer.offset + offset] = value;
- };
- function writeUInt16(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 1 < buffer.length,
- 'trying to write beyond buffer length');
- verifuint(value, 0xffff);
- }
- if (isBigEndian) {
- buffer.parent[buffer.offset + offset] = (value & 0xff00) >>> 8;
- buffer.parent[buffer.offset + offset + 1] = value & 0x00ff;
- } else {
- buffer.parent[buffer.offset + offset + 1] = (value & 0xff00) >>> 8;
- buffer.parent[buffer.offset + offset] = value & 0x00ff;
- }
- }
- Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) {
- writeUInt16(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) {
- writeUInt16(this, value, offset, true, noAssert);
- };
- function writeUInt32(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'trying to write beyond buffer length');
- verifuint(value, 0xffffffff);
- }
- if (isBigEndian) {
- buffer.parent[buffer.offset + offset] = (value >>> 24) & 0xff;
- buffer.parent[buffer.offset + offset + 1] = (value >>> 16) & 0xff;
- buffer.parent[buffer.offset + offset + 2] = (value >>> 8) & 0xff;
- buffer.parent[buffer.offset + offset + 3] = value & 0xff;
- } else {
- buffer.parent[buffer.offset + offset + 3] = (value >>> 24) & 0xff;
- buffer.parent[buffer.offset + offset + 2] = (value >>> 16) & 0xff;
- buffer.parent[buffer.offset + offset + 1] = (value >>> 8) & 0xff;
- buffer.parent[buffer.offset + offset] = value & 0xff;
- }
- }
- Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) {
- writeUInt32(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) {
- writeUInt32(this, value, offset, true, noAssert);
- };
- /*
- * We now move onto our friends in the signed number category. Unlike unsigned
- * numbers, we're going to have to worry a bit more about how we put values into
- * arrays. Since we are only worrying about signed 32-bit values, we're in
- * slightly better shape. Unfortunately, we really can't do our favorite binary
- * & in this system. It really seems to do the wrong thing. For example:
- *
- * > -32 & 0xff
- * 224
- *
- * What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of
- * this aren't treated as a signed number. Ultimately a bad thing.
- *
- * What we're going to want to do is basically create the unsigned equivalent of
- * our representation and pass that off to the wuint* functions. To do that
- * we're going to do the following:
- *
- * - if the value is positive
- * we can pass it directly off to the equivalent wuint
- * - if the value is negative
- * we do the following computation:
- * mb + val + 1, where
- * mb is the maximum unsigned value in that byte size
- * val is the Javascript negative integer
- *
- *
- * As a concrete value, take -128. In signed 16 bits this would be 0xff80. If
- * you do out the computations:
- *
- * 0xffff - 128 + 1
- * 0xffff - 127
- * 0xff80
- *
- * You can then encode this value as the signed version. This is really rather
- * hacky, but it should work and get the job done which is our goal here.
- */
- /*
- * A series of checks to make sure we actually have a signed 32-bit number
- */
- function verifsint(value, max, min) {
- assert.ok(typeof (value) == 'number',
- 'cannot write a non-number as a number');
- assert.ok(value <= max, 'value larger than maximum allowed value');
- assert.ok(value >= min, 'value smaller than minimum allowed value');
- assert.ok(Math.floor(value) === value, 'value has a fractional component');
- }
- function verifIEEE754(value, max, min) {
- assert.ok(typeof (value) == 'number',
- 'cannot write a non-number as a number');
- assert.ok(value <= max, 'value larger than maximum allowed value');
- assert.ok(value >= min, 'value smaller than minimum allowed value');
- }
- Buffer.prototype.writeInt8 = function(value, offset, noAssert) {
- var buffer = this;
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset < buffer.length,
- 'Trying to write beyond buffer length');
- verifsint(value, 0x7f, -0x80);
- }
- if (value >= 0) {
- buffer.writeUInt8(value, offset, noAssert);
- } else {
- buffer.writeUInt8(0xff + value + 1, offset, noAssert);
- }
- };
- function writeInt16(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 1 < buffer.length,
- 'Trying to write beyond buffer length');
- verifsint(value, 0x7fff, -0x8000);
- }
- if (value >= 0) {
- writeUInt16(buffer, value, offset, isBigEndian, noAssert);
- } else {
- writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert);
- }
- }
- Buffer.prototype.writeInt16LE = function(value, offset, noAssert) {
- writeInt16(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeInt16BE = function(value, offset, noAssert) {
- writeInt16(this, value, offset, true, noAssert);
- };
- function writeInt32(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to write beyond buffer length');
- verifsint(value, 0x7fffffff, -0x80000000);
- }
- if (value >= 0) {
- writeUInt32(buffer, value, offset, isBigEndian, noAssert);
- } else {
- writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert);
- }
- }
- Buffer.prototype.writeInt32LE = function(value, offset, noAssert) {
- writeInt32(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {
- writeInt32(this, value, offset, true, noAssert);
- };
- function writeFloat(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 3 < buffer.length,
- 'Trying to write beyond buffer length');
- verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38);
- }
- require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
- 23, 4);
- }
- Buffer.prototype.writeFloatLE = function(value, offset, noAssert) {
- writeFloat(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeFloatBE = function(value, offset, noAssert) {
- writeFloat(this, value, offset, true, noAssert);
- };
- function writeDouble(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
- assert.ok(offset + 7 < buffer.length,
- 'Trying to write beyond buffer length');
- verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308);
- }
- require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
- 52, 8);
- }
- Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) {
- writeDouble(this, value, offset, false, noAssert);
- };
- Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) {
- writeDouble(this, value, offset, true, noAssert);
- };
- SlowBuffer.prototype.readUInt8 = Buffer.prototype.readUInt8;
- SlowBuffer.prototype.readUInt16LE = Buffer.prototype.readUInt16LE;
- SlowBuffer.prototype.readUInt16BE = Buffer.prototype.readUInt16BE;
- SlowBuffer.prototype.readUInt32LE = Buffer.prototype.readUInt32LE;
- SlowBuffer.prototype.readUInt32BE = Buffer.prototype.readUInt32BE;
- SlowBuffer.prototype.readInt8 = Buffer.prototype.readInt8;
- SlowBuffer.prototype.readInt16LE = Buffer.prototype.readInt16LE;
- SlowBuffer.prototype.readInt16BE = Buffer.prototype.readInt16BE;
- SlowBuffer.prototype.readInt32LE = Buffer.prototype.readInt32LE;
- SlowBuffer.prototype.readInt32BE = Buffer.prototype.readInt32BE;
- SlowBuffer.prototype.readFloatLE = Buffer.prototype.readFloatLE;
- SlowBuffer.prototype.readFloatBE = Buffer.prototype.readFloatBE;
- SlowBuffer.prototype.readDoubleLE = Buffer.prototype.readDoubleLE;
- SlowBuffer.prototype.readDoubleBE = Buffer.prototype.readDoubleBE;
- SlowBuffer.prototype.writeUInt8 = Buffer.prototype.writeUInt8;
- SlowBuffer.prototype.writeUInt16LE = Buffer.prototype.writeUInt16LE;
- SlowBuffer.prototype.writeUInt16BE = Buffer.prototype.writeUInt16BE;
- SlowBuffer.prototype.writeUInt32LE = Buffer.prototype.writeUInt32LE;
- SlowBuffer.prototype.writeUInt32BE = Buffer.prototype.writeUInt32BE;
- SlowBuffer.prototype.writeInt8 = Buffer.prototype.writeInt8;
- SlowBuffer.prototype.writeInt16LE = Buffer.prototype.writeInt16LE;
- SlowBuffer.prototype.writeInt16BE = Buffer.prototype.writeInt16BE;
- SlowBuffer.prototype.writeInt32LE = Buffer.prototype.writeInt32LE;
- SlowBuffer.prototype.writeInt32BE = Buffer.prototype.writeInt32BE;
- SlowBuffer.prototype.writeFloatLE = Buffer.prototype.writeFloatLE;
- SlowBuffer.prototype.writeFloatBE = Buffer.prototype.writeFloatBE;
- SlowBuffer.prototype.writeDoubleLE = Buffer.prototype.writeDoubleLE;
- SlowBuffer.prototype.writeDoubleBE = Buffer.prototype.writeDoubleBE;
- },{"assert":1,"./buffer_ieee754":8,"base64-js":9}],9:[function(require,module,exports){
- (function (exports) {
- 'use strict';
- var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
- function b64ToByteArray(b64) {
- var i, j, l, tmp, placeHolders, arr;
-
- if (b64.length % 4 > 0) {
- throw 'Invalid string. Length must be a multiple of 4';
- }
- // the number of equal signs (place holders)
- // if there are two placeholders, than the two characters before it
- // represent one byte
- // if there is only one, then the three characters before it represent 2 bytes
- // this is just a cheap hack to not do indexOf twice
- placeHolders = b64.indexOf('=');
- placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0;
- // base64 is 4/3 + up to two characters of the original data
- arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders);
- // if there are placeholders, only get up to the last complete 4 chars
- l = placeHolders > 0 ? b64.length - 4 : b64.length;
- for (i = 0, j = 0; i < l; i += 4, j += 3) {
- tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]);
- arr.push((tmp & 0xFF0000) >> 16);
- arr.push((tmp & 0xFF00) >> 8);
- arr.push(tmp & 0xFF);
- }
- if (placeHolders === 2) {
- tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4);
- arr.push(tmp & 0xFF);
- } else if (placeHolders === 1) {
- tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2);
- arr.push((tmp >> 8) & 0xFF);
- arr.push(tmp & 0xFF);
- }
- return arr;
- }
- function uint8ToBase64(uint8) {
- var i,
- extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
- output = "",
- temp, length;
- function tripletToBase64 (num) {
- return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
- };
- // go through the array every three bytes, we'll deal with trailing stuff later
- for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
- temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
- output += tripletToBase64(temp);
- }
- // pad the end with zeros, but make sure to not forget the extra bytes
- switch (extraBytes) {
- case 1:
- temp = uint8[uint8.length - 1];
- output += lookup[temp >> 2];
- output += lookup[(temp << 4) & 0x3F];
- output += '==';
- break;
- case 2:
- temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]);
- output += lookup[temp >> 10];
- output += lookup[(temp >> 4) & 0x3F];
- output += lookup[(temp << 2) & 0x3F];
- output += '=';
- break;
- }
- return output;
- }
- module.exports.toByteArray = b64ToByteArray;
- module.exports.fromByteArray = uint8ToBase64;
- }());
- },{}]},{},[])
- ;;module.exports=require("buffer-browserify")
- },{}],30:[function(require,module,exports){
- // shim for using process in browser
- var process = module.exports = {};
- process.nextTick = (function () {
- var canSetImmediate = typeof window !== 'undefined'
- && window.setImmediate;
- var canPost = typeof window !== 'undefined'
- && window.postMessage && window.addEventListener
- ;
- if (canSetImmediate) {
- return function (f) { return window.setImmediate(f) };
- }
- if (canPost) {
- var queue = [];
- window.addEventListener('message', function (ev) {
- var source = ev.source;
- if ((source === window || source === null) && ev.data === 'process-tick') {
- ev.stopPropagation();
- if (queue.length > 0) {
- var fn = queue.shift();
- fn();
- }
- }
- }, true);
- return function nextTick(fn) {
- queue.push(fn);
- window.postMessage('process-tick', '*');
- };
- }
- return function nextTick(fn) {
- setTimeout(fn, 0);
- };
- })();
- process.title = 'browser';
- process.browser = true;
- process.env = {};
- process.argv = [];
- process.binding = function (name) {
- throw new Error('process.binding is not supported');
- }
- // TODO(shtylman)
- process.cwd = function () { return '/' };
- process.chdir = function (dir) {
- throw new Error('process.chdir is not supported');
- };
- },{}],31:[function(require,module,exports){
- module.exports = require('./lib/urlsafe-base64');
- },{"./lib/urlsafe-base64":32}],32:[function(require,module,exports){
- var Buffer=require("__browserify_Buffer").Buffer;/*!
- * urlsafe-base64
- */
- /**
- * Module Dependencies
- */
- // None yet!
- /**
- * Library version.
- */
- exports.version = '1.0.0';
- /**
- * .encode
- *
- * return an encoded Buffer as URL Safe Base64
- *
- * Note: This function encodes to the RFC 4648 Spec where '+' is encoded
- * as '-' and '/' is encoded as '_'. The padding character '=' is
- * removed.
- *
- * @param {Buffer} buffer
- * @return {String}
- * @api public
- */
- exports.encode = function encode(buffer) {
- return buffer.toString('base64')
- .replace(/\+/g, '-') // Convert '+' to '-'
- .replace(/\//g, '_') // Convert '/' to '_'
- .replace(/=+$/, ''); // Remove ending '='
- };
- /**
- * .decode
- *
- * return an decoded URL Safe Base64 as Buffer
- *
- * @param {String}
- * @return {Buffer}
- * @api public
- */
- exports.decode = function decode(base64) {
- // Add removed at end '='
- base64 += Array(5 - base64.length % 4).join('=');
- base64 = base64
- .replace(/\-/g, '+') // Convert '-' to '+'
- .replace(/\_/g, '/'); // Convert '_' to '/'
- return new Buffer(base64, 'base64');
- };
- /**
- * .validate
- *
- * Validates a string if it is URL Safe Base64 encoded.
- *
- * @param {String}
- * @return {Boolean}
- * @api public
- */
- exports.validate = function validate(base64) {
- return /^[A-Za-z0-9\-_]+$/.test(base64);
- };
- },{"__browserify_Buffer":29}]},{},[1])
- (1)
- });
- ;
|