Skip to content

Commit

Permalink
Use better generator for entry id
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-username committed Mar 27, 2018
1 parent 87d1045 commit 8f29a45
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/screens/Entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
modifyEntry,
getEntryDetails,
} from '../redux/modules/listings';
import generateId from '../utils/idGenerator';
import { generateRandomBytes } from '../utils/crypto';

const modes = {
add: 'ENTRY_ADD',
Expand Down Expand Up @@ -90,7 +90,7 @@ const mapStateToDispatch = (
) => ({
handleSubmit(id, name, code) {
if (action === ADD_ENTRY) {
dispatch(addEntry(generateId(), name, code));
dispatch(addEntry(generateRandomBytes(), name, code));
} else {
dispatch(modifyEntry(id, code));
}
Expand Down
5 changes: 5 additions & 0 deletions src/utils/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ export const hashString = string => {
.digest()
.toHex();
};

export const generateRandomBytes = (length = 6) => {
const bytes = forge.random.getBytesSync(8);
return forge.util.bytesToHex(bytes).substring(0, length);
};
6 changes: 0 additions & 6 deletions src/utils/idGenerator.js

This file was deleted.

0 comments on commit 8f29a45

Please sign in to comment.