cloak-rb 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +15 -3
- data/lib/cloak/redis.rb +12 -2
- data/lib/cloak/utils.rb +8 -8
- data/lib/cloak/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d80e7f19050d768a2f33ca148e7a7b177dc0bb3d09051005000a0b34f5286c4
|
4
|
+
data.tar.gz: b724ed183653e3d07d38d6139123ac2681a418c6734aff608b386ade5a5d0a63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 291b97787047627d1ade5f3e4a5be46bf1f13132cc0cff6d3f154f17c9707b451d8117199826a5a2b77edc2190b77d6ca7d63ada6327c93cdfe734c574a35951
|
7
|
+
data.tar.gz: 45873eed6dc32ac04b5ce11e3a599d3ad72576f826b7a7fead42c98c53222f7842e0fd1636cce1154f7e2d43e7d4e7eb560a5d456074d9e5866f91af444b01c3
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -13,7 +13,7 @@ See [technical details](#technical-details) for more info.
|
|
13
13
|
Add this line to your application’s Gemfile:
|
14
14
|
|
15
15
|
```ruby
|
16
|
-
gem
|
16
|
+
gem "cloak-rb"
|
17
17
|
```
|
18
18
|
|
19
19
|
## Getting Started
|
@@ -51,7 +51,14 @@ Create a client
|
|
51
51
|
redis = Cloak::Redis.new(key: key)
|
52
52
|
```
|
53
53
|
|
54
|
-
And use it in place of a `Redis` instance.
|
54
|
+
And use it in place of a `Redis` instance.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
redis.set("hello", "world")
|
58
|
+
redis.get("hello")
|
59
|
+
```
|
60
|
+
|
61
|
+
A few methods aren’t supported:
|
55
62
|
|
56
63
|
- `lrem` since encrypted list elements aren’t comparable
|
57
64
|
- `setrange`, `setbit`, `append`, and `bitop` since encrypted strings can’t be modified in-place
|
@@ -68,7 +75,12 @@ Create a client
|
|
68
75
|
dalli = Cloak::Dalli.new(key: key)
|
69
76
|
```
|
70
77
|
|
71
|
-
And use it in place a `Dalli::Client` instance.
|
78
|
+
And use it in place of a `Dalli::Client` instance.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
dalli.set("hello", "world")
|
82
|
+
dalli.get("hello")
|
83
|
+
```
|
72
84
|
|
73
85
|
## Technical Details
|
74
86
|
|
data/lib/cloak/redis.rb
CHANGED
@@ -10,13 +10,23 @@ module Cloak
|
|
10
10
|
def_delegators :@redis, :auth, :select, :quit, :bgrewriteaof, :bgsave,
|
11
11
|
:config, :client, :dbsize, :flushall, :flushdb, :info, :lastsave,
|
12
12
|
:monitor, :save, :shutdown, :slaveof, :slowlog, :sync, :time,
|
13
|
-
:unwatch, :
|
13
|
+
:unwatch, :exec, :discard
|
14
14
|
|
15
15
|
def initialize(key: nil, **options)
|
16
16
|
@redis = ::Redis.new(**options)
|
17
17
|
create_encryptor(key)
|
18
18
|
end
|
19
19
|
|
20
|
+
def pipelined(&block)
|
21
|
+
raise Error, "pipelined with block parameter not supported yet" if block&.arity != 0
|
22
|
+
@redis.pipelined(&block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def multi(&block)
|
26
|
+
raise Error, "multi with block parameter not supported yet" if block&.arity != 0
|
27
|
+
@redis.multi(&block)
|
28
|
+
end
|
29
|
+
|
20
30
|
def debug(*args)
|
21
31
|
args[1] = encrypt_key(args[1]) if args[0] == "object"
|
22
32
|
@redis.debug(*args)
|
@@ -739,7 +749,7 @@ module Cloak
|
|
739
749
|
|
740
750
|
keys = args.flatten.map { |k| encrypt_key(k) }
|
741
751
|
|
742
|
-
on_result(@redis._bpop
|
752
|
+
on_result(@redis.send(:_bpop, cmd, [keys, {timeout: timeout}], &blk)) do |res|
|
743
753
|
if res.nil?
|
744
754
|
res
|
745
755
|
elsif zset
|
data/lib/cloak/utils.rb
CHANGED
@@ -44,14 +44,6 @@ module Cloak
|
|
44
44
|
@encryptor.open(to_binary(key), nonce: KEY_NONCE)
|
45
45
|
end
|
46
46
|
|
47
|
-
def encrypt_field(key, field)
|
48
|
-
@encryptor.seal(to_binary(field), nonce: key.slice(0, 16))
|
49
|
-
end
|
50
|
-
|
51
|
-
def decrypt_field(key, field)
|
52
|
-
@encryptor.open(to_binary(field), nonce: key.slice(0, 16))
|
53
|
-
end
|
54
|
-
|
55
47
|
def encrypt_member(value)
|
56
48
|
@encryptor.seal(to_binary(value), nonce: MEMBER_NONCE)
|
57
49
|
end
|
@@ -68,6 +60,14 @@ module Cloak
|
|
68
60
|
@encryptor.open(to_binary(value), nonce: HLL_ELEMENT_NONCE)
|
69
61
|
end
|
70
62
|
|
63
|
+
def encrypt_field(key, field)
|
64
|
+
@encryptor.seal(to_binary(field), nonce: key.slice(0, 16))
|
65
|
+
end
|
66
|
+
|
67
|
+
def decrypt_field(key, field)
|
68
|
+
@encryptor.open(to_binary(field), nonce: key.slice(0, 16))
|
69
|
+
end
|
70
|
+
|
71
71
|
def to_binary(value)
|
72
72
|
value = value.to_s
|
73
73
|
value = value.dup.force_encoding(Encoding::BINARY) unless value.encoding == Encoding::BINARY
|
data/lib/cloak/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloak-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: miscreant
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description:
|
28
|
-
email: andrew@
|
28
|
+
email: andrew@ankane.org
|
29
29
|
executables: []
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
|
-
rubygems_version: 3.
|
60
|
+
rubygems_version: 3.3.7
|
61
61
|
signing_key:
|
62
62
|
specification_version: 4
|
63
63
|
summary: Application-level encryption for Redis and Memcached
|