Skip to content

Commit

Permalink
Improve handling of optional context for Secure Cell Token Protect an…
Browse files Browse the repository at this point in the history
…d Seal (#906)

* update README and example to use 0.14.3 version from npm registry

* add typescript types

* optional context, declarations file
  • Loading branch information
radetsky committed Mar 15, 2022
1 parent a177258 commit 7147271
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
4 changes: 2 additions & 2 deletions docs/examples/react-native/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ const App: () => Node = () => {
// Symmetric key => promise => encryption => promise => decryption
symmetricKey64()
.then((key64) => {
secureCellSealWithSymmetricKeyEncrypt64(key64, plaintext, context)
secureCellSealWithSymmetricKeyEncrypt64(key64, plaintext)
.then((encrypted64) => {
secureCellSealWithSymmetricKeyDecrypt64(key64, encrypted64, context)
secureCellSealWithSymmetricKeyDecrypt64(key64, encrypted64)
.then((decrypted) => {
console.log("Decrypted with the key:", decrypted)
})
Expand Down
5 changes: 3 additions & 2 deletions src/wrappers/themis/react-native-themis/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "react-native-themis",
"version": "0.14.3",
"version": "0.14.4",
"description": "Themis React Native is a convenient cryptographic library for data protection",
"react-native": "src/index",
"source": "src/index",
"types": "src/index.d.ts",
"files": [
"src",
"lib",
Expand Down Expand Up @@ -154,4 +155,4 @@
]
]
}
}
}

This file was deleted.

19 changes: 19 additions & 0 deletions src/wrappers/themis/react-native-themis/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export declare const COMPARATOR_NOT_READY: any, COMPARATOR_NOT_MATCH: any, COMPARATOR_MATCH: any, COMPARATOR_ERROR: any, KEYTYPE_RSA: any, KEYTYPE_EC: any;
export declare function keyPair64(typeOfKey: any): Promise<Object>;
export declare function symmetricKey64(): Promise<string>;
export declare function secureCellSealWithSymmetricKeyEncrypt64(symmetricKey64: String, plaintext: String, context?: String): Promise<string>;
export declare function secureCellSealWithSymmetricKeyDecrypt64(symmetricKey64: String, encrypted64: String, context?: String): Promise<string>;
export declare function secureCellSealWithPassphraseEncrypt64(passphrase: String, plaintext: String, context?: String): Promise<string>;
export declare function secureCellSealWithPassphraseDecrypt64(passphrase: String, encrypted64: String, context?: String): Promise<string>;
export declare function secureCellTokenProtectEncrypt64(symmetricKey64: String, plaintext: String, context?: String): Promise<Object>;
export declare function secureCellTokenProtectDecrypt64(symmetricKey64: String, encrypted64: String, token64: String, context?: String): Promise<string>;
export declare function secureCellContextImprintEncrypt64(symmetricKey64: String, plaintext: String, context: String): Promise<string>;
export declare function secureCellContextImprintDecrypt64(symmetricKey64: String, encrypted64: String, context: String): Promise<string>;
export declare function secureMessageSign64(plaintext: String, privateKey64: String, publicKey64: String): Promise<string>;
export declare function secureMessageVerify64(signed64: String, privateKey64: String, publicKey64: String): Promise<string>;
export declare function secureMessageEncrypt64(plaintext: String, privateKey64: String, publicKey64: String): Promise<string>;
export declare function secureMessageDecrypt64(encrypted64: String, privateKey64: String, publicKey64: String): Promise<string>;
export declare function string64(input: String): String;
export declare function comparatorInit64(data64: String): Promise<string>;
export declare function comparatorBegin(uuidStr: String): Promise<string>;
export declare function comparatorProceed64(uuidStr: String, data64: String): Promise<Object>;
12 changes: 6 additions & 6 deletions src/wrappers/themis/react-native-themis/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function symmetricKey64() {
});
}
;
export function secureCellSealWithSymmetricKeyEncrypt64(symmetricKey64, plaintext, context) {
export function secureCellSealWithSymmetricKeyEncrypt64(symmetricKey64, plaintext, context = "") {
const symmetricKey = Array.from(Buffer.from(symmetricKey64, 'base64'));
return new Promise((resolve, reject) => {
Themis.secureCellSealWithSymmetricKeyEncrypt(symmetricKey, plaintext, context, (encrypted) => {
Expand All @@ -44,7 +44,7 @@ export function secureCellSealWithSymmetricKeyEncrypt64(symmetricKey64, plaintex
});
}
;
export function secureCellSealWithSymmetricKeyDecrypt64(symmetricKey64, encrypted64, context) {
export function secureCellSealWithSymmetricKeyDecrypt64(symmetricKey64, encrypted64, context = "") {
const symmetricKey = Array.from(Buffer.from(symmetricKey64, 'base64'));
const encrypted = Array.from(Buffer.from(encrypted64, 'base64'));
return new Promise((resolve, reject) => {
Expand All @@ -56,15 +56,15 @@ export function secureCellSealWithSymmetricKeyDecrypt64(symmetricKey64, encrypte
});
}
;
export function secureCellSealWithPassphraseEncrypt64(passphrase, plaintext, context) {
export function secureCellSealWithPassphraseEncrypt64(passphrase, plaintext, context = "") {
return new Promise((resolve) => {
Themis.secureCellSealWithPassphraseEncrypt(passphrase, plaintext, context, (encrypted) => {
resolve(Buffer.from(new Uint8Array(encrypted)).toString("base64"));
});
});
}
;
export function secureCellSealWithPassphraseDecrypt64(passphrase, encrypted64, context) {
export function secureCellSealWithPassphraseDecrypt64(passphrase, encrypted64, context = "") {
const encrypted = Array.from(Buffer.from(encrypted64, 'base64'));
return new Promise((resolve, reject) => {
Themis.secureCellSealWithPassphraseDecrypt(passphrase, encrypted, context, (decrypted) => {
Expand All @@ -74,7 +74,7 @@ export function secureCellSealWithPassphraseDecrypt64(passphrase, encrypted64, c
});
});
}
export function secureCellTokenProtectEncrypt64(symmetricKey64, plaintext, context) {
export function secureCellTokenProtectEncrypt64(symmetricKey64, plaintext, context = "") {
const symmetricKey = Array.from(Buffer.from(symmetricKey64, 'base64'));
return new Promise((resolve, reject) => {
Themis.secureCellTokenProtectEncrypt(symmetricKey, plaintext, context, (encrypted) => {
Expand All @@ -89,7 +89,7 @@ export function secureCellTokenProtectEncrypt64(symmetricKey64, plaintext, conte
});
});
}
export function secureCellTokenProtectDecrypt64(symmetricKey64, encrypted64, token64, context) {
export function secureCellTokenProtectDecrypt64(symmetricKey64, encrypted64, token64, context = "") {
const symmetricKey = Array.from(Buffer.from(symmetricKey64, 'base64'));
const encrypted = Array.from(Buffer.from(encrypted64, 'base64'));
const token = Array.from(Buffer.from(token64, 'base64'));
Expand Down
12 changes: 6 additions & 6 deletions src/wrappers/themis/react-native-themis/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function symmetricKey64(): Promise<string> {
export function secureCellSealWithSymmetricKeyEncrypt64(
symmetricKey64: String,
plaintext: String,
context: String): Promise<string> {
context: String = ""): Promise<string> {

const symmetricKey = Array.from(Buffer.from(symmetricKey64, 'base64'));

Expand All @@ -68,7 +68,7 @@ export function secureCellSealWithSymmetricKeyEncrypt64(
export function secureCellSealWithSymmetricKeyDecrypt64(
symmetricKey64: String,
encrypted64: String,
context: String): Promise<string> {
context: String = ""): Promise<string> {

const symmetricKey = Array.from(Buffer.from(symmetricKey64, 'base64'));
const encrypted = Array.from(Buffer.from(encrypted64, 'base64'));
Expand All @@ -85,7 +85,7 @@ export function secureCellSealWithSymmetricKeyDecrypt64(
export function secureCellSealWithPassphraseEncrypt64(
passphrase: String,
plaintext: String,
context: String): Promise<string> {
context: String = ""): Promise<string> {

return new Promise((resolve) => {
Themis.secureCellSealWithPassphraseEncrypt(passphrase, plaintext, context, (encrypted: any) => {
Expand All @@ -97,7 +97,7 @@ export function secureCellSealWithPassphraseEncrypt64(
export function secureCellSealWithPassphraseDecrypt64(
passphrase: String,
encrypted64: String,
context: String): Promise<string> {
context: String = ""): Promise<string> {

const encrypted = Array.from(Buffer.from(encrypted64, 'base64'));

Expand All @@ -113,7 +113,7 @@ export function secureCellSealWithPassphraseDecrypt64(
export function secureCellTokenProtectEncrypt64(
symmetricKey64: String,
plaintext: String,
context: String): Promise<Object> {
context: String = ""): Promise<Object> {

const symmetricKey = Array.from(Buffer.from(symmetricKey64, 'base64'));

Expand All @@ -135,7 +135,7 @@ export function secureCellTokenProtectDecrypt64(
symmetricKey64: String,
encrypted64: String,
token64: String,
context: String): Promise<string> {
context: String = ""): Promise<string> {

const symmetricKey = Array.from(Buffer.from(symmetricKey64, 'base64'));
const encrypted = Array.from(Buffer.from(encrypted64, 'base64'));
Expand Down

0 comments on commit 7147271

Please sign in to comment.