fix: catch error when unmarshaling instead of crashing (#113)

* test: Add failing tests

* fix: Fix some failing tests

* fix: various fixes on garbage error handling and respective tests

* tests: increased timeout for test timing out in CI

* tests: increasing test timeout to please the CI gods

* tests: increasing test timeout to please the CI gods

* fix: for when unMarshallPrivateKey is called with null or undefined key
This commit is contained in:
Maciej Krüger
2017-12-01 09:36:29 +01:00
committed by David Dias
parent bf9b532067
commit 7608fdd858
8 changed files with 150 additions and 51 deletions

View File

@ -81,7 +81,13 @@ exports.marshalPublicKey = (key, type) => {
// Converts a protobuf serialized private key into its
// representative object
exports.unmarshalPrivateKey = (buf, callback) => {
const decoded = keysPBM.PrivateKey.decode(buf)
let decoded
try {
decoded = keysPBM.PrivateKey.decode(buf)
} catch (err) {
return callback(err)
}
const data = decoded.Data
switch (decoded.Type) {