stringent 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 120c7da87ce418a33d3983fa1c23524d2d87c1ae
4
+ data.tar.gz: 670a04abc57026643adbbe5d7fd78313c946ac43
5
+ SHA512:
6
+ metadata.gz: 65090a3035d60661f032294124c6b619c94b262d8a357aac0ddebafc35613200b8bb5478c47e304985a37b656c9205dd9d59235199a99b90accdb3d9fd2e30a1
7
+ data.tar.gz: f75a34b1bf48682460095904ae3a7d9979ea03d7724bdbd2bb7ad804b1907832bcea3d1a2dbcca1aa767453fc08516a47bcaf5f5e08f9df81ddb20e438799027
data/.gems ADDED
@@ -0,0 +1 @@
1
+ cutest -v 1.2.2
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,19 @@
1
+ This code tries to solve a particular problem with a very simple
2
+ implementation. We try to keep the code to a minimum while making
3
+ it as clear as possible. The design is very likely finished, and
4
+ if some feature is missing it is possible that it was left out on
5
+ purpose. That said, new usage patterns may arise, and when that
6
+ happens we are ready to adapt if necessary.
7
+
8
+ A good first step for contributing is to meet us on IRC and discuss
9
+ ideas. We spend a lot of time on #lesscode at freenode, always ready
10
+ to talk about code and simplicity. If connecting to IRC is not an
11
+ option, you can create an issue explaining the proposed change and
12
+ a use case. We pay a lot of attention to use cases, because our
13
+ goal is to keep the code base simple. Usually the result of a
14
+ conversation is the creation of a different tool.
15
+
16
+ Please don't start the conversation with a pull request. The code
17
+ should come at last, and even though it may help to convey an idea,
18
+ more often than not it draws the attention to a particular
19
+ implementation.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 Michel Martens
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ Stringent
2
+ =========
3
+
4
+ Generate a string with a target entropy
5
+
6
+ Description
7
+ -----------
8
+
9
+ Stringent uses `SecureRandom` to generate a pseudo-random number
10
+ with a target entropy, and proceeds to encode it with a given table
11
+ of symbols. The target entropy defaults to 256 bits, and the table
12
+ of symbols defaults to case sensitive alphanumeric characters. Both
13
+ values can be can be passed as parameters.
14
+
15
+ The entropy parameter means that there are `2^entropy` possible
16
+ outputs for a given call. However, it doesn not mean that each bit
17
+ is actually generated using one bit of entropy, since `SecureRandom`
18
+ may use `/dev/urandom` which, while unguessable, may have less than
19
+ 1 bit of entropy for each bit of output.
20
+
21
+ Usage
22
+ -----
23
+
24
+ Generate a random string with the default values for target entropy
25
+ and symbols table:
26
+
27
+ ```ruby
28
+ >> Stringent.generate
29
+ => "kEPcWwph6OkyHIKZtw4DwnWnlJo0Q6QoDp8Iykshrfm"
30
+ ```
31
+
32
+ Generate a random string with a custom target entropy:
33
+
34
+ ```ruby
35
+ >> Stringent.generate(entropy: 32)
36
+ => "Kqd6e0"
37
+ ```
38
+
39
+ Generate a random string with a custom target entropy and a custom
40
+ table:
41
+
42
+ ```ruby
43
+ >> Stringent.generate(entropy: 16, table: "01")
44
+ => "1000100110000000"
45
+ ```
46
+
47
+ Installation
48
+ ------------
49
+
50
+ ```
51
+ $ gem install stringent
52
+ ```
@@ -0,0 +1,15 @@
1
+ require "securerandom"
2
+
3
+ module Stringent
4
+ TABLE = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.freeze
5
+
6
+ def self.generate(entropy: 256, table: TABLE)
7
+ number = SecureRandom.random_number(2 ** entropy)
8
+ length = (entropy / Math.log2(table.size)).ceil
9
+
10
+ Array.new(length) {
11
+ number, modulo = number.divmod(table.size)
12
+ table[modulo]
13
+ }.join
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ .PHONY: test
2
+
3
+ test:
4
+ cutest ./test/*.rb
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "stringent"
3
+ s.version = "0.0.1"
4
+ s.summary = "Generate a string with a target entropy"
5
+ s.description = "Generate a string with a target entropy"
6
+ s.authors = ["Michel Martens"]
7
+ s.email = ["michel@soveran.com"]
8
+ s.homepage = "https://github.com/soveran/stringent"
9
+ s.license = "MIT"
10
+
11
+ s.files = `git ls-files`.split("\n")
12
+
13
+ s.add_development_dependency "cutest"
14
+ end
@@ -0,0 +1,6 @@
1
+ require_relative "../lib/stringent"
2
+
3
+ test do
4
+ assert_equal 1, Stringent.generate(entropy: 1, table: '01').size
5
+ assert_equal 2, Stringent.generate(entropy: 2, table: '01').size
6
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stringent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michel Martens
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cutest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Generate a string with a target entropy
28
+ email:
29
+ - michel@soveran.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gems
35
+ - CHANGELOG
36
+ - CONTRIBUTING
37
+ - LICENSE
38
+ - README.md
39
+ - lib/stringent.rb
40
+ - makefile
41
+ - stringent.gemspec
42
+ - test/all.rb
43
+ homepage: https://github.com/soveran/stringent
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.0.14
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Generate a string with a target entropy
67
+ test_files: []