mirror of
https://github.com/moparisthebest/mail
synced 2025-01-30 22:50:17 -05:00
Use crypto-lib util function for keychain code generation
This commit is contained in:
parent
6ee9853506
commit
d365de4e5b
@ -3,6 +3,7 @@ define(function(require) {
|
||||
|
||||
var angular = require('angular'),
|
||||
appController = require('js/app-controller'),
|
||||
util = require('js/crypto/util'),
|
||||
keychain, pgp;
|
||||
|
||||
var PrivateKeyUploadCtrl = function($scope) {
|
||||
@ -82,26 +83,13 @@ define(function(require) {
|
||||
// go to step 1
|
||||
$scope.step = 1;
|
||||
// generate new code for the user
|
||||
$scope.code = $scope.generateCode();
|
||||
$scope.code = util.randomString(24).toUpperCase();
|
||||
$scope.displayedCode = $scope.code.slice(0, 4) + '-' + $scope.code.slice(4, 8) + '-' + $scope.code.slice(8, 12) + '-' + $scope.code.slice(12, 16) + '-' + $scope.code.slice(16, 20) + '-' + $scope.code.slice(20, 24);
|
||||
|
||||
// clear input fields of any previous artifacts
|
||||
$scope.code0 = $scope.code1 = $scope.code2 = $scope.code3 = $scope.code4 = $scope.code5 = '';
|
||||
};
|
||||
|
||||
$scope.generateCode = function() {
|
||||
function randomString(length, chars) {
|
||||
var result = '';
|
||||
var randomValues = new Uint8Array(length); // get random length number of bytes
|
||||
window.crypto.getRandomValues(randomValues);
|
||||
for (var i = 0; i < length; i++) {
|
||||
result += chars[Math.round(randomValues[i] / 255 * (chars.length - 1))];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return randomString(24, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ');
|
||||
};
|
||||
|
||||
$scope.verifyCode = function() {
|
||||
var inputCode = '' + $scope.code0 + $scope.code1 + $scope.code2 + $scope.code3 + $scope.code4 + $scope.code5;
|
||||
|
||||
|
@ -18,4 +18,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
button.ng-animate {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
}
|
@ -109,15 +109,12 @@ define(function(require) {
|
||||
|
||||
describe('displayUploadUi', function() {
|
||||
it('should work', function() {
|
||||
var generateCodeStub = sinon.stub(scope, 'generateCode');
|
||||
generateCodeStub.returns('asdf');
|
||||
|
||||
// add some artifacts from a previous key input
|
||||
scope.code0 = scope.code1 = scope.code2 = scope.code3 = scope.code4 = scope.code5 = 'asdasd';
|
||||
|
||||
scope.displayUploadUi();
|
||||
expect(scope.step).to.equal(1);
|
||||
expect(scope.code).to.equal('asdf');
|
||||
expect(scope.code.length).to.equal(24);
|
||||
|
||||
// artifacts should be cleared
|
||||
expect(scope.code0).to.be.empty;
|
||||
@ -126,14 +123,6 @@ define(function(require) {
|
||||
expect(scope.code3).to.be.empty;
|
||||
expect(scope.code4).to.be.empty;
|
||||
expect(scope.code5).to.be.empty;
|
||||
|
||||
generateCodeStub.restore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateCode', function() {
|
||||
it('should work', function() {
|
||||
expect(scope.generateCode().length).to.equal(24);
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user