Skip to content

Commit

Permalink
bcrypto: do not require bsert in production.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Jan 24, 2020
1 parent 55d8639 commit 9ff273d
Show file tree
Hide file tree
Showing 93 changed files with 121 additions and 93 deletions.
2 changes: 1 addition & 1 deletion lib/bcrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

'use strict';

const assert = require('bsert');
const assert = require('./internal/assert');
const SHA512 = require('./sha512');
const Blowfish = require('./js/ciphers/blowfish');

Expand Down
2 changes: 1 addition & 1 deletion lib/cshake.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

'use strict';

const assert = require('bsert');
const assert = require('./internal/assert');
const Keccak = require('./keccak');
const HMAC = require('./internal/hmac');

Expand Down
2 changes: 1 addition & 1 deletion lib/ctr-drbg.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

'use strict';

const assert = require('bsert');
const assert = require('./internal/assert');
const cipher = require('./cipher');
const {Cipher} = cipher;

Expand Down
2 changes: 1 addition & 1 deletion lib/dsaies.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

const assert = require('bsert');
const assert = require('./internal/assert');
const dsa = require('./dsa');
const random = require('./random');
const box = require('./secretbox');
Expand Down
2 changes: 1 addition & 1 deletion lib/eb2k.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

const assert = require('bsert');
const assert = require('./internal/assert');
const MD5 = require('./md5');

/*
Expand Down
2 changes: 1 addition & 1 deletion lib/ecies.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

const assert = require('bsert');
const assert = require('./internal/assert');
const box = require('./secretbox');
const random = require('./random');

Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/asn1.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');
const bio = require('bufio');
const objects = require('../internal/objects');

Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/base16.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');
const isBrowser = Buffer.alloc(0)._isBuffer === true;

/*
Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/base32.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');

/*
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');

/*
* Base64
Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');

/*
* Lines
Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/pem.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');
const base64 = require('./base64');
const lines = require('./lines');

Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/pemcrypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');
const {PEMBlock} = require('./pem');
const cipher = require('../cipher');
const random = require('../random');
Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/pkcs5.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');

/*
* PKCS5
Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');

/*
* Util
Expand Down
2 changes: 1 addition & 1 deletion lib/encoding/x509.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');
const asn1 = require('./asn1');
const pem = require('./pem');
const {types} = asn1;
Expand Down
2 changes: 1 addition & 1 deletion lib/gost94.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

'use strict';

const assert = require('bsert');
const assert = require('./internal/assert');
const HMAC = require('./internal/hmac');

/*
Expand Down
2 changes: 1 addition & 1 deletion lib/hash-drbg.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'use strict';

const assert = require('bsert');
const assert = require('./internal/assert');

/*
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/hkdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

const assert = require('bsert');
const assert = require('./internal/assert');

/**
* HKDF
Expand Down
2 changes: 1 addition & 1 deletion lib/hmac-drbg.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

const assert = require('bsert');
const assert = require('./internal/assert');

/*
* Constants
Expand Down
28 changes: 28 additions & 0 deletions lib/internal/assert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*!
* assert.js - assert for bcrypto
* Copyright (c) 2020, Christopher Jeffrey (MIT License).
* https://github.com/bcoin-org/bcrypto
*/

'use strict';

/*
* Assert
*/

function assert(val, msg) {
if (!val) {
const err = new Error(msg || 'Assertion failed');

if (Error.captureStackTrace)
Error.captureStackTrace(err, assert);

throw err;
}
}

/*
* Expose
*/

module.exports = assert;
2 changes: 1 addition & 1 deletion lib/internal/ciphers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');

/*
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/hmac.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');

/**
* HMAC
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/primes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');
const BN = require('../bn');
const random = require('../random');

Expand Down
2 changes: 1 addition & 1 deletion lib/js/aead.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');
const ChaCha20 = require('./chacha20');
const Poly1305 = require('./poly1305');

Expand Down
2 changes: 1 addition & 1 deletion lib/js/base58.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');

/*
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/js/bech32.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');

/**
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/js/blake2b.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');
const HMAC = require('../internal/hmac');

/*
Expand Down
2 changes: 1 addition & 1 deletion lib/js/blake2s.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');
const HMAC = require('../internal/hmac');

/*
Expand Down
2 changes: 1 addition & 1 deletion lib/js/cash32.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');

/**
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/js/chacha20.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');

/*
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/js/cipher.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../internal/assert');
const ciphers = require('../internal/ciphers');
const modes = require('./ciphers/modes');
const AES = require('./ciphers/aes');
Expand Down
2 changes: 1 addition & 1 deletion lib/js/ciphers/aes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../../internal/assert');

/*
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/js/ciphers/blowfish.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../../internal/assert');

/*
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/js/ciphers/camellia.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../../internal/assert');

/*
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/js/ciphers/cast5.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../../internal/assert');

/*
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/js/ciphers/des.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../../internal/assert');

/*
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/js/ciphers/gcm.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../../internal/assert');

/*
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/js/ciphers/idea.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../../internal/assert');

/*
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/js/ciphers/modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../../internal/assert');
const gcm = require('./gcm');

/*
Expand Down
2 changes: 1 addition & 1 deletion lib/js/ciphers/rc2.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../../internal/assert');

/*
* Constants
Expand Down
2 changes: 1 addition & 1 deletion lib/js/ciphers/twofish.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

const assert = require('bsert');
const assert = require('../../internal/assert');

/*
* Constants
Expand Down
Loading

0 comments on commit 9ff273d

Please sign in to comment.