urlcrypt 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +6 -3
- data/Rakefile +1 -1
- data/lib/URLcrypt.rb +1 -1
- data/test/URLcrypt_test.rb +10 -38
- data/test/regression_test.rb +36 -0
- data/test/test_helper.rb +33 -0
- metadata +23 -42
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 43b85d8e2005d9c5fb0b2181f9865acb54c85123b9e4aeac7c7c66360aedbdfd
|
4
|
+
data.tar.gz: '008bc1517bf2fd48531d97bdfa4738520b59c855f145716238bd92edc5ba52bc'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c663737786ae94458f6a28442936fd6bdcdde71bbb198d13c1693d151a028d03d647ff080ccdb2b243fa49310b6cc97b95ea305abc28fd22d46d918f10e00e0
|
7
|
+
data.tar.gz: 92567f8985d16055720cea95be351e0a675c764734ae9aba366cb85f360d763d623e44136385c09edece332765eb417f5f79be943a2046abcf466323baf6b110
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ that doesn't have other authentication or persistence mechanisms (like cookies):
|
|
20
20
|
* Links that come with an expiration date (à la S3)
|
21
21
|
* Mini-apps that don't persist data on the server
|
22
22
|
|
23
|
-
Works with Ruby
|
23
|
+
Works with Ruby 2.1+
|
24
24
|
|
25
25
|
**Important**: As a general guideline, URL lengths shouldn't exceed about 2000
|
26
26
|
characters in length, as URLs longer than that will not work in some browsers
|
@@ -29,14 +29,17 @@ with URLcrypt.
|
|
29
29
|
|
30
30
|
**WORD OF WARNING: THERE IS NO GUARANTEE WHATSOEVER THAT THIS GEM IS ACTUALLY SECURE AND WORKS. USE AT YOUR OWN RISK.**
|
31
31
|
|
32
|
-
URLcrypt is an extraction from [
|
32
|
+
URLcrypt is an extraction from [Noko Time Tracking](https://nokotime.com),
|
33
33
|
where it is used to generate URLs for dynamically generated images in emails.
|
34
34
|
|
35
35
|
Patches are welcome; please include tests!
|
36
36
|
|
37
37
|
## Installation
|
38
38
|
|
39
|
-
Add
|
39
|
+
Add to your Gemfile:
|
40
|
+
```ruby
|
41
|
+
gem 'urlcrypt', '~> 0.1.1', require: 'URLcrypt'
|
42
|
+
```
|
40
43
|
|
41
44
|
## Example
|
42
45
|
|
data/Rakefile
CHANGED
@@ -38,7 +38,7 @@ gemspec = Gem::Specification.new do |s|
|
|
38
38
|
s.require_paths << 'lib'
|
39
39
|
s.requirements << 'none'
|
40
40
|
s.summary = "Securely encode and decode short pieces of arbitrary binary data in URLs."
|
41
|
-
s.version = "0.1.
|
41
|
+
s.version = "0.1.2"
|
42
42
|
end
|
43
43
|
|
44
44
|
Gem::PackageTask.new(gemspec) do |pkg|
|
data/lib/URLcrypt.rb
CHANGED
data/test/URLcrypt_test.rb
CHANGED
@@ -1,37 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require '
|
3
|
-
Bundler.require(:default, :test)
|
4
|
-
|
5
|
-
require 'coveralls'
|
6
|
-
Coveralls.wear!
|
7
|
-
|
8
|
-
require 'test/unit'
|
9
|
-
|
10
|
-
class TestURLcrypt < Test::Unit::TestCase
|
11
|
-
|
12
|
-
require 'URLcrypt'
|
13
|
-
|
14
|
-
def assert_bytes_equal(string1, string2)
|
15
|
-
bytes1 = string1.bytes.to_a.join(':')
|
16
|
-
bytes2 = string2.bytes.to_a.join(':')
|
17
|
-
assert_equal(bytes1, bytes2)
|
18
|
-
end
|
19
|
-
|
20
|
-
def assert_decoding(encoded, plain)
|
21
|
-
decoded = URLcrypt.decode(encoded)
|
22
|
-
assert_bytes_equal(plain, decoded)
|
23
|
-
end
|
24
|
-
|
25
|
-
def assert_encoding(encoded, plain)
|
26
|
-
actual = URLcrypt.encode(plain)
|
27
|
-
assert_bytes_equal(encoded, actual)
|
28
|
-
end
|
29
|
-
|
30
|
-
def assert_encode_and_decode(encoded, plain)
|
31
|
-
assert_encoding(encoded, plain)
|
32
|
-
assert_decoding(encoded, plain)
|
33
|
-
end
|
2
|
+
require 'test_helper'
|
34
3
|
|
4
|
+
class TestURLcrypt < TestClass
|
35
5
|
def test_empty_string
|
36
6
|
assert_encode_and_decode('', '')
|
37
7
|
end
|
@@ -41,11 +11,11 @@ class TestURLcrypt < Test::Unit::TestCase
|
|
41
11
|
'111gc86f4nxw5zj1b3qmhpb14n5h25l4m7111',
|
42
12
|
"\0\0awesome \n ü string\0\0")
|
43
13
|
end
|
44
|
-
|
14
|
+
|
45
15
|
def test_invalid_encoding
|
46
16
|
assert_decoding('ZZZZZ', '')
|
47
17
|
end
|
48
|
-
|
18
|
+
|
49
19
|
def test_arbitrary_byte_strings
|
50
20
|
0.step(1500,17) do |n|
|
51
21
|
original = (0..n).map{rand(256).chr}.join
|
@@ -55,10 +25,12 @@ class TestURLcrypt < Test::Unit::TestCase
|
|
55
25
|
end
|
56
26
|
|
57
27
|
def test_encryption
|
58
|
-
#
|
59
|
-
|
60
|
-
|
61
|
-
|
28
|
+
# pack() converts this secret into a byte array
|
29
|
+
secret = ['d25883a27b9a639da85ea7e159b661218799c9efa63069fac13a6778c954fb6d'].pack('H*')
|
30
|
+
URLcrypt::key = secret
|
31
|
+
|
32
|
+
assert_equal OpenSSL::Cipher.new('aes-256-cbc').key_len, secret.bytesize
|
33
|
+
|
62
34
|
original = "hello world!"
|
63
35
|
encrypted = URLcrypt::encrypt(original)
|
64
36
|
assert_equal(URLcrypt::decrypt(encrypted), original)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
class URLcryptRegressionTest < TestClass
|
3
|
+
def test_encryption_and_decryption
|
4
|
+
original = '{"some":"json_data","token":"dfsfsdfsdf"}'
|
5
|
+
encrypted = URLcrypt.encrypt(original)
|
6
|
+
|
7
|
+
encrypted = URLcrypt::encrypt(original)
|
8
|
+
assert_equal(URLcrypt::decrypt(encrypted), original)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_encryption_with_too_long_key
|
12
|
+
# this key was generated via rake secret in a rails app, the pack() converts it into a byte array
|
13
|
+
secret = ['d25883a27b9a639da85ea7e159b661218799c9efa63069fac13a6778c954fb6d721968887a19bdb01af8f59eb5a90d256bd9903355c20b0b4b39bf4048b9b17b'].pack('H*')
|
14
|
+
URLcrypt::key = secret
|
15
|
+
|
16
|
+
assert OpenSSL::Cipher.new('aes-256-cbc').key_len < secret.bytesize
|
17
|
+
|
18
|
+
original = "hello world!"
|
19
|
+
encrypted = URLcrypt::encrypt(original)
|
20
|
+
assert_equal(URLcrypt::decrypt(encrypted), original)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_encryption_and_decryption_with_too_long_key
|
24
|
+
# this key was generated via rake secret in a rails app, the pack() converts it into a byte array
|
25
|
+
secret = ['d25883a27b9a639da85ea7e159b661218799c9efa63069fac13a6778c954fb6d721968887a19bdb01af8f59eb5a90d256bd9903355c20b0b4b39bf4048b9b17b'].pack('H*')
|
26
|
+
URLcrypt::key = secret
|
27
|
+
|
28
|
+
assert OpenSSL::Cipher.new('aes-256-cbc').key_len < secret.bytesize
|
29
|
+
|
30
|
+
original = '{"some":"json_data","token":"dfsfsdfsdf"}'
|
31
|
+
encrypted = URLcrypt.encrypt(original)
|
32
|
+
|
33
|
+
encrypted = URLcrypt::encrypt(original)
|
34
|
+
assert_equal(URLcrypt::decrypt(encrypted), original)
|
35
|
+
end
|
36
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.require(:default, :test)
|
4
|
+
|
5
|
+
require 'coveralls'
|
6
|
+
Coveralls.wear!
|
7
|
+
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
class TestClass < Test::Unit::TestCase
|
11
|
+
require 'URLcrypt'
|
12
|
+
|
13
|
+
def assert_bytes_equal(string1, string2)
|
14
|
+
bytes1 = string1.bytes.to_a.join(':')
|
15
|
+
bytes2 = string2.bytes.to_a.join(':')
|
16
|
+
assert_equal(bytes1, bytes2)
|
17
|
+
end
|
18
|
+
|
19
|
+
def assert_decoding(encoded, plain)
|
20
|
+
decoded = URLcrypt.decode(encoded)
|
21
|
+
assert_bytes_equal(plain, decoded)
|
22
|
+
end
|
23
|
+
|
24
|
+
def assert_encoding(encoded, plain)
|
25
|
+
actual = URLcrypt.encode(plain)
|
26
|
+
assert_bytes_equal(encoded, actual)
|
27
|
+
end
|
28
|
+
|
29
|
+
def assert_encode_and_decode(encoded, plain)
|
30
|
+
assert_encoding(encoded, plain)
|
31
|
+
assert_decoding(encoded, plain)
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,70 +1,51 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: urlcrypt
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 1
|
10
|
-
version: 0.1.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Thomas Fuchs
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2015-03-18 00:00:00 Z
|
11
|
+
date: 2020-11-02 00:00:00.000000000 Z
|
19
12
|
dependencies: []
|
20
|
-
|
21
13
|
description:
|
22
14
|
email: thomas@slash7.com
|
23
15
|
executables: []
|
24
|
-
|
25
16
|
extensions: []
|
26
|
-
|
27
|
-
|
17
|
+
extra_rdoc_files:
|
18
|
+
- README.md
|
19
|
+
files:
|
28
20
|
- README.md
|
29
|
-
files:
|
30
21
|
- Rakefile
|
31
22
|
- config/environment.rb
|
32
23
|
- lib/URLcrypt.rb
|
33
24
|
- test/URLcrypt_test.rb
|
34
|
-
-
|
25
|
+
- test/regression_test.rb
|
26
|
+
- test/test_helper.rb
|
35
27
|
homepage:
|
36
28
|
licenses: []
|
37
|
-
|
29
|
+
metadata: {}
|
38
30
|
post_install_message:
|
39
31
|
rdoc_options: []
|
40
|
-
|
41
|
-
require_paths:
|
32
|
+
require_paths:
|
42
33
|
- lib
|
43
34
|
- lib
|
44
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
-
|
46
|
-
requirements:
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
47
37
|
- - ">="
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
version: "0"
|
53
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
-
none: false
|
55
|
-
requirements:
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
56
42
|
- - ">="
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
|
60
|
-
- 0
|
61
|
-
version: "0"
|
62
|
-
requirements:
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements:
|
63
46
|
- none
|
64
|
-
|
65
|
-
rubygems_version: 1.8.24
|
47
|
+
rubygems_version: 3.1.2
|
66
48
|
signing_key:
|
67
|
-
specification_version:
|
49
|
+
specification_version: 4
|
68
50
|
summary: Securely encode and decode short pieces of arbitrary binary data in URLs.
|
69
51
|
test_files: []
|
70
|
-
|