Initial commit. Experimental cross-platform frontend for yubikey programming.
/*######################################################################
### YubiKey global namespace
######################################################################*/
var Y = {
// Information for the currently inserted key.
keyinfo: {},
// Declared windows, for easy referencing
window: {},
// Convert a string to hexadecimal.
//
toHex: function( string ) {
var hex = '';
for( var i = 0; i < string.length; i++ )
hex += string.charCodeAt(i).toString(16);
return hex;
},
// Return a random string of +length+.
//
randString: function( length ) {
var text = '';
var set = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for( var i = 0; i < length; i++ )
text += set.charAt( Math.floor(Math.random() * set.length) );
return text;
},
// Generic delayed callback that returns the timer handle.
//
delay: (function() {
var timer = null;
return function( callback, ms, clear_previous ) {
if ( clear_previous) clearTimeout( timer );
timer = setTimeout( callback, ms );
return timer;
};
})(),
// Stop the default webkit behavior (viewer) when you drag a file into a window.
//
disableDragDrop: function( window ) {
window.ondragover = function(e) { e.preventDefault(); return false };
window.ondrop = function(e) { e.preventDefault(); return false };
},
// Node's filesystem interface.
fs: require( 'fs' ),
// Manage child processes.
spawn: require( 'child_process' ).spawn
};
// Make the 'Y' namespace available elsewhere.
global.Y = Y;