Socket
Socket
Sign inDemoInstall

basic-crypto

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.0.2

.codeclimate.yml

14

index.js

@@ -68,7 +68,6 @@ 'use strict'

error = e
}finally{
if(!callback && error) throw error
if(!callback && !error) return encrypted
callback(error, encrypted)
}
if(!callback && error) throw error
if(!callback && !error) return encrypted
return callback(error, encrypted)
}

@@ -106,7 +105,6 @@

error = e
}finally{
if(!callback && error) throw error
if(!callback && !error) return plainText
callback(error, plainText)
}
if(!callback && error) throw error
if(!callback && !error) return plainText
return callback(error, plainText)
}

@@ -113,0 +111,0 @@

{
"name": "basic-crypto",
"version": "1.0.1",
"version": "1.0.2",
"description": "basic crypto wrapper, with sensible defaults",
"main": "index.js",
"scripts": {
"test": "node ./test.js"
"test": "nyc -s node ./test && nyc report > lcov.info"
},

@@ -19,4 +19,4 @@ "repository": "leonardodino/basic-crypto",

],
"engines" : {
"node" : ">=4.0.0"
"engines": {
"node": ">=4.0.0"
},

@@ -26,4 +26,6 @@ "author": "Leonardo Dino",

"devDependencies": {
"eslint": "^3.18.0",
"nyc": "^10.1.2",
"tape": "^4.5.1"
}
}
# basic-crypto
[![Build](https://travis-ci.org/leonardodino/basic-crypto.svg?branch=master)](http://travis-ci.org/leonardodino/basic-crypto)
[![npm version][npm-badge]][npm-url]
[![Build Status][travis-badge]][travis-url]
[![Coverage Status][coverage-badge]][coverage-url]
[![Code Climate][codeclimate-badge]][codeclimate-url]

@@ -147,1 +150,10 @@ Basic, high-level, opnionated crypto suite. <sup name="anchor0">[0](#footnote0)</sup>

<sup name="footnote6">`6`</sup> A fixed key is useful when talking to other processes, or storing the key for later. When not provided a key will be generated randomly on the fly, but it's not possible to access this value, and it's unique in each instantiation. [↩](#anchor6)
[npm-badge]: https://img.shields.io/npm/v/basic-crypto.svg
[npm-url]: https://www.npmjs.com/package/basic-crypto
[travis-badge]: https://api.travis-ci.org/leonardodino/basic-crypto.svg
[travis-url]: https://travis-ci.org/leonardodino/basic-crypto
[codeclimate-badge]: https://codeclimate.com/github/leonardodino/basic-crypto/badges/gpa.svg
[codeclimate-url]: https://codeclimate.com/github/leonardodino/basic-crypto
[coverage-badge]: https://codeclimate.com/github/leonardodino/basic-crypto/badges/coverage.svg
[coverage-url]: https://codeclimate.com/github/leonardodino/basic-crypto/coverage

@@ -14,3 +14,3 @@ 'use strict'

}
throw error('LABEL: wrong number of arguments')
throw new Error('LABEL: wrong number of arguments')
}

@@ -121,3 +121,2 @@

if(!basicCryptoOptions || !basicCryptoOptions.integrity){return}
var plainText = 'abcd😜§±4563'

@@ -128,3 +127,3 @@ var testName = label(mode, 'reject invalid hmac size', hmacSize, _testName)

t.throws(function(){
var basicCrypto = new BasicCrypto(instanceOptions)
new BasicCrypto(instanceOptions)
})

@@ -143,4 +142,4 @@ t.end()

t.throws(function(){
var basicCrypto = new BasicCrypto(option)
})
new BasicCrypto(option)
}, /options must be an object or string/ )
t.end()

@@ -210,1 +209,85 @@ })

})
test('test encryption error handling', function(t){
var basicCrypto = new BasicCrypto({integrity: true})
var plainText = 'random string'
var parts = basicCrypto.encrypt(plainText).split('$')
var missingHmac = [parts[0], parts[1]].join('$')
var tampered = [
parts[0].split('').reverse().join(''),
parts[1],
parts[2],
].join('$')
var invalidhex = parts[0]
t.throws(function(){
basicCrypto.decrypt(missingHmac)
}, /Missing HMAC/i, 'Missing HMAC')
t.throws(function(){
basicCrypto.decrypt(tampered)
}, /tampered/i, 'Tampered Content')
t.throws(function(){
basicCrypto.decrypt(invalidhex)
}, /Invalid hex/i, 'Invalid hex string')
t.end()
})
test('encryption - reject invalid input', function(t){
var basicCrypto = new BasicCrypto()
t.throws(function(){
basicCrypto.encrypt()
}, /TypeError/, 'Missing plaintext')
t.throws(function(){
basicCrypto.encrypt(new Error('plaintext'))
}, /TypeError/, 'Invalid plaintext')
t.end()
})
test('decryption - reject invalid input', function(t){
var basicCrypto = new BasicCrypto({integrity: true})
var parts = basicCrypto.encrypt('plaintext').split('$')
t.throws(function(){
var missingHmac = [parts[0], parts[1]].join('$')
basicCrypto.decrypt(missingHmac)
}, /Missing HMAC/i, 'Missing HMAC')
t.throws(function(){
var tampered = [
parts[0].split('').reverse().join(''),
parts[1],
parts[2],
].join('$')
basicCrypto.decrypt(tampered)
}, /tampered/i, 'Tampered Content')
t.throws(function(){
var hmacLengthMismatch = [
parts[0],
parts[1],
parts[2].substring(1),
].join('$')
basicCrypto.decrypt(hmacLengthMismatch)
}, /tampered/i, 'hmac length mismatch')
t.throws(function(){
var invalidhex = parts[0]
basicCrypto.decrypt(invalidhex)
}, /Invalid hex/i, 'Invalid hex string')
t.throws(function(){
basicCrypto.decrypt()
}, /TypeError/i, 'Missing cyphertext')
t.throws(function(){
basicCrypto.decrypt(new Error('cyphertext'))
}, /TypeError/i, 'Invalid cyphertext')
t.end()
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc