Skip to content

Commit

Permalink
refactor service to native class
Browse files Browse the repository at this point in the history
  • Loading branch information
jelhan committed Jan 10, 2020
1 parent 2e372b6 commit cbad6ef
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions app/services/encryption.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import classic from 'ember-classic-decorator';
import Service from '@ember/service';
import generatePassphrase from '../utils/generate-passphrase';
import sjcl from 'sjcl';

export default Service.extend({
key: null,
@classic
export default class EncryptionService extends Service {
key = null;

decrypt(value) {
return JSON.parse(
Expand All @@ -12,21 +14,17 @@ export default Service.extend({
value
)
);
},
}

encrypt(value) {
return sjcl.encrypt(
this.key,
JSON.stringify(value)
);
},
}

generateKey() {
const passphraseLength = 40;
this.set('key', generatePassphrase(passphraseLength));
},

init() {
this._super(...arguments);
}
});
}

0 comments on commit cbad6ef

Please sign in to comment.