asherah 1.0.44 → 1.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,12 +4,13 @@ This is a wrapper of the Asherah Go implementation using the Cobhan FFI library
4
4
 
5
5
  Example code:
6
6
 
7
+ ### TypeScript
7
8
 
8
9
  ```typescript
9
10
  import { AsherahConfig, decrypt, encrypt, setup, shutdown } from 'asherah'
10
11
 
11
12
  const config: AsherahConfig = {
12
- KMS: 'static',
13
+ KMS: 'aws',
13
14
  Metastore: 'memory',
14
15
  ServiceName: 'TestService',
15
16
  ProductID: 'TestProduct',
@@ -24,7 +25,7 @@ const config: AsherahConfig = {
24
25
  DynamoDBTableName: null,
25
26
  SessionCacheMaxSize: null,
26
27
  SessionCacheDuration: null,
27
- RegionMap: null,
28
+ RegionMap: {"us-west-2": "arn:aws:kms:us-west-2:XXXXXXXXX:key/XXXXXXXXXX"},
28
29
  PreferredRegion: null,
29
30
  EnableRegionSuffix: null
30
31
  };
@@ -33,6 +34,8 @@ setup(config)
33
34
 
34
35
  const input = 'mysecretdata'
35
36
 
37
+ console.log("Input: " + input)
38
+
36
39
  const data = Buffer.from(input, 'utf8');
37
40
 
38
41
  const encrypted = encrypt('partition', data);
@@ -41,5 +44,53 @@ const decrypted = decrypt('partition', encrypted);
41
44
 
42
45
  const output = decrypted.toString('utf8');
43
46
 
47
+ console.log("Output: " + output)
48
+
44
49
  shutdown()
45
50
  ```
51
+
52
+ ### JavaScript
53
+
54
+ ```javascript
55
+
56
+ const asherah = require('asherah')
57
+
58
+ const config = {
59
+ KMS: 'aws',
60
+ Metastore: 'memory',
61
+ ServiceName: 'TestService',
62
+ ProductID: 'TestProduct',
63
+ Verbose: true,
64
+ EnableSessionCaching: true,
65
+ ExpireAfter: null,
66
+ CheckInterval: null,
67
+ ConnectionString: null,
68
+ ReplicaReadConsistency: null,
69
+ DynamoDBEndpoint: null,
70
+ DynamoDBRegion: null,
71
+ DynamoDBTableName: null,
72
+ SessionCacheMaxSize: null,
73
+ SessionCacheDuration: null,
74
+ RegionMap: {"us-west-2": "arn:aws:kms:us-west-2:XXXXXXXXX:key/XXXXXXXXXX"},
75
+ PreferredRegion: null,
76
+ EnableRegionSuffix: null
77
+ };
78
+
79
+ asherah.setup(config)
80
+
81
+ const input = 'mysecretdata'
82
+
83
+ console.log("Input: " + input)
84
+
85
+ const data = Buffer.from(input, 'utf8');
86
+
87
+ const encrypted = asherah.encrypt('partition', data);
88
+
89
+ const decrypted = asherah.decrypt('partition', encrypted);
90
+
91
+ const output = decrypted.toString('utf8');
92
+
93
+ console.log("Output: " + output)
94
+
95
+ asherah.shutdown()
96
+ ```
package/dist/asherah.js CHANGED
@@ -11,9 +11,16 @@ const libasherah = (0, cobhan_1.load_platform_library)(binaries_path, 'libashera
11
11
  'SetupJson': ['int32', ['pointer']],
12
12
  'EncryptToJson': ['int32', ['pointer', 'pointer', 'pointer']],
13
13
  'DecryptFromJson': ['int32', ['pointer', 'pointer', 'pointer']],
14
- 'EstimateBuffer': ['int32', ['int32', 'int32']],
15
14
  'Shutdown': ['void', []]
16
15
  });
16
+ const EstimatedEncryptionOverhead = 48;
17
+ const EstimatedEnvelopeOverhead = 185;
18
+ const Base64Overhead = 1.34;
19
+ let EstimatedIntermediateKeyOverhead = 0;
20
+ function estimate_buffer(dataLen, partitionLen) {
21
+ const estimatedDataLen = (dataLen + EstimatedEncryptionOverhead) * Base64Overhead;
22
+ return cobhan_1.header_size + EstimatedEnvelopeOverhead + EstimatedIntermediateKeyOverhead + partitionLen + estimatedDataLen;
23
+ }
17
24
  function find_binaries() {
18
25
  if (fs_1.default.existsSync('node_modules/asherah/binaries')) {
19
26
  return 'node_modules/asherah/binaries';
@@ -25,6 +32,7 @@ function find_binaries() {
25
32
  }
26
33
  function setup(config) {
27
34
  const configJsonBuffer = (0, cobhan_1.json_to_cbuffer)(config);
35
+ EstimatedIntermediateKeyOverhead = config.ProductID.length + config.ServiceName.length;
28
36
  const result = libasherah.SetupJson(configJsonBuffer);
29
37
  if (result < 0) {
30
38
  throw new Error('setupJson failed: ' + result);
@@ -49,7 +57,7 @@ exports.decrypt = decrypt;
49
57
  function encrypt(partitionId, data) {
50
58
  const partitionIdBuffer = (0, cobhan_1.string_to_cbuffer)(partitionId);
51
59
  const dataBuffer = (0, cobhan_1.buffer_to_cbuffer)(data);
52
- const outputJsonBuffer = (0, cobhan_1.allocate_cbuffer)(libasherah.EstimateBuffer(data.byteLength, partitionId.length));
60
+ const outputJsonBuffer = (0, cobhan_1.allocate_cbuffer)(estimate_buffer(data.byteLength, partitionId.length));
53
61
  const result = libasherah.EncryptToJson(partitionIdBuffer, dataBuffer, outputJsonBuffer);
54
62
  if (result < 0) {
55
63
  throw new Error('encrypt failed: ' + result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asherah",
3
- "version": "1.0.44",
3
+ "version": "1.0.45",
4
4
  "description": "Asherah envelope encryption and key rotation library",
5
5
  "main": "dist/asherah.js",
6
6
  "repository": {
@@ -48,6 +48,6 @@
48
48
  },
49
49
  "types": "dist/asherah.d.ts",
50
50
  "dependencies": {
51
- "cobhan": "^1.0.27"
51
+ "cobhan": "^1.0.31"
52
52
  }
53
53
  }