author | Mahlon E. Smith <mahlon@martini.nu> |
Mon, 09 Feb 2015 09:20:01 -0800 | |
changeset 0 | 52d30e6014a0 |
permissions | -rw-r--r-- |
0
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1 |
/*###################################################################### |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2 |
### YubiKey global namespace |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3 |
######################################################################*/ |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4 |
var Y = { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
6 |
// Information for the currently inserted key. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7 |
keyinfo: {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
8 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
9 |
// Declared windows, for easy referencing |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
10 |
window: {}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
11 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
12 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
13 |
// Convert a string to hexadecimal. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
14 |
// |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
15 |
toHex: function( string ) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
16 |
var hex = ''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
17 |
for( var i = 0; i < string.length; i++ ) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
18 |
hex += string.charCodeAt(i).toString(16); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
19 |
return hex; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
20 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
21 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
22 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
23 |
// Return a random string of +length+. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
24 |
// |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
25 |
randString: function( length ) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
26 |
var text = ''; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
27 |
var set = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
28 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
29 |
for( var i = 0; i < length; i++ ) |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
30 |
text += set.charAt( Math.floor(Math.random() * set.length) ); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
31 |
return text; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
32 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
33 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
34 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
35 |
// Generic delayed callback that returns the timer handle. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
36 |
// |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
37 |
delay: (function() { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
38 |
var timer = null; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
39 |
return function( callback, ms, clear_previous ) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
40 |
if ( clear_previous) clearTimeout( timer ); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
41 |
timer = setTimeout( callback, ms ); |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
42 |
return timer; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
43 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
44 |
})(), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
45 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
46 |
// Stop the default webkit behavior (viewer) when you drag a file into a window. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
47 |
// |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
48 |
disableDragDrop: function( window ) { |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
49 |
window.ondragover = function(e) { e.preventDefault(); return false }; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
50 |
window.ondrop = function(e) { e.preventDefault(); return false }; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
51 |
}, |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
52 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
53 |
// Node's filesystem interface. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
54 |
fs: require( 'fs' ), |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
55 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
56 |
// Manage child processes. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
57 |
spawn: require( 'child_process' ).spawn |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
58 |
}; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
59 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
60 |
|
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
61 |
// Make the 'Y' namespace available elsewhere. |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
62 |
global.Y = Y; |
52d30e6014a0
Initial commit. Experimental cross-platform frontend for yubikey programming.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
63 |