Skip to content

Commit

Permalink
added hash option/route for hash generators
Browse files Browse the repository at this point in the history
  • Loading branch information
Matheus Cesar C. - Matsukii committed Oct 29, 2019
1 parent b530b13 commit bd2b751
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ response:
https://polarpod.herokuapp.com/apis/hash/[sha1|md5|sha256|sha224]?d=[data]
```

### Raw hash - ONLY FOR SHA256 and SHA224 (temporarily)

```http
https://polarpod.herokuapp.com/apis/hash/rar/[sha256|sha224]?d=[data]
```

parameters

* d: data
Expand All @@ -63,6 +69,10 @@ example
https://polarpod.herokuapp.com/apis/hash/sha256?d=test
```

```http
https://polarpod.herokuapp.com/apis/hash/raw/sha256?d=test
```

### Warning(known issue that will not be corrected soon): MD5 and SHA1 - do not expect the same hash from given text to be equal to other hash generators

## SVG QR Code generator
Expand Down
28 changes: 28 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ module.exports = (app, dir) => {
/**
* @description hash function
*
* TODO: MOVE THIS CODE TO A NEW FILE
*
* params: d = data/text to hash
*
* @returns the hash from given data
Expand Down Expand Up @@ -285,6 +287,32 @@ module.exports = (app, dir) => {
res.status(400).send(malformedQuery(dat, alg));
}
}
});

app.get("/apis/hash/raw/:alg", (req, res) => {

let dat = req.query.d;
let alg = req.params.alg;

if(alg == ''){
res.send(404).send(resMsgs.hashNoParams);
}
else if(!dat || !alg){
res.status(400).send(malformedQuery(dat, alg));
}
else {
if(alg == 'sha256'){
let h = sha2xx.sha256(dat);
res.status(200).send(h);
}
else if(alg == 'sha224'){
let h = sha2xx.sha224(dat);
res.status(200).send(h);
}
}


})


}

0 comments on commit bd2b751

Please sign in to comment.