Skip to content

Commit 9d5455e

Browse files
authored
[#15] Add hash256 to Api256 (#16)
1 parent df3dc0e commit 9d5455e

File tree

7 files changed

+34
-5
lines changed

7 files changed

+34
-5
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
sudo: false
22
language: rust
33
rust:
4-
- 1.29.1
4+
- 1.30.0
55

66
# all unlabeled jobs run at test. Only if all "test" jobs finish, will the publish job run
77
stages:

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.4.1
2+
3+
### Added
4+
+ `Api256.hash256(hashable_buffer: Buffer): Buffer;` Note that the returned `Buffer` will always be _exactly_ 32 bytes.
5+
16
## 0.4.0
27

38
### Breaking Changes
@@ -25,7 +30,7 @@ None
2530

2631
### Changed
2732

28-
+ Updated to `rerypt-rs` 0.3.0.
33+
+ Updated to `recrypt-rs` 0.3.0.
2934

3035
## 0.2.0
3136

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class Api256 {
5252
generatePlaintext(): Plaintext;
5353
generateTransformKey(fromPrivateKey: PrivateKey, toPublicKey: PublicKey, privateSigningKey: PrivateSigningKey): TransformKey;
5454
computePublicKey(privateKey: PrivateKey): PublicKey;
55+
hash256(hashable_buffer: Buffer): Buffer;
5556
deriveSymmetricKey(plaintext: Plaintext): Buffer;
5657
encrypt(plaintext: Plaintext, toPublicKey: PublicKey, privateSigningKey: PrivateSigningKey): EncryptedValue;
5758
transform(encryptedValue: EncryptedValue, transformKey: TransformKey, privateSigningKey: PrivateSigningKey): EncryptedValue;

native/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "recrypt-node-binding"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
authors = ["IronCore Labs <code@ironcorelabs.com>"]
55

66
[lib]
@@ -9,7 +9,8 @@ crate-type = ["dylib"]
99

1010
[dependencies]
1111
rand = "0.5.5"
12-
recrypt = "0.3.0"
12+
#recrypt = "0.3.0"
13+
recrypt = { git = "https://github.com/IronCoreLabs/recrypt-rs"}
1314
neon = "0.2.0"
1415

1516
[build-dependencies]

native/src/api256.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ declare_types! {
136136
Ok(util::public_key_to_js_object(&mut cx, &derived_public_key)?.upcast())
137137
}
138138

139+
method hash256(mut cx) {
140+
let hashable_buffer: Handle<JsBuffer> = cx.argument::<JsBuffer>(0)?;
141+
142+
let hashed_bytes = {
143+
let mut this = cx.this();
144+
let guard = cx.lock();
145+
let mut recrypt_api_256 = this.borrow_mut(&guard);
146+
recrypt_api_256.api.hash_256(&util::buffer_to_variable_bytes(&cx, hashable_buffer))
147+
};
148+
149+
Ok(util::bytes_to_buffer(&mut cx, &hashed_bytes)?.upcast())
150+
}
151+
139152
method deriveSymmetricKey(mut cx){
140153
let plaintext_buffer: Handle<JsBuffer> = cx.argument::<JsBuffer>(0)?;
141154

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ironcorelabs/recrypt-node-binding",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "Bindings to allow the recrypt-rs library to work via NodeJS.",
55
"repository": {
66
"type": "git",

test/recrypt-node.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ describe("Recrypt-Node", () => {
122122
});
123123
});
124124

125+
describe("hash256", () => {
126+
test("should return 32 bytes for plaintext", () => {
127+
const pt = api.generatePlaintext();
128+
const symmetricKey = api.hash256(pt);
129+
expect(symmetricKey).toBeInstanceOf(Buffer);
130+
expect(symmetricKey).toHaveLength(32);
131+
});
132+
});
133+
125134
describe("deriveSymmetricKey", () => {
126135
test("should return symmetric key from plaintext", () => {
127136
const pt = api.generatePlaintext();

0 commit comments

Comments
 (0)