signed 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/signed/version.rb +1 -1
- data/lib/signed.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 93e816e1da46b866b267adb26a636e9d2980dad8
|
|
4
|
+
data.tar.gz: 2788bea793e7835cd67e93dd06f95ae7b5de66a3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4ccf4c7f002c3b2e7c6d9c7d24dce53efb460fd1a74ff18de083df2df6b217377276929cc6fe9872feb79bf3174201c1f68acae2b00d52e33af41c3e53b0b96
|
|
7
|
+
data.tar.gz: ba3070b6a307a80f16c6797be17bacff79e36885ce2a39a34829c0fc84fe44b4053e3a9e2e11bea7936436e72fc09187402473dae0496075eb9bf51a44ca2405
|
data/README.md
CHANGED
|
@@ -28,7 +28,7 @@ require 'signed'
|
|
|
28
28
|
|
|
29
29
|
data = 'hello world'
|
|
30
30
|
secret = 'secret string'
|
|
31
|
-
Signed.
|
|
31
|
+
Signed.sign(data, secret)
|
|
32
32
|
|
|
33
33
|
```
|
|
34
34
|
to verify signature
|
|
@@ -38,20 +38,20 @@ require 'signed'
|
|
|
38
38
|
data = 'hello world'
|
|
39
39
|
secret = 'secret string'
|
|
40
40
|
signature = 'a683633f77b24215387902b1685586b456513a06a3990c339143cd4528ce2d26:aW5maW5pdA=='
|
|
41
|
-
Signed.
|
|
41
|
+
Signed.verify?(data, signature, secret)
|
|
42
42
|
```
|
|
43
43
|
you can also add timestamp to set expiration
|
|
44
44
|
|
|
45
45
|
```ruby
|
|
46
|
-
Signed.
|
|
46
|
+
Signed.sign(data, secret, expiry: timestamp)
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
if you want to change hashing algorithm
|
|
50
50
|
|
|
51
51
|
```ruby
|
|
52
|
-
Signed.
|
|
52
|
+
Signed.sign(data, secret, algo: 'MD5')
|
|
53
53
|
# to verify signature
|
|
54
|
-
Signed.
|
|
54
|
+
Signed.verify?(data, signature, secret, algo: 'MD5')
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
## Development
|
data/lib/signed/version.rb
CHANGED
data/lib/signed.rb
CHANGED
|
@@ -19,9 +19,15 @@ module Signed
|
|
|
19
19
|
|
|
20
20
|
def verify_signature(data, signature, secret, algo: 'SHA256')
|
|
21
21
|
sign = signature.split(':')
|
|
22
|
+
return false if sign.count < 2
|
|
22
23
|
hash = sign[0]
|
|
23
24
|
expiry = Base64.decode64(sign[1])
|
|
24
25
|
return false if Utils.check_expiry(expiry)
|
|
25
26
|
Signature.verify_hash(algo, hash, "#{data}:#{expiry}:#{secret}")
|
|
26
27
|
end
|
|
28
|
+
|
|
29
|
+
class << self
|
|
30
|
+
alias_method :verify?, :verify_signature
|
|
31
|
+
alias_method :sign, :create_signature
|
|
32
|
+
end
|
|
27
33
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: signed
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- haseeb
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-08-
|
|
11
|
+
date: 2017-08-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|