Skip to content

Commit

Permalink
Modifications according to PR #29 comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vellotis committed Jan 6, 2017
1 parent b75c6e9 commit 54d12eb
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 96 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/gh-pages
/dist
/build
/hwcrypto.js
6 changes: 1 addition & 5 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
export const VERSION = '@@hwcryptoversion'

export const digidoc_mime = 'application/x-digidoc'
export const digidoc_chrome = 'TokenSigning'

export const USER_CANCEL = 'user_cancel'
export const NO_CERTIFICATES = 'no_certificates'
export const INVALID_ARGUMENT = 'invalid_argument'
export const TECHNICAL_ERROR = 'technical_error'
export const NO_IMPLEMENTATION = 'no_implementation'
export const NOT_ALLOWED = 'not_allowed'

export const localServiceURL = 'https://local.ria.ee'
export const defaultXHRTimeout = 5000
export const defaultXHRTimeout = 5000
6 changes: 3 additions & 3 deletions src/hwcrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// https://github.com/open-eid/hwcrypto.js
import { _debug, _array2hex, _hex2array, hasExtensionFor, hasPluginFor } from './utils'
import * as CONSTANTS from './constants'
import { enabledPlugins } from './interfaces'
import { enabledBackends } from './interfaces'
import NoBackend from './NotImplementedPlugin'

let _backend = null
Expand All @@ -31,7 +31,7 @@ function _autodetect(force) {
}

function tryToApplyPlugin() {
return enabledPlugins.reduce(function(promise, Plugin) {
return enabledBackends.reduce(function(promise, Plugin) {
return promise.then(function(result) {
if (result) {
return result
Expand Down Expand Up @@ -84,7 +84,7 @@ function _performCrypto(method, cert, hash, options = {}) {
class hwcrypto {
static use(backend) {
function tryToFindAndUsePlugin() {
return enabledPlugins.reduce(function(promise, Plugin) {
return enabledBackends.reduce(function(promise, Plugin) {
return promise.then(function(result) {
if (!result && Plugin._id === backend) {
return _testAndUse(Plugin)
Expand Down
8 changes: 5 additions & 3 deletions src/interfaces/DigiDocExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import NotImplementedPlugin from '../NotImplementedPlugin'
import * as CONSTANTS from '../constants'
import { hasExtensionFor } from '../utils'

const digidoc_chrome = 'TokenSigning'

class DigiDocExtension extends NotImplementedPlugin {
static get _id() { return 'chrome' }

static isApplicable() {
const isChrome = navigator.userAgent.indexOf("Chrome") != -1
return Promise.resolve(isChrome && hasExtensionFor(CONSTANTS.digidoc_chrome))
return Promise.resolve(isChrome && hasExtensionFor(digidoc_chrome))
}

constructor() {
Expand All @@ -22,8 +24,8 @@ class DigiDocExtension extends NotImplementedPlugin {

check() {
const extensionFound =
hasExtensionFor(CONSTANTS.digidoc_chrome)
&& !!(this.interface = new window[CONSTANTS.digidoc_chrome]())
hasExtensionFor(digidoc_chrome)
&& !!(this.interface = new window[digidoc_chrome]())
return Promise.resolve(extensionFound)
}

Expand Down
7 changes: 5 additions & 2 deletions src/interfaces/DigiDocPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { hasPluginFor, loadPluginFor, _debug } from '../utils'
import * as CONSTANTS from '../constants'
import NotImplementedPlugin from '../NotImplementedPlugin'

//
const digidoc_mime = 'application/x-digidoc'

function code2str(err) {
_debug("Error: " + err + " with: " + this.interface.errorMessage)
switch (parseInt(err)) {
Expand All @@ -29,12 +32,12 @@ class DigiDocPlugin extends NotImplementedPlugin {
_debug("Assuming IE BHO, testing")
const isMSIE = navigator.userAgent.indexOf("MSIE") !== -1
const isTrident = navigator.userAgent.indexOf("Trident") !== -1
return Promise.resolve(isMSIE || isTrident || hasPluginFor(CONSTANTS.digidoc_mime))
return Promise.resolve(isMSIE || isTrident || hasPluginFor(digidoc_mime))
}

constructor() {
super()
this.interface = loadPluginFor(CONSTANTS.digidoc_mime) || {}
this.interface = loadPluginFor(digidoc_mime) || {}
}

get _name() {
Expand Down
79 changes: 0 additions & 79 deletions src/interfaces/DigiDocServlet.js

This file was deleted.

6 changes: 2 additions & 4 deletions src/interfaces/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import DigiDocPlugin from './DigiDocPlugin'
import DigiDocExtension from './DigiDocExtension'
import DigiDocServlet from './DigiDocServlet'

const enabledPlugins = [
DigiDocServlet,
const enabledBackends = [
DigiDocPlugin,
DigiDocExtension
]

export { DigiDocPlugin, DigiDocExtension, DigiDocServlet, enabledPlugins }
export { enabledBackends }

0 comments on commit 54d12eb

Please sign in to comment.