mirror of
https://github.com/Tygs/0bin.git
synced 2023-08-10 21:13:00 +03:00
New clean layout to be pip installable
This commit is contained in:
311
zerobin/static/js/ZeroClipboard.js
Executable file
311
zerobin/static/js/ZeroClipboard.js
Executable file
@ -0,0 +1,311 @@
|
||||
// Simple Set Clipboard System
|
||||
// Author: Joseph Huckaby
|
||||
|
||||
var ZeroClipboard = {
|
||||
|
||||
version: "1.0.7",
|
||||
clients: {}, // registered upload clients on page, indexed by id
|
||||
moviePath: 'ZeroClipboard.swf', // URL to movie
|
||||
nextId: 1, // ID of next movie
|
||||
|
||||
$: function(thingy) {
|
||||
// simple DOM lookup utility function
|
||||
if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
|
||||
if (!thingy.addClass) {
|
||||
// extend element with a few useful methods
|
||||
thingy.hide = function() { this.style.display = 'none'; };
|
||||
thingy.show = function() { this.style.display = ''; };
|
||||
thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
|
||||
thingy.removeClass = function(name) {
|
||||
var classes = this.className.split(/\s+/);
|
||||
var idx = -1;
|
||||
for (var k = 0; k < classes.length; k++) {
|
||||
if (classes[k] == name) { idx = k; k = classes.length; }
|
||||
}
|
||||
if (idx > -1) {
|
||||
classes.splice( idx, 1 );
|
||||
this.className = classes.join(' ');
|
||||
}
|
||||
return this;
|
||||
};
|
||||
thingy.hasClass = function(name) {
|
||||
return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
|
||||
};
|
||||
}
|
||||
return thingy;
|
||||
},
|
||||
|
||||
setMoviePath: function(path) {
|
||||
// set path to ZeroClipboard.swf
|
||||
this.moviePath = path;
|
||||
},
|
||||
|
||||
dispatch: function(id, eventName, args) {
|
||||
// receive event from flash movie, send to client
|
||||
var client = this.clients[id];
|
||||
if (client) {
|
||||
client.receiveEvent(eventName, args);
|
||||
}
|
||||
},
|
||||
|
||||
register: function(id, client) {
|
||||
// register new client to receive events
|
||||
this.clients[id] = client;
|
||||
},
|
||||
|
||||
getDOMObjectPosition: function(obj, stopObj) {
|
||||
// get absolute coordinates for dom element
|
||||
var info = {
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: obj.width ? obj.width : obj.offsetWidth,
|
||||
height: obj.height ? obj.height : obj.offsetHeight
|
||||
};
|
||||
|
||||
while (obj && (obj != stopObj)) {
|
||||
info.left += obj.offsetLeft;
|
||||
info.top += obj.offsetTop;
|
||||
obj = obj.offsetParent;
|
||||
}
|
||||
|
||||
return info;
|
||||
},
|
||||
|
||||
Client: function(elem) {
|
||||
// constructor for new simple upload client
|
||||
this.handlers = {};
|
||||
|
||||
// unique ID
|
||||
this.id = ZeroClipboard.nextId++;
|
||||
this.movieId = 'ZeroClipboardMovie_' + this.id;
|
||||
|
||||
// register client with singleton to receive flash events
|
||||
ZeroClipboard.register(this.id, this);
|
||||
|
||||
// create movie
|
||||
if (elem) this.glue(elem);
|
||||
}
|
||||
};
|
||||
|
||||
ZeroClipboard.Client.prototype = {
|
||||
|
||||
id: 0, // unique ID for us
|
||||
ready: false, // whether movie is ready to receive events or not
|
||||
movie: null, // reference to movie object
|
||||
clipText: '', // text to copy to clipboard
|
||||
handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
|
||||
cssEffects: true, // enable CSS mouse effects on dom container
|
||||
handlers: null, // user event handlers
|
||||
|
||||
glue: function(elem, appendElem, stylesToAdd) {
|
||||
// glue to DOM element
|
||||
// elem can be ID or actual DOM element object
|
||||
this.domElement = ZeroClipboard.$(elem);
|
||||
|
||||
// float just above object, or zIndex 99 if dom element isn't set
|
||||
var zIndex = 99;
|
||||
if (this.domElement.style.zIndex) {
|
||||
zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
|
||||
}
|
||||
|
||||
if (typeof(appendElem) == 'string') {
|
||||
appendElem = ZeroClipboard.$(appendElem);
|
||||
}
|
||||
else if (typeof(appendElem) == 'undefined') {
|
||||
appendElem = document.getElementsByTagName('body')[0];
|
||||
}
|
||||
|
||||
// find X/Y position of domElement
|
||||
var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
|
||||
|
||||
// create floating DIV above element
|
||||
this.div = document.createElement('div');
|
||||
var style = this.div.style;
|
||||
style.position = 'absolute';
|
||||
style.left = '' + box.left + 'px';
|
||||
style.top = '' + box.top + 'px';
|
||||
style.width = '' + box.width + 'px';
|
||||
style.height = '' + box.height + 'px';
|
||||
style.zIndex = zIndex;
|
||||
|
||||
if (typeof(stylesToAdd) == 'object') {
|
||||
for (addedStyle in stylesToAdd) {
|
||||
style[addedStyle] = stylesToAdd[addedStyle];
|
||||
}
|
||||
}
|
||||
|
||||
//style.backgroundColor = '#f00'; // debug
|
||||
|
||||
appendElem.appendChild(this.div);
|
||||
|
||||
this.div.innerHTML = this.getHTML( box.width, box.height );
|
||||
},
|
||||
|
||||
getHTML: function(width, height) {
|
||||
// return HTML for movie
|
||||
var html = '';
|
||||
var flashvars = 'id=' + this.id +
|
||||
'&width=' + width +
|
||||
'&height=' + height;
|
||||
|
||||
if (navigator.userAgent.match(/MSIE/)) {
|
||||
// IE gets an OBJECT tag
|
||||
var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
|
||||
html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+this.movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard.moviePath+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+'"/><param name="wmode" value="transparent"/></object>';
|
||||
}
|
||||
else {
|
||||
// all other browsers get an EMBED tag
|
||||
html += '<embed id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+this.movieId+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'" wmode="transparent" />';
|
||||
}
|
||||
return html;
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
// temporarily hide floater offscreen
|
||||
if (this.div) {
|
||||
this.div.style.left = '-2000px';
|
||||
}
|
||||
},
|
||||
|
||||
show: function() {
|
||||
// show ourselves after a call to hide()
|
||||
this.reposition();
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
// destroy control and floater
|
||||
if (this.domElement && this.div) {
|
||||
this.hide();
|
||||
this.div.innerHTML = '';
|
||||
|
||||
var body = document.getElementsByTagName('body')[0];
|
||||
try { body.removeChild( this.div ); } catch(e) {;}
|
||||
|
||||
this.domElement = null;
|
||||
this.div = null;
|
||||
}
|
||||
},
|
||||
|
||||
reposition: function(elem) {
|
||||
// reposition our floating div, optionally to new container
|
||||
// warning: container CANNOT change size, only position
|
||||
if (elem) {
|
||||
this.domElement = ZeroClipboard.$(elem);
|
||||
if (!this.domElement) this.hide();
|
||||
}
|
||||
|
||||
if (this.domElement && this.div) {
|
||||
var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
|
||||
var style = this.div.style;
|
||||
style.left = '' + box.left + 'px';
|
||||
style.top = '' + box.top + 'px';
|
||||
}
|
||||
},
|
||||
|
||||
setText: function(newText) {
|
||||
// set text to be copied to clipboard
|
||||
this.clipText = newText;
|
||||
if (this.ready) this.movie.setText(newText);
|
||||
},
|
||||
|
||||
addEventListener: function(eventName, func) {
|
||||
// add user event listener for event
|
||||
// event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
|
||||
eventName = eventName.toString().toLowerCase().replace(/^on/, '');
|
||||
if (!this.handlers[eventName]) this.handlers[eventName] = [];
|
||||
this.handlers[eventName].push(func);
|
||||
},
|
||||
|
||||
setHandCursor: function(enabled) {
|
||||
// enable hand cursor (true), or default arrow cursor (false)
|
||||
this.handCursorEnabled = enabled;
|
||||
if (this.ready) this.movie.setHandCursor(enabled);
|
||||
},
|
||||
|
||||
setCSSEffects: function(enabled) {
|
||||
// enable or disable CSS effects on DOM container
|
||||
this.cssEffects = !!enabled;
|
||||
},
|
||||
|
||||
receiveEvent: function(eventName, args) {
|
||||
// receive event from flash
|
||||
eventName = eventName.toString().toLowerCase().replace(/^on/, '');
|
||||
|
||||
// special behavior for certain events
|
||||
switch (eventName) {
|
||||
case 'load':
|
||||
// movie claims it is ready, but in IE this isn't always the case...
|
||||
// bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
|
||||
this.movie = document.getElementById(this.movieId);
|
||||
if (!this.movie) {
|
||||
var self = this;
|
||||
setTimeout( function() { self.receiveEvent('load', null); }, 1 );
|
||||
return;
|
||||
}
|
||||
|
||||
// firefox on pc needs a "kick" in order to set these in certain cases
|
||||
if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
|
||||
var self = this;
|
||||
setTimeout( function() { self.receiveEvent('load', null); }, 100 );
|
||||
this.ready = true;
|
||||
return;
|
||||
}
|
||||
|
||||
this.ready = true;
|
||||
this.movie.setText( this.clipText );
|
||||
this.movie.setHandCursor( this.handCursorEnabled );
|
||||
break;
|
||||
|
||||
case 'mouseover':
|
||||
if (this.domElement && this.cssEffects) {
|
||||
this.domElement.addClass('hover');
|
||||
if (this.recoverActive) this.domElement.addClass('active');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mouseout':
|
||||
if (this.domElement && this.cssEffects) {
|
||||
this.recoverActive = false;
|
||||
if (this.domElement.hasClass('active')) {
|
||||
this.domElement.removeClass('active');
|
||||
this.recoverActive = true;
|
||||
}
|
||||
this.domElement.removeClass('hover');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mousedown':
|
||||
if (this.domElement && this.cssEffects) {
|
||||
this.domElement.addClass('active');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'mouseup':
|
||||
if (this.domElement && this.cssEffects) {
|
||||
this.domElement.removeClass('active');
|
||||
this.recoverActive = false;
|
||||
}
|
||||
break;
|
||||
} // switch eventName
|
||||
|
||||
if (this.handlers[eventName]) {
|
||||
for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
|
||||
var func = this.handlers[eventName][idx];
|
||||
|
||||
if (typeof(func) == 'function') {
|
||||
// actual function reference
|
||||
func(this, args);
|
||||
}
|
||||
else if ((typeof(func) == 'object') && (func.length == 2)) {
|
||||
// PHP style object + method, i.e. [myObject, 'myMethod']
|
||||
func[0][ func[1] ](this, args);
|
||||
}
|
||||
else if (typeof(func) == 'string') {
|
||||
// name of function
|
||||
window[func](this, args);
|
||||
}
|
||||
} // foreach event handler defined
|
||||
} // user defined handler for event
|
||||
}
|
||||
|
||||
};
|
BIN
zerobin/static/js/ZeroClipboard.swf
Executable file
BIN
zerobin/static/js/ZeroClipboard.swf
Executable file
Binary file not shown.
668
zerobin/static/js/behavior.js
Normal file
668
zerobin/static/js/behavior.js
Normal file
@ -0,0 +1,668 @@
|
||||
/*global sjcl:true, jQuery:true, $:true, lzw:true, zerobin:true, ZeroClipboard:true, vizhash:true, prettyPrint:true, confirm:true */
|
||||
;(function(){
|
||||
"use strict";
|
||||
|
||||
/* Start random number generator seeding ASAP */
|
||||
sjcl.random.startCollectors();
|
||||
/* Ensure jquery use cache for ajax requests */
|
||||
$.ajaxSetup({ cache: true });
|
||||
|
||||
/** Create a function that create inline callbacks.
|
||||
We use it to create callbacks for onliners with static arguments
|
||||
E.G:
|
||||
$('stuff').hide(function()(console.log(1, 2, 3)))
|
||||
|
||||
Becomes:
|
||||
|
||||
$('stuff').hide(mkcb(console.log, 1, 2, 3))
|
||||
*/
|
||||
function mkcb(func){
|
||||
var args = arguments;
|
||||
return function(){
|
||||
return func.apply(func, Array.prototype.slice.call(args, 1));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************************
|
||||
**** 0bin utilities ***
|
||||
****************************/
|
||||
|
||||
|
||||
window.zerobin = {
|
||||
/** Base64 + compress + encrypt, with callbacks before each operation,
|
||||
and all of them are executed in a timed continuation to give
|
||||
a change to the UI to respond.
|
||||
*/
|
||||
version: '0.1',
|
||||
encrypt: function(key, content, toBase64Callback,
|
||||
compressCallback, encryptCallback, doneCallback) {
|
||||
|
||||
setTimeout (function(){
|
||||
|
||||
content = sjcl.codec.utf8String.toBits(content);
|
||||
if (toBase64Callback) {toBase64Callback();}
|
||||
|
||||
setTimeout(function(){
|
||||
|
||||
content = sjcl.codec.base64.fromBits(content);
|
||||
if (compressCallback) {compressCallback();}
|
||||
|
||||
setTimeout(function(){
|
||||
|
||||
content = lzw.compress(content);
|
||||
if (encryptCallback) {encryptCallback();}
|
||||
|
||||
setTimeout(function(){
|
||||
content = sjcl.encrypt(key, content);
|
||||
if (doneCallback) {doneCallback(content);}
|
||||
}, 250);
|
||||
|
||||
}, 250);
|
||||
|
||||
}, 250);
|
||||
|
||||
}, 250);
|
||||
},
|
||||
|
||||
/** Base64 decoding + uncompress + decrypt, with callbacks before each operation,
|
||||
and all of them are executed in a timed continuation to give
|
||||
a change to the UI to respond.
|
||||
|
||||
This is where using a library to fake synchronicity could start to be
|
||||
useful, this code is starting be difficult to read. If anyone read this
|
||||
and got a suggestion, by all means, speak your mind.
|
||||
*/
|
||||
decrypt: function(key, content, errorCallback, uncompressCallback,
|
||||
fromBase64Callback, toStringCallback, doneCallback) {
|
||||
|
||||
/* Decrypt */
|
||||
setTimeout(function(){
|
||||
|
||||
try {
|
||||
|
||||
content = sjcl.decrypt(key, content);
|
||||
if (uncompressCallback) {uncompressCallback();}
|
||||
|
||||
/* Decompress */
|
||||
setTimeout(function(){
|
||||
|
||||
try {
|
||||
|
||||
content = lzw.decompress(content);
|
||||
if (fromBase64Callback) {fromBase64Callback();}
|
||||
|
||||
/* From base 64 to bits */
|
||||
setTimeout(function(){
|
||||
|
||||
try {
|
||||
|
||||
content = sjcl.codec.base64.toBits(content);
|
||||
if (toStringCallback) {toStringCallback();}
|
||||
|
||||
/* From bits to string */
|
||||
setTimeout(function(){
|
||||
|
||||
try {
|
||||
content = sjcl.codec.utf8String.fromBits(content);
|
||||
if (doneCallback) {doneCallback(content);}
|
||||
} catch (err) {
|
||||
errorCallback(err);
|
||||
}
|
||||
|
||||
}, 250); /* "End of from bits to string" */
|
||||
|
||||
} catch (err) {
|
||||
errorCallback(err);
|
||||
}
|
||||
|
||||
}, 250); /* End of "from base 64 to bits" */
|
||||
|
||||
} catch (err) {
|
||||
errorCallback(err);
|
||||
}
|
||||
|
||||
}, 250); /* End of "decompress" */
|
||||
|
||||
} catch (err) {
|
||||
errorCallback(err);
|
||||
}
|
||||
|
||||
}, 250); /* End of "decrypt" */
|
||||
},
|
||||
|
||||
/** Create a random base64 string long enought to be suitable as
|
||||
an encryption key */
|
||||
makeKey: function() {
|
||||
return sjcl.codec.base64.fromBits(sjcl.random.randomWords(8, 0), 0);
|
||||
},
|
||||
|
||||
getFormatedDate: function(date){
|
||||
date = date || new Date();
|
||||
return ((date.getMonth() +1 ) + '-' +
|
||||
date.getDate() + '-' + date.getFullYear());
|
||||
},
|
||||
|
||||
getFormatedTime: function(date){
|
||||
date = date || new Date();
|
||||
var h = date.getHours();
|
||||
var m = date.getMinutes();
|
||||
var s = date.getSeconds();
|
||||
if (h < 10) {h = "0" + h;}
|
||||
if (m < 10) {m = "0" + m;}
|
||||
if (s < 10) {s = "0" + s;}
|
||||
return h + ":" + m + ":" + s;
|
||||
},
|
||||
|
||||
numOrdA: function(a, b){
|
||||
return (a-b);
|
||||
},
|
||||
|
||||
getKeys: function(){
|
||||
var keys = [];
|
||||
for(var i = 0; i <= localStorage.length; i++){
|
||||
if(localStorage.key(i) !== null){
|
||||
keys[i] = parseInt(localStorage.key(i), 10);
|
||||
}
|
||||
}
|
||||
return keys.sort(zerobin.numOrdA);
|
||||
},
|
||||
/** Get a tinyurl using JSONP */
|
||||
getTinyURL: function(longURL, success) {
|
||||
var api = 'http://json-tinyurl.appspot.com/?url=';
|
||||
$.getJSON(api + encodeURIComponent(longURL) + '&callback=?', function(data){
|
||||
success(data.tinyurl);
|
||||
});
|
||||
},
|
||||
|
||||
/** Check for browser support of the named featured. Store the result
|
||||
and add a class to the html tag with the result */
|
||||
support: {
|
||||
localStorage: (function(){
|
||||
var val = !!(localStorage);
|
||||
$('html').addClass((val ? '' : 'no-') + 'local-storage');
|
||||
return val;
|
||||
})(),
|
||||
|
||||
history: (function(){
|
||||
var val = !!(window.history && history.pushState);
|
||||
$('html').addClass((val ? '' : 'no-') + 'history');
|
||||
return val;
|
||||
})(),
|
||||
|
||||
fileUpload: (function(){
|
||||
var w = window;
|
||||
var val = !!(w.File && w.FileReader && w.FileList && w.Blob);
|
||||
$('html').addClass((val ? '' : 'no-') + 'file-upload');
|
||||
return val;
|
||||
})()
|
||||
},
|
||||
|
||||
storatePaste: function(url){
|
||||
if (zerobin.support.localStorage){
|
||||
var paste = (zerobin.getFormatedDate() + " " +
|
||||
zerobin.getFormatedTime() + ";" + url);
|
||||
var keys = zerobin.getKeys();
|
||||
|
||||
if(keys.length < 1){keys[0] = 0;}
|
||||
|
||||
if (localStorage.length > 19) {
|
||||
void localStorage.removeItem(keys[0]);
|
||||
}
|
||||
|
||||
localStorage.setItem(keys.reverse()[0]+1, paste);
|
||||
}
|
||||
},
|
||||
|
||||
/** Return a list of the previous paste url with creation date */
|
||||
getPreviousPastes: function(){
|
||||
var pastes = [],
|
||||
keys = zerobin.getKeys(),
|
||||
date = zerobin.getFormatedDate();
|
||||
keys.reverse();
|
||||
|
||||
for (var i = 0; i <= keys.length-1; i++) {
|
||||
var paste = localStorage.getItem(keys[i]).split(';');
|
||||
var displayDate = paste[0].split(' ')[0];
|
||||
var prefix = 'the ';
|
||||
if (displayDate === date){
|
||||
displayDate = paste[0].split(' ')[1];
|
||||
prefix = 'at ';
|
||||
}
|
||||
pastes.push({displayDate: displayDate, prefix: prefix, link: paste[1]});
|
||||
}
|
||||
|
||||
return pastes;
|
||||
},
|
||||
|
||||
/** Return an link object with the URL as href so you can extract host,
|
||||
protocol, hash, etc.
|
||||
|
||||
This function use a closure to store a <div> parent for the <a>
|
||||
because IE requires the link be processed by it's HTML parser
|
||||
for the URL to be parsed. */
|
||||
parseUrl: (function(){
|
||||
|
||||
var div = document.createElement('div');
|
||||
div.innerHTML = "<a></a>";
|
||||
|
||||
return function(url){
|
||||
div.firstChild.href = url;
|
||||
div.innerHTML = div.innerHTML;
|
||||
return div.firstChild;
|
||||
};
|
||||
|
||||
})(),
|
||||
|
||||
getPasteId: function(url){
|
||||
var loc = url ? zerobin.parseUrl(url) : window.location;
|
||||
return loc.pathname.replace(/\/|paste/g, '').replace(/\?.*$/, '');
|
||||
},
|
||||
|
||||
getPasteKey: function(url){
|
||||
var loc = url ? zerobin.parseUrl(url) : window.location;
|
||||
return loc.hash.replace('#', '').replace(/\?.*$/, '');
|
||||
},
|
||||
|
||||
/** Return the paste content stripted from any code coloration */
|
||||
getPasteContent: function(){
|
||||
var copy = '' ;
|
||||
$("#paste-content li").each(function(index) {
|
||||
copy = copy + $(this).text() + '\n';
|
||||
});
|
||||
return copy;
|
||||
},
|
||||
|
||||
/** Return an approximate estimate the number of bytes in a text */
|
||||
count: function(text, options) {
|
||||
// Set option defaults
|
||||
var crlf = /(\r?\n|\r)/g;
|
||||
var whitespace = /(\r?\n|\r|\s+)/g;
|
||||
options = options || {};
|
||||
options.lineBreaks = options.lineBreaks || 1;
|
||||
|
||||
var length = text.length,
|
||||
nonAscii = length - text.replace(/[\u0100-\uFFFF]/g, '').length,
|
||||
lineBreaks = length - text.replace(crlf, '').length;
|
||||
|
||||
return length + nonAscii + Math.max(0, options.lineBreaks * (lineBreaks - 1));
|
||||
},
|
||||
/** Create a message, style it and insert it in the alert box */
|
||||
message: function(type, message, title, flush, callback) {
|
||||
|
||||
$(window).scrollTop(0);
|
||||
|
||||
if (flush) {$('.alert-'+type).remove();}
|
||||
|
||||
var $message = $('#alert-template').clone().attr('id', null)
|
||||
.addClass('alert alert-' + type);
|
||||
$('.message', $message).html(message);
|
||||
|
||||
if (title) {$('.title', $message).html(title);}
|
||||
else {$('.title', $message).remove();}
|
||||
|
||||
$message.prependTo($('#main')).show('fadeUp', callback);
|
||||
},
|
||||
|
||||
/** Return a progress bar object */
|
||||
progressBar: function(selector){
|
||||
var $container = $(selector);
|
||||
var bar = {container: $container, elem: $container.find('.bar')};
|
||||
bar.set = function(text, rate){bar.elem.text(text).css('width', rate);};
|
||||
return bar;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/***************************
|
||||
**** On document ready ***
|
||||
****************************/
|
||||
|
||||
|
||||
$(function(){
|
||||
|
||||
/**
|
||||
On the create paste page:
|
||||
On click on the send button, compress and encrypt data before
|
||||
posting it using ajax. Then redirect to the address of the
|
||||
newly created paste, adding the key in the hash.
|
||||
*/
|
||||
$('.btn-primary').live("click", function(e){
|
||||
|
||||
e.preventDefault();
|
||||
var paste = $('textarea').val();
|
||||
|
||||
var sizebytes = zerobin.count($('#content').val());
|
||||
var oversized = sizebytes > zerobin.max_size;
|
||||
var readableFsize = Math.round(sizebytes / 1024);
|
||||
var readableMaxsize = Math.round(zerobin.max_size / 1024);
|
||||
|
||||
if (oversized){
|
||||
zerobin.message('error',
|
||||
('Your file is <strong class="file-size">' + readableFsize +
|
||||
'</strong>KB. You have reached the maximum size limit of ' +
|
||||
readableMaxsize + 'KB.'),
|
||||
'Warning!', true);
|
||||
}
|
||||
|
||||
if (!oversized && paste.trim()) {
|
||||
|
||||
var $form = $('input, textarea, select, button').prop('disabled', true);
|
||||
|
||||
// set up progress bar
|
||||
var bar = zerobin.progressBar('form.well .progress');
|
||||
bar.container.show();
|
||||
bar.set('Converting paste to bits...', '25%');
|
||||
|
||||
/* Encode, compress, encrypt and send the paste then redirect the user
|
||||
to the new paste. We ensure a loading animation is updated
|
||||
during the process by passing callbacks.
|
||||
*/
|
||||
try {
|
||||
|
||||
var expiration = $('#expiration').val();
|
||||
var key = zerobin.makeKey();
|
||||
|
||||
zerobin.encrypt(key, paste,
|
||||
|
||||
mkcb(bar.set, 'Encoding to base64...', '45%'),
|
||||
mkcb(bar.set, 'Compressing...', '65%'),
|
||||
mkcb(bar.set, 'Encrypting...', '85%'),
|
||||
|
||||
/* This block deal with sending the data, redirection or error handling */
|
||||
function(content){
|
||||
|
||||
bar.set('Sending...', '95%');
|
||||
var data = {content: content, expiration: expiration};
|
||||
|
||||
$.post('/paste/create', data)
|
||||
.error(function(error) {
|
||||
$form.prop('disabled', false);
|
||||
bar.container.hide();
|
||||
zerobin.message(
|
||||
'error',
|
||||
'Paste could not be saved. Please try again later.',
|
||||
'Error'
|
||||
);
|
||||
|
||||
})
|
||||
.success(function(data) {
|
||||
bar.set('Redirecting to new paste...', '100%');
|
||||
|
||||
if (data.status === 'error') {
|
||||
zerobin.message('error', data.message, 'Error');
|
||||
$form.prop('disabled', false);
|
||||
bar.container.hide();
|
||||
} else {
|
||||
var paste_url = '/paste/' + data.paste + '#' + key;
|
||||
zerobin.storatePaste(paste_url);
|
||||
window.location = (paste_url);
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
$form.prop('disabled', false);
|
||||
bar.container.hide();
|
||||
zerobin.message('error', 'Paste could not be encrypted. Aborting.',
|
||||
'Error');
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
DECRYPTION:
|
||||
On the display paste page, decrypt and decompress the paste content,
|
||||
add syntax coloration then setup the copy to clipboard button.
|
||||
Also calculate and set the paste visual hash.
|
||||
*/
|
||||
var content = $('#paste-content').text().trim();
|
||||
var key = zerobin.getPasteKey();
|
||||
var error = false;
|
||||
if (content && key) {
|
||||
|
||||
/* Load the lib for visual canvas, create one from the paste id and
|
||||
insert it */
|
||||
$.getScript("/static/js/vizhash.min.js").done(function(script, textStatus) {
|
||||
if (vizhash.supportCanvas) {
|
||||
var vhash = vizhash.canvasHash(zerobin.getPasteId(), 24, 24);
|
||||
$('<a class="vhash" href="#"></a>').click(function(e){
|
||||
e.preventDefault();
|
||||
if(confirm("This picture is unique to your paste so you can identify" +
|
||||
" it quickly. \n\n Do you want to know more about this?")){
|
||||
window.open("http://is.gd/IJaMRG", "_blank");
|
||||
}
|
||||
}).prependTo('.lnk-option').append(vhash.canvas);
|
||||
}
|
||||
});
|
||||
|
||||
var $form = $('input, textarea, select, button').prop('disabled', true);
|
||||
|
||||
var bar = zerobin.progressBar('.well form .progress');
|
||||
bar.container.show();
|
||||
bar.set('Decrypting paste...', '25%');
|
||||
|
||||
zerobin.decrypt(key, content,
|
||||
|
||||
/* On error*/
|
||||
function(){
|
||||
bar.container.hide();
|
||||
zerobin.message('error', 'Could not decrypt data (Wrong key ?)', 'Error');
|
||||
},
|
||||
|
||||
/* Update progress bar */
|
||||
mkcb(bar.set, 'Decompressing...', '45%'),
|
||||
mkcb(bar.set, 'Base64 decoding...', '65%'),
|
||||
mkcb(bar.set, 'From bits to string...', '85%'),
|
||||
|
||||
/* When done */
|
||||
function(content){
|
||||
|
||||
/* Decrypted content goes back to initial container*/
|
||||
$('#paste-content').text(content);
|
||||
content = '';
|
||||
|
||||
bar.set('Code coloration...', '95%');
|
||||
|
||||
/* Add a continuation to let the UI redraw */
|
||||
setTimeout(function(){
|
||||
|
||||
/* Setup flash clipboard button */
|
||||
ZeroClipboard.setMoviePath('/static/js/ZeroClipboard.swf');
|
||||
|
||||
var clip = new ZeroClipboard.Client();
|
||||
|
||||
// Callback to reposition the clibpboad flash animation overlay
|
||||
var reposition = function(){clip.reposition();};
|
||||
|
||||
clip.addEventListener('mouseup', function(){
|
||||
$('#clip-button').text('Copying paste...');
|
||||
clip.setText(zerobin.getPasteContent());
|
||||
});
|
||||
clip.addEventListener('complete', function(){
|
||||
$('#clip-button').text('Copy to clipboard');
|
||||
zerobin.message('info', 'The paste is now in your clipboard', '',
|
||||
true, reposition);
|
||||
});
|
||||
clip.glue('clip-button');
|
||||
|
||||
window.onresize = reposition;
|
||||
|
||||
|
||||
/* Setup link to get the paste short url*/
|
||||
$('#short-url').click(function(e) {
|
||||
e.preventDefault();
|
||||
$('#short-url').text('Loading short url...');
|
||||
zerobin.getTinyURL(window.location.toString(), function(tinyurl){
|
||||
clip.setText(tinyurl);
|
||||
$('#copy-success').hide();
|
||||
zerobin.message('success',
|
||||
'<a href="' + tinyurl + '">' + tinyurl + '</a>',
|
||||
'Short url', true, reposition
|
||||
);
|
||||
$('#short-url').text('Get short url');
|
||||
});
|
||||
});
|
||||
|
||||
/* Remap the message close handler to include the clipboard
|
||||
flash reposition */
|
||||
$(".close").off().live('click', function(e){
|
||||
e.preventDefault();
|
||||
$(this).parent().fadeOut(reposition);
|
||||
});
|
||||
|
||||
/** Syntaxic coloration */
|
||||
prettyPrint();
|
||||
|
||||
/* Class to switch to paste content style with coloration done */
|
||||
$('#paste-content').addClass('done');
|
||||
|
||||
/* Display result */
|
||||
bar.set('Done', '100%');
|
||||
bar.container.hide();
|
||||
|
||||
$form.prop('disabled', false);
|
||||
|
||||
}, 250);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
} /* End of "DECRYPTION" */
|
||||
|
||||
/* Synchronize expiration select boxes value */
|
||||
$('.paste-option select').live('change', function(){
|
||||
var $this = $(this);
|
||||
$this.val($this.val());
|
||||
});
|
||||
|
||||
|
||||
/* Resize Textarea according to content */
|
||||
$('#content').elastic();
|
||||
|
||||
|
||||
/* Display bottom paste option buttons when needed */
|
||||
$('#content').live('keyup change', function(){
|
||||
if($('#content').height() < 400 ){
|
||||
$('.paste-option.down').remove();
|
||||
}
|
||||
else {
|
||||
|
||||
if ($('.paste-option').length === 1) {
|
||||
$('.paste-option').clone().addClass('down').appendTo('form.well');
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
/* Display previous pastes */
|
||||
if (zerobin.support.localStorage){
|
||||
|
||||
var $container = $('.previous-pastes'),
|
||||
pastes = zerobin.getPreviousPastes();
|
||||
|
||||
if (pastes.length){
|
||||
|
||||
$.getScript("/static/js/vizhash.min.js").done(function(script, textStatus) {
|
||||
|
||||
$container.find('.item').remove();
|
||||
$.each(zerobin.getPreviousPastes(), function(i, paste){
|
||||
|
||||
var $li = $('<li class="item"></li>').appendTo($container);
|
||||
var $link = $('<a></a>').attr('href', paste.link)
|
||||
.text(paste.prefix + paste.displayDate)
|
||||
.appendTo($li);
|
||||
|
||||
if (vizhash.supportCanvas) {
|
||||
var pasteId = zerobin.getPasteId(paste.link);
|
||||
var vhash = vizhash.canvasHash(pasteId, 24, 24).canvas;
|
||||
$link.prepend($(vhash).addClass('vhash'));
|
||||
}
|
||||
|
||||
// hightlite the current link and make sure clicking the link
|
||||
// does redirect to the page
|
||||
if (paste.link.replace(/#[^#]+/, '') === window.location.pathname){
|
||||
$li.addClass('active');
|
||||
$link.click(function(){window.location.reload();});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Event handler for "clone paste" button */
|
||||
$('.btn-clone').click(function(e){
|
||||
e.preventDefault();
|
||||
$('.submit-form').show();
|
||||
$('.paste-form').hide();
|
||||
$('#content').val(zerobin.getPasteContent()).trigger('change');
|
||||
});
|
||||
|
||||
$('.clone .btn-danger').click(function(e){
|
||||
e.preventDefault();
|
||||
$('.submit-form').hide();
|
||||
$('.paste-form').show();
|
||||
});
|
||||
|
||||
|
||||
/* Upload file using HTML5 File API */
|
||||
if (zerobin.support.fileUpload) {
|
||||
|
||||
var upload = function(files) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(event) {
|
||||
$('#content').val(event.target.result).trigger('change');
|
||||
};
|
||||
reader.readAsText(files[0]);
|
||||
};
|
||||
|
||||
var $buttonOverlay = $('#file-upload');
|
||||
var $button = $('.btn-upload');
|
||||
|
||||
try {
|
||||
$button.val('Uploading...');
|
||||
$button.prop('disabled', true);
|
||||
$buttonOverlay.change(function(){upload(this.files);});
|
||||
}
|
||||
catch (e) {
|
||||
zerobin.message('error', 'Could no upload the file', 'Error');
|
||||
$button.val('Upload File');
|
||||
$button.prop('disabled', false);
|
||||
}
|
||||
|
||||
$button.prop('disabled', false);
|
||||
$button.val('Upload File');
|
||||
$buttonOverlay.mouseover(mkcb($(this).css, 'cursor', 'pointer'));
|
||||
}
|
||||
|
||||
/* Alerts */
|
||||
|
||||
$(".close").live('click', function(e){
|
||||
e.preventDefault();
|
||||
$(this).parent().fadeOut();
|
||||
});
|
||||
|
||||
|
||||
/* Parse obfuscaded emails and make them usable */
|
||||
$('.email-link').each(function(i, elem){
|
||||
var $obfuscatedEmail = $(this);
|
||||
var address = $obfuscatedEmail.attr('title').replace('__AT__', '@');
|
||||
var text = $obfuscatedEmail.text().replace('__AT__', '@');
|
||||
var $plainTextEmail = $('<a href="mailto:' + address + '">'+ text +'</a>');
|
||||
$obfuscatedEmail.replaceWith($plainTextEmail);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
}); /* End of "document ready" jquery callback */
|
||||
|
||||
})(); /* End of self executing function */
|
4
zerobin/static/js/jquery-1.7.2.min.js
vendored
Normal file
4
zerobin/static/js/jquery-1.7.2.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
162
zerobin/static/js/jquery.elastic.source.js
Normal file
162
zerobin/static/js/jquery.elastic.source.js
Normal file
@ -0,0 +1,162 @@
|
||||
/**
|
||||
* @name Elastic
|
||||
* @descripton Elastic is jQuery plugin that grow and shrink your textareas automatically
|
||||
* @version 1.6.11
|
||||
* @requires jQuery 1.2.6+
|
||||
*
|
||||
* @author Jan Jarfalk
|
||||
* @author-email jan.jarfalk@unwrongest.com
|
||||
* @author-website http://www.unwrongest.com
|
||||
*
|
||||
* @licence MIT License - http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
(function($){
|
||||
jQuery.fn.extend({
|
||||
elastic: function() {
|
||||
|
||||
// We will create a div clone of the textarea
|
||||
// by copying these attributes from the textarea to the div.
|
||||
var mimics = [
|
||||
'paddingTop',
|
||||
'paddingRight',
|
||||
'paddingBottom',
|
||||
'paddingLeft',
|
||||
'fontSize',
|
||||
'lineHeight',
|
||||
'fontFamily',
|
||||
'width',
|
||||
'fontWeight',
|
||||
'border-top-width',
|
||||
'border-right-width',
|
||||
'border-bottom-width',
|
||||
'border-left-width',
|
||||
'borderTopStyle',
|
||||
'borderTopColor',
|
||||
'borderRightStyle',
|
||||
'borderRightColor',
|
||||
'borderBottomStyle',
|
||||
'borderBottomColor',
|
||||
'borderLeftStyle',
|
||||
'borderLeftColor'
|
||||
];
|
||||
|
||||
return this.each( function() {
|
||||
|
||||
// Elastic only works on textareas
|
||||
if ( this.type !== 'textarea' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var $textarea = jQuery(this),
|
||||
$twin = jQuery('<div />').css({
|
||||
'position' : 'absolute',
|
||||
'display' : 'none',
|
||||
'word-wrap' : 'break-word',
|
||||
'white-space' :'pre-wrap'
|
||||
}),
|
||||
lineHeight = parseInt($textarea.css('line-height'),10) || parseInt($textarea.css('font-size'),'10'),
|
||||
minheight = parseInt($textarea.css('height'),10) || lineHeight*3,
|
||||
maxheight = parseInt($textarea.css('max-height'),10) || Number.MAX_VALUE,
|
||||
goalheight = 0;
|
||||
|
||||
// Opera returns max-height of -1 if not set
|
||||
if (maxheight < 0) { maxheight = Number.MAX_VALUE; }
|
||||
|
||||
// Append the twin to the DOM
|
||||
// We are going to meassure the height of this, not the textarea.
|
||||
$twin.appendTo($textarea.parent());
|
||||
|
||||
// Copy the essential styles (mimics) from the textarea to the twin
|
||||
var i = mimics.length;
|
||||
while(i--){
|
||||
$twin.css(mimics[i].toString(),$textarea.css(mimics[i].toString()));
|
||||
}
|
||||
|
||||
// Updates the width of the twin. (solution for textareas with widths in percent)
|
||||
function setTwinWidth(){
|
||||
var curatedWidth = Math.floor(parseInt($textarea.width(),10));
|
||||
if($twin.width() !== curatedWidth){
|
||||
$twin.css({'width': curatedWidth + 'px'});
|
||||
|
||||
// Update height of textarea
|
||||
update(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Sets a given height and overflow state on the textarea
|
||||
function setHeightAndOverflow(height, overflow){
|
||||
|
||||
var curratedHeight = Math.floor(parseInt(height,10));
|
||||
if($textarea.height() !== curratedHeight){
|
||||
$textarea.css({'height': curratedHeight + 'px','overflow':overflow});
|
||||
}
|
||||
}
|
||||
|
||||
// This function will update the height of the textarea if necessary
|
||||
function update(forced) {
|
||||
|
||||
// Get curated content from the textarea.
|
||||
var textareaContent = $textarea.val().replace(/&/g,'&').replace(/ {2}/g, ' ').replace(/<|>/g, '>').replace(/\n/g, '<br />');
|
||||
|
||||
// Compare curated content with curated twin.
|
||||
var twinContent = $twin.html().replace(/<br>/ig,'<br />');
|
||||
|
||||
if(forced || textareaContent+' ' !== twinContent){
|
||||
|
||||
// Add an extra white space so new rows are added when you are at the end of a row.
|
||||
$twin.html(textareaContent+' ');
|
||||
|
||||
// Change textarea height if twin plus the height of one line differs more than 3 pixel from textarea height
|
||||
if(Math.abs($twin.height() + lineHeight - $textarea.height()) > 3){
|
||||
|
||||
var goalheight = $twin.height()+lineHeight;
|
||||
if(goalheight >= maxheight) {
|
||||
setHeightAndOverflow(maxheight,'auto');
|
||||
} else if(goalheight <= minheight) {
|
||||
setHeightAndOverflow(minheight,'hidden');
|
||||
} else {
|
||||
setHeightAndOverflow(goalheight,'hidden');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Hide scrollbars
|
||||
$textarea.css({'overflow':'hidden'});
|
||||
|
||||
// Update textarea size on keyup, change, cut and paste
|
||||
$textarea.bind('keyup change cut paste', function(){
|
||||
update();
|
||||
});
|
||||
|
||||
// Update width of twin if browser or textarea is resized (solution for textareas with widths in percent)
|
||||
$(window).bind('resize', setTwinWidth);
|
||||
$textarea.bind('resize', setTwinWidth);
|
||||
$textarea.bind('update', update);
|
||||
|
||||
// Compact textarea on blur
|
||||
$textarea.bind('blur',function(){
|
||||
if($twin.height() < maxheight){
|
||||
if($twin.height() > minheight) {
|
||||
$textarea.height($twin.height());
|
||||
} else {
|
||||
$textarea.height(minheight);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// And this line is to catch the browser paste event
|
||||
$textarea.bind('input paste',function(e){ setTimeout( update, 250); });
|
||||
|
||||
// Run update once when elastic is initialized
|
||||
update();
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
})(jQuery);
|
111
zerobin/static/js/lzw.js
Normal file
111
zerobin/static/js/lzw.js
Normal file
@ -0,0 +1,111 @@
|
||||
// Author: Anthony McKale
|
||||
//
|
||||
// Note: modifed to javascript from orginal as2 found below
|
||||
// basically identical actual to as2
|
||||
//
|
||||
// http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/
|
||||
//
|
||||
// A class for LZW compression modified from code posted at the following URL's
|
||||
// http://www.shoe-box.org/blog/index.php/2004/05/05/13-CompressionLzw
|
||||
// http://www.lalex.com/blog/comments/200405/164-compression-lzw-actionscript-2.html
|
||||
//
|
||||
var lzw = {
|
||||
// Change this variable to output an xml safe string
|
||||
xmlsafe : false,
|
||||
compress : function(str){
|
||||
var dico = new Array();
|
||||
var skipnum = lzw.xmlsafe?5:0;
|
||||
for (var i = 0; i < 256; i++)
|
||||
{
|
||||
dico[String.fromCharCode(i)] = i;
|
||||
}
|
||||
if (lzw.xmlsafe)
|
||||
{
|
||||
dico["<"] = 256;
|
||||
dico[">"] = 257;
|
||||
dico["&"] = 258;
|
||||
dico["\""] = 259;
|
||||
dico["'"] = 260;
|
||||
}
|
||||
var res = "";
|
||||
var txt2encode = str;
|
||||
var splitStr = txt2encode.split("");
|
||||
var len = splitStr.length;
|
||||
var nbChar = 256+skipnum;
|
||||
var buffer = "";
|
||||
for (var i = 0; i <= len; i++)
|
||||
{
|
||||
var current = splitStr[i];
|
||||
if (dico[buffer + current] !== undefined)
|
||||
{
|
||||
buffer += current;
|
||||
}
|
||||
else
|
||||
{
|
||||
res += String.fromCharCode(dico[buffer]);
|
||||
dico[buffer + current] = nbChar;
|
||||
nbChar++;
|
||||
buffer = current;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
},
|
||||
decompress : function (str)
|
||||
{
|
||||
var dico = new Array();
|
||||
var skipnum = lzw.xmlsafe?5:0;
|
||||
for (var i = 0; i < 256; i++)
|
||||
{
|
||||
var c = String.fromCharCode(i);
|
||||
dico[i] = c;
|
||||
}
|
||||
if (lzw.xmlsafe)
|
||||
{
|
||||
dico[256] = "<";
|
||||
dico[257] = ">";
|
||||
dico[258] = "&";
|
||||
dico[259] = "\"";
|
||||
dico[260] = "'";
|
||||
}
|
||||
var txt2encode = str;
|
||||
var splitStr = txt2encode.split("");
|
||||
var length = splitStr.length;
|
||||
var nbChar = 256+skipnum;
|
||||
var buffer = "";
|
||||
var chaine = "";
|
||||
var result = "";
|
||||
for (var i = 0; i < length; i++)
|
||||
{
|
||||
var code = txt2encode.charCodeAt(i);
|
||||
var current = dico[code];
|
||||
if (buffer == "")
|
||||
{
|
||||
buffer = current;
|
||||
result += current;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (code <= 255+skipnum)
|
||||
{
|
||||
result += current;
|
||||
chaine = buffer + current;
|
||||
dico[nbChar] = chaine;
|
||||
nbChar++;
|
||||
buffer = current;
|
||||
}
|
||||
else
|
||||
{
|
||||
chaine = dico[code];
|
||||
if (chaine == undefined) chaine = buffer + buffer.slice(0,1);
|
||||
result += chaine;
|
||||
dico[nbChar] = buffer + chaine.slice(0, 1);
|
||||
nbChar++;
|
||||
buffer = chaine;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
68
zerobin/static/js/prettify.min.js
vendored
Normal file
68
zerobin/static/js/prettify.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
41
zerobin/static/js/sjcl.js
Normal file
41
zerobin/static/js/sjcl.js
Normal file
@ -0,0 +1,41 @@
|
||||
"use strict";var sjcl={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(a){this.toString=function(){return"CORRUPT: "+this.message};this.message=a},invalid:function(a){this.toString=function(){return"INVALID: "+this.message};this.message=a},bug:function(a){this.toString=function(){return"BUG: "+this.message};this.message=a},notReady:function(a){this.toString=function(){return"NOT READY: "+this.message};this.message=a}}};
|
||||
if(typeof module!="undefined"&&module.exports)module.exports=sjcl;
|
||||
sjcl.cipher.aes=function(a){this.h[0][0][0]||this.w();var b,c,d,e,f=this.h[0][4],g=this.h[1];b=a.length;var h=1;if(b!==4&&b!==6&&b!==8)throw new sjcl.exception.invalid("invalid aes key size");this.a=[d=a.slice(0),e=[]];for(a=b;a<4*b+28;a++){c=d[a-1];if(a%b===0||b===8&&a%b===4){c=f[c>>>24]<<24^f[c>>16&255]<<16^f[c>>8&255]<<8^f[c&255];if(a%b===0){c=c<<8^c>>>24^h<<24;h=h<<1^(h>>7)*283}}d[a]=d[a-b]^c}for(b=0;a;b++,a--){c=d[b&3?a:a-4];e[b]=a<=4||b<4?c:g[0][f[c>>>24]]^g[1][f[c>>16&255]]^g[2][f[c>>8&255]]^
|
||||
g[3][f[c&255]]}};
|
||||
sjcl.cipher.aes.prototype={encrypt:function(a){return this.H(a,0)},decrypt:function(a){return this.H(a,1)},h:[[[],[],[],[],[]],[[],[],[],[],[]]],w:function(){var a=this.h[0],b=this.h[1],c=a[4],d=b[4],e,f,g,h=[],i=[],k,j,l,m;for(e=0;e<0x100;e++)i[(h[e]=e<<1^(e>>7)*283)^e]=e;for(f=g=0;!c[f];f^=k||1,g=i[g]||1){l=g^g<<1^g<<2^g<<3^g<<4;l=l>>8^l&255^99;c[f]=l;d[l]=f;j=h[e=h[k=h[f]]];m=j*0x1010101^e*0x10001^k*0x101^f*0x1010100;j=h[l]*0x101^l*0x1010100;for(e=0;e<4;e++){a[e][f]=j=j<<24^j>>>8;b[e][l]=m=m<<24^m>>>8}}for(e=
|
||||
0;e<5;e++){a[e]=a[e].slice(0);b[e]=b[e].slice(0)}},H:function(a,b){if(a.length!==4)throw new sjcl.exception.invalid("invalid aes block size");var c=this.a[b],d=a[0]^c[0],e=a[b?3:1]^c[1],f=a[2]^c[2];a=a[b?1:3]^c[3];var g,h,i,k=c.length/4-2,j,l=4,m=[0,0,0,0];g=this.h[b];var n=g[0],o=g[1],p=g[2],q=g[3],r=g[4];for(j=0;j<k;j++){g=n[d>>>24]^o[e>>16&255]^p[f>>8&255]^q[a&255]^c[l];h=n[e>>>24]^o[f>>16&255]^p[a>>8&255]^q[d&255]^c[l+1];i=n[f>>>24]^o[a>>16&255]^p[d>>8&255]^q[e&255]^c[l+2];a=n[a>>>24]^o[d>>16&
|
||||
255]^p[e>>8&255]^q[f&255]^c[l+3];l+=4;d=g;e=h;f=i}for(j=0;j<4;j++){m[b?3&-j:j]=r[d>>>24]<<24^r[e>>16&255]<<16^r[f>>8&255]<<8^r[a&255]^c[l++];g=d;d=e;e=f;f=a;a=g}return m}};
|
||||
sjcl.bitArray={bitSlice:function(a,b,c){a=sjcl.bitArray.P(a.slice(b/32),32-(b&31)).slice(1);return c===undefined?a:sjcl.bitArray.clamp(a,c-b)},extract:function(a,b,c){var d=Math.floor(-b-c&31);return((b+c-1^b)&-32?a[b/32|0]<<32-d^a[b/32+1|0]>>>d:a[b/32|0]>>>d)&(1<<c)-1},concat:function(a,b){if(a.length===0||b.length===0)return a.concat(b);var c=a[a.length-1],d=sjcl.bitArray.getPartial(c);return d===32?a.concat(b):sjcl.bitArray.P(b,d,c|0,a.slice(0,a.length-1))},bitLength:function(a){var b=a.length;
|
||||
if(b===0)return 0;return(b-1)*32+sjcl.bitArray.getPartial(a[b-1])},clamp:function(a,b){if(a.length*32<b)return a;a=a.slice(0,Math.ceil(b/32));var c=a.length;b&=31;if(c>0&&b)a[c-1]=sjcl.bitArray.partial(b,a[c-1]&2147483648>>b-1,1);return a},partial:function(a,b,c){if(a===32)return b;return(c?b|0:b<<32-a)+a*0x10000000000},getPartial:function(a){return Math.round(a/0x10000000000)||32},equal:function(a,b){if(sjcl.bitArray.bitLength(a)!==sjcl.bitArray.bitLength(b))return false;var c=0,d;for(d=0;d<a.length;d++)c|=
|
||||
a[d]^b[d];return c===0},P:function(a,b,c,d){var e;e=0;if(d===undefined)d=[];for(;b>=32;b-=32){d.push(c);c=0}if(b===0)return d.concat(a);for(e=0;e<a.length;e++){d.push(c|a[e]>>>b);c=a[e]<<32-b}e=a.length?a[a.length-1]:0;a=sjcl.bitArray.getPartial(e);d.push(sjcl.bitArray.partial(b+a&31,b+a>32?c:d.pop(),1));return d},k:function(a,b){return[a[0]^b[0],a[1]^b[1],a[2]^b[2],a[3]^b[3]]}};
|
||||
sjcl.codec.utf8String={fromBits:function(a){var b="",c=sjcl.bitArray.bitLength(a),d,e;for(d=0;d<c/8;d++){if((d&3)===0)e=a[d/4];b+=String.fromCharCode(e>>>24);e<<=8}return decodeURIComponent(escape(b))},toBits:function(a){a=unescape(encodeURIComponent(a));var b=[],c,d=0;for(c=0;c<a.length;c++){d=d<<8|a.charCodeAt(c);if((c&3)===3){b.push(d);d=0}}c&3&&b.push(sjcl.bitArray.partial(8*(c&3),d));return b}};
|
||||
sjcl.codec.hex={fromBits:function(a){var b="",c;for(c=0;c<a.length;c++)b+=((a[c]|0)+0xf00000000000).toString(16).substr(4);return b.substr(0,sjcl.bitArray.bitLength(a)/4)},toBits:function(a){var b,c=[],d;a=a.replace(/\s|0x/g,"");d=a.length;a+="00000000";for(b=0;b<a.length;b+=8)c.push(parseInt(a.substr(b,8),16)^0);return sjcl.bitArray.clamp(c,d*4)}};
|
||||
sjcl.codec.base64={D:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",fromBits:function(a,b,c){var d="",e=0,f=sjcl.codec.base64.D,g=0,h=sjcl.bitArray.bitLength(a);if(c)f=f.substr(0,62)+"-_";for(c=0;d.length*6<h;){d+=f.charAt((g^a[c]>>>e)>>>26);if(e<6){g=a[c]<<6-e;e+=26;c++}else{g<<=6;e-=6}}for(;d.length&3&&!b;)d+="=";return d},toBits:function(a,b){a=a.replace(/\s|=/g,"");var c=[],d=0,e=sjcl.codec.base64.D,f=0,g;if(b)e=e.substr(0,62)+"-_";for(b=0;b<a.length;b++){g=e.indexOf(a.charAt(b));
|
||||
if(g<0)throw new sjcl.exception.invalid("this isn't base64!");if(d>26){d-=26;c.push(f^g>>>d);f=g<<32-d}else{d+=6;f^=g<<32-d}}d&56&&c.push(sjcl.bitArray.partial(d&56,f,1));return c}};sjcl.codec.base64url={fromBits:function(a){return sjcl.codec.base64.fromBits(a,1,1)},toBits:function(a){return sjcl.codec.base64.toBits(a,1)}};sjcl.hash.sha256=function(a){this.a[0]||this.w();if(a){this.n=a.n.slice(0);this.i=a.i.slice(0);this.e=a.e}else this.reset()};sjcl.hash.sha256.hash=function(a){return(new sjcl.hash.sha256).update(a).finalize()};
|
||||
sjcl.hash.sha256.prototype={blockSize:512,reset:function(){this.n=this.N.slice(0);this.i=[];this.e=0;return this},update:function(a){if(typeof a==="string")a=sjcl.codec.utf8String.toBits(a);var b,c=this.i=sjcl.bitArray.concat(this.i,a);b=this.e;a=this.e=b+sjcl.bitArray.bitLength(a);for(b=512+b&-512;b<=a;b+=512)this.C(c.splice(0,16));return this},finalize:function(){var a,b=this.i,c=this.n;b=sjcl.bitArray.concat(b,[sjcl.bitArray.partial(1,1)]);for(a=b.length+2;a&15;a++)b.push(0);b.push(Math.floor(this.e/
|
||||
4294967296));for(b.push(this.e|0);b.length;)this.C(b.splice(0,16));this.reset();return c},N:[],a:[],w:function(){function a(e){return(e-Math.floor(e))*0x100000000|0}var b=0,c=2,d;a:for(;b<64;c++){for(d=2;d*d<=c;d++)if(c%d===0)continue a;if(b<8)this.N[b]=a(Math.pow(c,0.5));this.a[b]=a(Math.pow(c,1/3));b++}},C:function(a){var b,c,d=a.slice(0),e=this.n,f=this.a,g=e[0],h=e[1],i=e[2],k=e[3],j=e[4],l=e[5],m=e[6],n=e[7];for(a=0;a<64;a++){if(a<16)b=d[a];else{b=d[a+1&15];c=d[a+14&15];b=d[a&15]=(b>>>7^b>>>18^
|
||||
b>>>3^b<<25^b<<14)+(c>>>17^c>>>19^c>>>10^c<<15^c<<13)+d[a&15]+d[a+9&15]|0}b=b+n+(j>>>6^j>>>11^j>>>25^j<<26^j<<21^j<<7)+(m^j&(l^m))+f[a];n=m;m=l;l=j;j=k+b|0;k=i;i=h;h=g;g=b+(h&i^k&(h^i))+(h>>>2^h>>>13^h>>>22^h<<30^h<<19^h<<10)|0}e[0]=e[0]+g|0;e[1]=e[1]+h|0;e[2]=e[2]+i|0;e[3]=e[3]+k|0;e[4]=e[4]+j|0;e[5]=e[5]+l|0;e[6]=e[6]+m|0;e[7]=e[7]+n|0}};
|
||||
sjcl.mode.ccm={name:"ccm",encrypt:function(a,b,c,d,e){var f,g=b.slice(0),h=sjcl.bitArray,i=h.bitLength(c)/8,k=h.bitLength(g)/8;e=e||64;d=d||[];if(i<7)throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");for(f=2;f<4&&k>>>8*f;f++);if(f<15-i)f=15-i;c=h.clamp(c,8*(15-f));b=sjcl.mode.ccm.G(a,b,c,d,e,f);g=sjcl.mode.ccm.I(a,g,c,b,e,f);return h.concat(g.data,g.tag)},decrypt:function(a,b,c,d,e){e=e||64;d=d||[];var f=sjcl.bitArray,g=f.bitLength(c)/8,h=f.bitLength(b),i=f.clamp(b,h-e),k=f.bitSlice(b,
|
||||
h-e);h=(h-e)/8;if(g<7)throw new sjcl.exception.invalid("ccm: iv must be at least 7 bytes");for(b=2;b<4&&h>>>8*b;b++);if(b<15-g)b=15-g;c=f.clamp(c,8*(15-b));i=sjcl.mode.ccm.I(a,i,c,k,e,b);a=sjcl.mode.ccm.G(a,i.data,c,d,e,b);if(!f.equal(i.tag,a))throw new sjcl.exception.corrupt("ccm: tag doesn't match");return i.data},G:function(a,b,c,d,e,f){var g=[],h=sjcl.bitArray,i=h.k;e/=8;if(e%2||e<4||e>16)throw new sjcl.exception.invalid("ccm: invalid tag length");if(d.length>0xffffffff||b.length>0xffffffff)throw new sjcl.exception.bug("ccm: can't deal with 4GiB or more data");
|
||||
f=[h.partial(8,(d.length?64:0)|e-2<<2|f-1)];f=h.concat(f,c);f[3]|=h.bitLength(b)/8;f=a.encrypt(f);if(d.length){c=h.bitLength(d)/8;if(c<=65279)g=[h.partial(16,c)];else if(c<=0xffffffff)g=h.concat([h.partial(16,65534)],[c]);g=h.concat(g,d);for(d=0;d<g.length;d+=4)f=a.encrypt(i(f,g.slice(d,d+4).concat([0,0,0])))}for(d=0;d<b.length;d+=4)f=a.encrypt(i(f,b.slice(d,d+4).concat([0,0,0])));return h.clamp(f,e*8)},I:function(a,b,c,d,e,f){var g,h=sjcl.bitArray;g=h.k;var i=b.length,k=h.bitLength(b);c=h.concat([h.partial(8,
|
||||
f-1)],c).concat([0,0,0]).slice(0,4);d=h.bitSlice(g(d,a.encrypt(c)),0,e);if(!i)return{tag:d,data:[]};for(g=0;g<i;g+=4){c[3]++;e=a.encrypt(c);b[g]^=e[0];b[g+1]^=e[1];b[g+2]^=e[2];b[g+3]^=e[3]}return{tag:d,data:h.clamp(b,k)}}};
|
||||
sjcl.mode.ocb2={name:"ocb2",encrypt:function(a,b,c,d,e,f){if(sjcl.bitArray.bitLength(c)!==128)throw new sjcl.exception.invalid("ocb iv must be 128 bits");var g,h=sjcl.mode.ocb2.A,i=sjcl.bitArray,k=i.k,j=[0,0,0,0];c=h(a.encrypt(c));var l,m=[];d=d||[];e=e||64;for(g=0;g+4<b.length;g+=4){l=b.slice(g,g+4);j=k(j,l);m=m.concat(k(c,a.encrypt(k(c,l))));c=h(c)}l=b.slice(g);b=i.bitLength(l);g=a.encrypt(k(c,[0,0,0,b]));l=i.clamp(k(l.concat([0,0,0]),g),b);j=k(j,k(l.concat([0,0,0]),g));j=a.encrypt(k(j,k(c,h(c))));
|
||||
if(d.length)j=k(j,f?d:sjcl.mode.ocb2.pmac(a,d));return m.concat(i.concat(l,i.clamp(j,e)))},decrypt:function(a,b,c,d,e,f){if(sjcl.bitArray.bitLength(c)!==128)throw new sjcl.exception.invalid("ocb iv must be 128 bits");e=e||64;var g=sjcl.mode.ocb2.A,h=sjcl.bitArray,i=h.k,k=[0,0,0,0],j=g(a.encrypt(c)),l,m,n=sjcl.bitArray.bitLength(b)-e,o=[];d=d||[];for(c=0;c+4<n/32;c+=4){l=i(j,a.decrypt(i(j,b.slice(c,c+4))));k=i(k,l);o=o.concat(l);j=g(j)}m=n-c*32;l=a.encrypt(i(j,[0,0,0,m]));l=i(l,h.clamp(b.slice(c),
|
||||
m).concat([0,0,0]));k=i(k,l);k=a.encrypt(i(k,i(j,g(j))));if(d.length)k=i(k,f?d:sjcl.mode.ocb2.pmac(a,d));if(!h.equal(h.clamp(k,e),h.bitSlice(b,n)))throw new sjcl.exception.corrupt("ocb: tag doesn't match");return o.concat(h.clamp(l,m))},pmac:function(a,b){var c,d=sjcl.mode.ocb2.A,e=sjcl.bitArray,f=e.k,g=[0,0,0,0],h=a.encrypt([0,0,0,0]);h=f(h,d(d(h)));for(c=0;c+4<b.length;c+=4){h=d(h);g=f(g,a.encrypt(f(h,b.slice(c,c+4))))}b=b.slice(c);if(e.bitLength(b)<128){h=f(h,d(h));b=e.concat(b,[2147483648|0,0,
|
||||
0,0])}g=f(g,b);return a.encrypt(f(d(f(h,d(h))),g))},A:function(a){return[a[0]<<1^a[1]>>>31,a[1]<<1^a[2]>>>31,a[2]<<1^a[3]>>>31,a[3]<<1^(a[0]>>>31)*135]}};sjcl.misc.hmac=function(a,b){this.M=b=b||sjcl.hash.sha256;var c=[[],[]],d=b.prototype.blockSize/32;this.l=[new b,new b];if(a.length>d)a=b.hash(a);for(b=0;b<d;b++){c[0][b]=a[b]^909522486;c[1][b]=a[b]^1549556828}this.l[0].update(c[0]);this.l[1].update(c[1])};
|
||||
sjcl.misc.hmac.prototype.encrypt=sjcl.misc.hmac.prototype.mac=function(a,b){a=(new this.M(this.l[0])).update(a,b).finalize();return(new this.M(this.l[1])).update(a).finalize()};
|
||||
sjcl.misc.pbkdf2=function(a,b,c,d,e){c=c||1E3;if(d<0||c<0)throw sjcl.exception.invalid("invalid params to pbkdf2");if(typeof a==="string")a=sjcl.codec.utf8String.toBits(a);e=e||sjcl.misc.hmac;a=new e(a);var f,g,h,i,k=[],j=sjcl.bitArray;for(i=1;32*k.length<(d||1);i++){e=f=a.encrypt(j.concat(b,[i]));for(g=1;g<c;g++){f=a.encrypt(f);for(h=0;h<f.length;h++)e[h]^=f[h]}k=k.concat(e)}if(d)k=j.clamp(k,d);return k};
|
||||
sjcl.random={randomWords:function(a,b){var c=[];b=this.isReady(b);var d;if(b===0)throw new sjcl.exception.notReady("generator isn't seeded");else b&2&&this.U(!(b&1));for(b=0;b<a;b+=4){(b+1)%0x10000===0&&this.L();d=this.u();c.push(d[0],d[1],d[2],d[3])}this.L();return c.slice(0,a)},setDefaultParanoia:function(a){this.t=a},addEntropy:function(a,b,c){c=c||"user";var d,e,f=(new Date).valueOf(),g=this.q[c],h=this.isReady();d=this.F[c];if(d===undefined)d=this.F[c]=this.R++;if(g===undefined)g=this.q[c]=0;this.q[c]=
|
||||
(this.q[c]+1)%this.b.length;switch(typeof a){case "number":break;case "object":if(b===undefined)for(c=b=0;c<a.length;c++)for(e=a[c];e>0;){b++;e>>>=1}this.b[g].update([d,this.J++,2,b,f,a.length].concat(a));break;case "string":if(b===undefined)b=a.length;this.b[g].update([d,this.J++,3,b,f,a.length]);this.b[g].update(a);break;default:throw new sjcl.exception.bug("random: addEntropy only supports number, array or string");}this.j[g]+=b;this.f+=b;if(h===0){this.isReady()!==0&&this.K("seeded",Math.max(this.g,
|
||||
this.f));this.K("progress",this.getProgress())}},isReady:function(a){a=this.B[a!==undefined?a:this.t];return this.g&&this.g>=a?this.j[0]>80&&(new Date).valueOf()>this.O?3:1:this.f>=a?2:0},getProgress:function(a){a=this.B[a?a:this.t];return this.g>=a?1["0"]:this.f>a?1["0"]:this.f/a},startCollectors:function(){if(!this.m){if(window.addEventListener){window.addEventListener("load",this.o,false);window.addEventListener("mousemove",this.p,false)}else if(document.attachEvent){document.attachEvent("onload",
|
||||
this.o);document.attachEvent("onmousemove",this.p)}else throw new sjcl.exception.bug("can't attach event");this.m=true}},stopCollectors:function(){if(this.m){if(window.removeEventListener){window.removeEventListener("load",this.o,false);window.removeEventListener("mousemove",this.p,false)}else if(window.detachEvent){window.detachEvent("onload",this.o);window.detachEvent("onmousemove",this.p)}this.m=false}},addEventListener:function(a,b){this.r[a][this.Q++]=b},removeEventListener:function(a,b){var c;
|
||||
a=this.r[a];var d=[];for(c in a)a.hasOwnProperty(c)&&a[c]===b&&d.push(c);for(b=0;b<d.length;b++){c=d[b];delete a[c]}},b:[new sjcl.hash.sha256],j:[0],z:0,q:{},J:0,F:{},R:0,g:0,f:0,O:0,a:[0,0,0,0,0,0,0,0],d:[0,0,0,0],s:undefined,t:6,m:false,r:{progress:{},seeded:{}},Q:0,B:[0,48,64,96,128,192,0x100,384,512,768,1024],u:function(){for(var a=0;a<4;a++){this.d[a]=this.d[a]+1|0;if(this.d[a])break}return this.s.encrypt(this.d)},L:function(){this.a=this.u().concat(this.u());this.s=new sjcl.cipher.aes(this.a)},
|
||||
T:function(a){this.a=sjcl.hash.sha256.hash(this.a.concat(a));this.s=new sjcl.cipher.aes(this.a);for(a=0;a<4;a++){this.d[a]=this.d[a]+1|0;if(this.d[a])break}},U:function(a){var b=[],c=0,d;this.O=b[0]=(new Date).valueOf()+3E4;for(d=0;d<16;d++)b.push(Math.random()*0x100000000|0);for(d=0;d<this.b.length;d++){b=b.concat(this.b[d].finalize());c+=this.j[d];this.j[d]=0;if(!a&&this.z&1<<d)break}if(this.z>=1<<this.b.length){this.b.push(new sjcl.hash.sha256);this.j.push(0)}this.f-=c;if(c>this.g)this.g=c;this.z++;
|
||||
this.T(b)},p:function(a){sjcl.random.addEntropy([a.x||a.clientX||a.offsetX,a.y||a.clientY||a.offsetY],2,"mouse")},o:function(){sjcl.random.addEntropy(new Date,2,"loadtime")},K:function(a,b){var c;a=sjcl.random.r[a];var d=[];for(c in a)a.hasOwnProperty(c)&&d.push(a[c]);for(c=0;c<d.length;c++)d[c](b)}};try{var s=new Uint32Array(32);crypto.getRandomValues(s);sjcl.random.addEntropy(s,1024,"crypto['getRandomValues']")}catch(t){}
|
||||
sjcl.json={defaults:{v:1,iter:1E3,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},encrypt:function(a,b,c,d){c=c||{};d=d||{};var e=sjcl.json,f=e.c({iv:sjcl.random.randomWords(4,0)},e.defaults),g;e.c(f,c);c=f.adata;if(typeof f.salt==="string")f.salt=sjcl.codec.base64.toBits(f.salt);if(typeof f.iv==="string")f.iv=sjcl.codec.base64.toBits(f.iv);if(!sjcl.mode[f.mode]||!sjcl.cipher[f.cipher]||typeof a==="string"&&f.iter<=100||f.ts!==64&&f.ts!==96&&f.ts!==128||f.ks!==128&&f.ks!==192&&f.ks!==0x100||f.iv.length<
|
||||
2||f.iv.length>4)throw new sjcl.exception.invalid("json encrypt: invalid parameters");if(typeof a==="string"){g=sjcl.misc.cachedPbkdf2(a,f);a=g.key.slice(0,f.ks/32);f.salt=g.salt}if(typeof b==="string")b=sjcl.codec.utf8String.toBits(b);if(typeof c==="string")c=sjcl.codec.utf8String.toBits(c);g=new sjcl.cipher[f.cipher](a);e.c(d,f);d.key=a;f.ct=sjcl.mode[f.mode].encrypt(g,b,f.iv,c,f.ts);return e.encode(e.V(f,e.defaults))},decrypt:function(a,b,c,d){c=c||{};d=d||{};var e=sjcl.json;b=e.c(e.c(e.c({},e.defaults),
|
||||
e.decode(b)),c,true);var f;c=b.adata;if(typeof b.salt==="string")b.salt=sjcl.codec.base64.toBits(b.salt);if(typeof b.iv==="string")b.iv=sjcl.codec.base64.toBits(b.iv);if(!sjcl.mode[b.mode]||!sjcl.cipher[b.cipher]||typeof a==="string"&&b.iter<=100||b.ts!==64&&b.ts!==96&&b.ts!==128||b.ks!==128&&b.ks!==192&&b.ks!==0x100||!b.iv||b.iv.length<2||b.iv.length>4)throw new sjcl.exception.invalid("json decrypt: invalid parameters");if(typeof a==="string"){f=sjcl.misc.cachedPbkdf2(a,b);a=f.key.slice(0,b.ks/32);
|
||||
b.salt=f.salt}if(typeof c==="string")c=sjcl.codec.utf8String.toBits(c);f=new sjcl.cipher[b.cipher](a);c=sjcl.mode[b.mode].decrypt(f,b.ct,b.iv,c,b.ts);e.c(d,b);d.key=a;return sjcl.codec.utf8String.fromBits(c)},encode:function(a){var b,c="{",d="";for(b in a)if(a.hasOwnProperty(b)){if(!b.match(/^[a-z0-9]+$/i))throw new sjcl.exception.invalid("json encode: invalid property name");c+=d+'"'+b+'":';d=",";switch(typeof a[b]){case "number":case "boolean":c+=a[b];break;case "string":c+='"'+escape(a[b])+'"';
|
||||
break;case "object":c+='"'+sjcl.codec.base64.fromBits(a[b],1)+'"';break;default:throw new sjcl.exception.bug("json encode: unsupported type");}}return c+"}"},decode:function(a){a=a.replace(/\s/g,"");if(!a.match(/^\{.*\}$/))throw new sjcl.exception.invalid("json decode: this isn't json!");a=a.replace(/^\{|\}$/g,"").split(/,/);var b={},c,d;for(c=0;c<a.length;c++){if(!(d=a[c].match(/^(?:(["']?)([a-z][a-z0-9]*)\1):(?:(\d+)|"([a-z0-9+\/%*_.@=\-]*)")$/i)))throw new sjcl.exception.invalid("json decode: this isn't json!");
|
||||
b[d[2]]=d[3]?parseInt(d[3],10):d[2].match(/^(ct|salt|iv)$/)?sjcl.codec.base64.toBits(d[4]):unescape(d[4])}return b},c:function(a,b,c){if(a===undefined)a={};if(b===undefined)return a;var d;for(d in b)if(b.hasOwnProperty(d)){if(c&&a[d]!==undefined&&a[d]!==b[d])throw new sjcl.exception.invalid("required parameter overridden");a[d]=b[d]}return a},V:function(a,b){var c={},d;for(d in a)if(a.hasOwnProperty(d)&&a[d]!==b[d])c[d]=a[d];return c},W:function(a,b){var c={},d;for(d=0;d<b.length;d++)if(a[b[d]]!==
|
||||
undefined)c[b[d]]=a[b[d]];return c}};sjcl.encrypt=sjcl.json.encrypt;sjcl.decrypt=sjcl.json.decrypt;sjcl.misc.S={};sjcl.misc.cachedPbkdf2=function(a,b){var c=sjcl.misc.S,d;b=b||{};d=b.iter||1E3;c=c[a]=c[a]||{};d=c[d]=c[d]||{firstSalt:b.salt&&b.salt.length?b.salt.slice(0):sjcl.random.randomWords(2,0)};c=b.salt===undefined?d.firstSalt:b.salt;d[c]=d[c]||sjcl.misc.pbkdf2(a,c,b.iter);return{key:d[c].slice(0),salt:c.slice(0)}};
|
2
zerobin/static/js/vizhash.min.js
vendored
Normal file
2
zerobin/static/js/vizhash.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user