2
2
// https://github.com/open-eid/hwcrypto.js
3
3
var hwcrypto = ( function hwcrypto ( ) {
4
4
'use strict' ;
5
- console . log ( "hwcrypto.js activated" ) ;
5
+ var _debug = function ( x ) {
6
+ // console.log(x);
7
+ } ;
8
+ _debug ( "hwcrypto.js activated" ) ;
6
9
// Fix up IE8
7
10
window . addEventListener = window . addEventListener || window . attachEvent ;
8
11
// Returns "true" if a plugin is present for the MIME
@@ -42,10 +45,10 @@ var hwcrypto = (function hwcrypto() {
42
45
function loadPluginFor ( mime ) {
43
46
var element = _mimeid ( mime ) ;
44
47
if ( document . getElementById ( element ) ) {
45
- console . log ( "Plugin element already loaded" ) ;
48
+ _debug ( "Plugin element already loaded" ) ;
46
49
return document . getElementById ( element ) ;
47
50
}
48
- console . log ( 'Loading plugin for ' + mime + ' into ' + element ) ;
51
+ _debug ( 'Loading plugin for ' + mime + ' into ' + element ) ;
49
52
// Must insert tag as string (not as an Element object) so that IE9 can access plugin methods
50
53
var objectTag = '<object id="' + element + '" type="' + mime + '" style="width: 1px; height: 1px; position: absolute; visibility: hidden;"></object>' ;
51
54
var div = document . createElement ( "div" ) ;
@@ -70,10 +73,10 @@ var hwcrypto = (function hwcrypto() {
70
73
var msg = 'probe() detected ' ;
71
74
// First try Chrome extensions
72
75
if ( hasExtensionFor ( digidoc_chrome ) ) {
73
- console . log ( msg + digidoc_chrome ) ;
76
+ _debug ( msg + digidoc_chrome ) ;
74
77
}
75
78
if ( hasPluginFor ( digidoc_mime ) ) {
76
- console . log ( msg + digidoc_mime ) ;
79
+ _debug ( msg + digidoc_mime ) ;
77
80
}
78
81
}
79
82
// TODO: remove
@@ -89,7 +92,7 @@ var hwcrypto = (function hwcrypto() {
89
92
var certificate_ids = { } ;
90
93
91
94
function code2str ( err ) {
92
- console . log ( "Error: " + err + " with: " + p . errorMessage ) ;
95
+ _debug ( "Error: " + err + " with: " + p . errorMessage ) ;
93
96
switch ( parseInt ( err ) ) {
94
97
case 1 :
95
98
return USER_CANCEL ;
@@ -101,7 +104,7 @@ var hwcrypto = (function hwcrypto() {
101
104
case 19 :
102
105
return NOT_ALLOWED ;
103
106
default :
104
- console . log ( "Unknown error: " + err + " with: " + p . errorMessage ) ;
107
+ _debug ( "Unknown error: " + err + " with: " + p . errorMessage ) ;
105
108
return TECHNICAL_ERROR ;
106
109
}
107
110
}
@@ -141,7 +144,7 @@ var hwcrypto = (function hwcrypto() {
141
144
} ) ;
142
145
}
143
146
} catch ( ex ) {
144
- console . log ( ex ) ;
147
+ _debug ( ex ) ;
145
148
reject ( code2err ( p . errorCode ) ) ;
146
149
}
147
150
} ) ;
@@ -160,11 +163,11 @@ var hwcrypto = (function hwcrypto() {
160
163
hex : v
161
164
} ) ;
162
165
} catch ( ex ) {
163
- console . log ( JSON . stringify ( ex ) ) ;
166
+ _debug ( JSON . stringify ( ex ) ) ;
164
167
reject ( code2err ( p . errorCode ) ) ;
165
168
}
166
169
} else {
167
- console . log ( "invalid certificate: " + cert ) ;
170
+ _debug ( "invalid certificate: " + cert ) ;
168
171
reject ( new Error ( INVALID_ARGUMENT ) ) ;
169
172
}
170
173
} ) ;
@@ -227,11 +230,11 @@ var hwcrypto = (function hwcrypto() {
227
230
var b = new Backend ( ) ;
228
231
b . check ( ) . then ( function ( isLoaded ) {
229
232
if ( isLoaded ) {
230
- console . log ( "Using backend: " + b . _name ) ;
233
+ _debug ( "Using backend: " + b . _name ) ;
231
234
_backend = b ;
232
235
resolve ( true ) ;
233
236
} else {
234
- console . log ( b . _name + " check() failed" ) ;
237
+ _debug ( b . _name + " check() failed" ) ;
235
238
resolve ( false ) ;
236
239
}
237
240
} ) ;
@@ -240,7 +243,7 @@ var hwcrypto = (function hwcrypto() {
240
243
241
244
function _autodetect ( force ) {
242
245
return new Promise ( function ( resolve , reject ) {
243
- console . log ( "Autodetecting best backend" ) ;
246
+ _debug ( "Autodetecting best backend" ) ;
244
247
if ( typeof force === 'undefined' ) {
245
248
force = false ;
246
249
}
@@ -260,7 +263,7 @@ var hwcrypto = (function hwcrypto() {
260
263
261
264
// IE BHO
262
265
if ( navigator . userAgent . indexOf ( "MSIE" ) != - 1 || navigator . userAgent . indexOf ( "Trident" ) != - 1 ) {
263
- console . log ( "Assuming IE BHO, testing" ) ;
266
+ _debug ( "Assuming IE BHO, testing" ) ;
264
267
return tryDigiDocPlugin ( ) ;
265
268
}
266
269
@@ -317,7 +320,7 @@ var hwcrypto = (function hwcrypto() {
317
320
// Get a certificate
318
321
fields . getCertificate = function ( options ) {
319
322
if ( typeof options !== 'object' ) {
320
- console . log ( "getCertificate options parameter must be an object" ) ;
323
+ _debug ( "getCertificate options parameter must be an object" ) ;
321
324
return Promise . reject ( new Error ( INVALID_ARGUMENT ) ) ;
322
325
}
323
326
// If options does not specify a language, set to 'en'
@@ -352,7 +355,7 @@ var hwcrypto = (function hwcrypto() {
352
355
// Convert Hash to hex and vice versa.
353
356
// TODO: All backends currently expect the presence of Hex.
354
357
if ( hash . hex && ! hash . value ) {
355
- console . log ( "DEPRECATED: hash.hex as argument to sign() is deprecated, use hash.value instead" ) ;
358
+ _debug ( "DEPRECATED: hash.hex as argument to sign() is deprecated, use hash.value instead" ) ;
356
359
hash . value = _hex2array ( hash . hex ) ;
357
360
}
358
361
if ( hash . value && ! hash . hex )
0 commit comments