cript 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Simple Encryption Tools for Ruby
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/cript.png)](http://badge.fury.io/rb/cript)
5
6
  [![Build Status](https://travis-ci.org/atongen/cript.png)](https://travis-ci.org/atongen/cript)
6
7
 
7
8
  ## Installation
@@ -69,25 +70,15 @@ encrypted = c.encrypt("More secret stuff!")
69
70
  You can use Cript::Simple from bash with the `cript` executable.
70
71
  Type `cript --help` after gem installation for usage.
71
72
 
72
- ### Cript::Hidr
73
+ ## TODO
73
74
 
74
- The Hidr class allows you to obscure strings in other strings by facilitating a two-way conversion
75
- between a string and a binary version of that string.
76
-
77
- The resulting binary characters can be any two charaters. By default it uses a space and a tab.
78
-
79
- ```ruby
80
- h = Cript::Hidr.new(b0: 'a', b1: 'z')
81
- result = h.hide('Wow!')
82
- ```
83
-
84
- After running this code, result will contain "zzzazazazzzzazzazzzazzzazaaaazaa".
85
-
86
- It comes with a few commonly used mappings already setup: ascii, unicode, orly.
87
- Call the class method of the same name to get these hidrs.
88
-
89
- You can use Cript::Hidr from bash with the `hidr` executable.
90
- Type `hidr --help` after gem installation for usage.
75
+ [ ] plugable encryption
76
+ [ ] gpg encryption
77
+ [ ] plugable storage
78
+ [ ] ssh storage
79
+ [ ] s3 storage
80
+ [ ] google drive storage
81
+ [ ] drb storage
91
82
 
92
83
  ## Contributing
93
84
 
data/lib/cript.rb CHANGED
@@ -11,4 +11,3 @@ require "cript/simple"
11
11
  require "cript/naive"
12
12
  require "cript/store"
13
13
  require "cript/ehash"
14
- require "cript/hidr"
data/lib/cript/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cript
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-25 00:00:00.000000000 Z
12
+ date: 2013-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -64,33 +64,28 @@ email:
64
64
  - atongen@gmail.com
65
65
  executables:
66
66
  - cript
67
- - hidr
68
67
  extensions: []
69
68
  extra_rdoc_files: []
70
69
  files:
71
70
  - .gitignore
71
+ - .rspec
72
72
  - .travis.yml
73
73
  - Gemfile
74
74
  - LICENSE.txt
75
75
  - README.md
76
76
  - Rakefile
77
77
  - bin/cript
78
- - bin/hidr
79
78
  - cript.gemspec
80
79
  - lib/cript.rb
81
80
  - lib/cript/cript_command.rb
82
81
  - lib/cript/cripter.rb
83
82
  - lib/cript/ehash.rb
84
- - lib/cript/hidr.rb
85
- - lib/cript/hidr_command.rb
86
83
  - lib/cript/naive.rb
87
84
  - lib/cript/simple.rb
88
85
  - lib/cript/store.rb
89
86
  - lib/cript/version.rb
90
87
  - spec/cript_command_spec.rb
91
88
  - spec/ehash_spec.rb
92
- - spec/hidr_command_spec.rb
93
- - spec/hidr_spec.rb
94
89
  - spec/naive_spec.rb
95
90
  - spec/simple_spec.rb
96
91
  - spec/spec_helper.rb
@@ -122,8 +117,6 @@ summary: Simple Encryption Tools for Ruby
122
117
  test_files:
123
118
  - spec/cript_command_spec.rb
124
119
  - spec/ehash_spec.rb
125
- - spec/hidr_command_spec.rb
126
- - spec/hidr_spec.rb
127
120
  - spec/naive_spec.rb
128
121
  - spec/simple_spec.rb
129
122
  - spec/spec_helper.rb
data/bin/hidr DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- lib = File.expand_path('../../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
- require 'cript/hidr_command'
6
- Cript::HidrCommand.new(ARGV).run!
data/lib/cript/hidr.rb DELETED
@@ -1,38 +0,0 @@
1
- # encoding: UTF-8
2
- #
3
- # Cript::Hidr
4
- #
5
- module Cript
6
- # Hidr can be used to obscure strings in other utf-8 strings.
7
- # This is not encryption, and it's not secure!
8
- class Hidr
9
-
10
- CHARS = {
11
- binary: ["0", "1"],
12
- ascii: ["\s","\t"],
13
- unicode: ["\u200B","\uFEFF"],
14
- orly: ["\u0CA0", "\u005F"],
15
- niceday: ["\s", "\u263A"]
16
- }
17
-
18
- class << self
19
- def build(type)
20
- if CHARS.has_key?(type)
21
- new(b0: CHARS[type].first, b1: CHARS[type].last)
22
- end
23
- end
24
- CHARS.keys.each { |key| class_eval("def #{key}; build(:#{key}); end") }
25
- end
26
-
27
- def initialize(*o)
28
- @o = o.last.is_a?(Hash) ? o.pop : {}
29
- @o[:b0] ||= CHARS[:ascii].first
30
- @o[:b1] ||= CHARS[:ascii].last
31
- end
32
-
33
- def h(m);m.unpack('b*').first.split("").map{|v|v=='0'?@o[:b0]:@o[:b1]}.join;end
34
- def s(n);[n.chars.to_a.map{|y|y==@o[:b0]?'0':'1'}.join].pack('b*');end
35
- def e(o);s(h(o));end
36
- { hide: :h, show: :s, echo: :e }.each { |k,v| alias_method k, v }
37
- end
38
- end
@@ -1,136 +0,0 @@
1
- require 'cript'
2
- require 'optparse'
3
-
4
- module Cript
5
- class HidrCommand
6
-
7
- attr_reader :options
8
-
9
- def initialize(argv)
10
- @argv = argv.dup
11
-
12
- @options = {
13
- mode: nil,
14
- infile: '-',
15
- outfile: '-',
16
- force: false,
17
- b0: '0',
18
- b1: '1',
19
- debug: false
20
- }
21
-
22
- parse!
23
- end
24
-
25
- def run!
26
- validate_mode
27
- hidr = build_hidr
28
- data = read_data
29
- get_writer do |writer|
30
- if @options[:mode] == 'hide'
31
- writer.print hidr.hide(data)
32
- else
33
- writer.print hidr.show(data)
34
- end
35
- end
36
- end
37
-
38
- private
39
-
40
- def parser
41
- @parser ||= OptionParser.new do |opts|
42
- opts.banner = "Usage: hidr [options]"
43
-
44
- opts.separator ""
45
- opts.separator "Mode:"
46
- opts.on("-h", "--hide", "hide mode") { @options[:mode] = 'hide' }
47
- opts.on("-s", "--show", "show mode") { @options[:mode] = 'show' }
48
-
49
- opts.separator ""
50
- opts.separator "Bits:"
51
- opts.on("-0", "--zero CHAR", "zero char (default: '#{@options[:b0]}')") { |char| @options[:b0] = char }
52
- opts.on("-1", "--one CHAR", "one char (default: '#{@options[:b1]}')") { |char| @options[:b1] = char }
53
- opts.on("-b", "--builtin BUILTIN", "built-in binary set (overrides zero and one, options: #{Cript::Hidr::CHARS.keys.join(', ')})") { |builtin| @options[:builtin] = builtin.to_s.strip.to_sym }
54
-
55
- opts.separator ""
56
- opts.separator "Files:"
57
- opts.on("-i", "--infile FILE", "infile (default: '#{@options[:infile]}')") { |file| @options[:infile] = file }
58
- opts.on("-o", "--outfile FILE", "outfile (default: '#{@options[:outfile]}')") { |file| @options[:outfile] = file }
59
- opts.on("-f", "--force", "force overwrite outfile (default: #{@options[:force]})") { @options[:force] = true }
60
-
61
- opts.separator ""
62
- opts.separator "Common options:"
63
-
64
- opts.on_tail("-D", "--debug", "Set debugging on") { @options[:debug] = true }
65
- opts.on_tail("-H", "--help", "Show this message") { puts opts; exit }
66
- opts.on_tail('-v', '--version', "Show version") { puts Cript::VERSION; exit }
67
- end
68
- end
69
-
70
- def parse!
71
- parser.parse!(@argv)
72
- end
73
-
74
- # run methods
75
-
76
- def validate_mode
77
- unless %w{ hide show }.include?(@options[:mode])
78
- STDERR.puts "Mode (show or hide) is required."
79
- exit 1
80
- end
81
- end
82
-
83
- def build_hidr
84
- if @options[:builtin]
85
- if Cript::Hidr::CHARS.keys.include?(@options[:builtin])
86
- Cript::Hidr.send(@options[:builtin])
87
- else
88
- STDERR.puts "Invalid builtin: #{@options[:builtin]}"
89
- exit 1
90
- end
91
- else
92
- Cript::Hidr.new(b0: @options[:b0], b1: @options[:b1])
93
- end
94
- end
95
-
96
- def read_data
97
- if @options[:infile] == '-'
98
- # requires ARGV clear
99
- STDIN.read
100
- elsif File.file?(@options[:infile])
101
- File.read(@options[:infile])
102
- else
103
- STDERR.puts "Invalid infile: #{@options[:infile]}"
104
- exit 1
105
- end
106
- end
107
-
108
- def get_writer
109
- begin
110
- if @options[:outfile] == '-'
111
- writer = STDOUT
112
- elsif File.file?(@options[:outfile])
113
- if @options[:force]
114
- writer = File.open(@options[:outfile], 'wb')
115
- else
116
- STDERR.puts "Not overwriting file without force"
117
- exit 1
118
- end
119
- else
120
- writer = File.open(@options[:outfile], 'wb')
121
- end
122
-
123
- yield(writer)
124
- rescue => e
125
- STDERR.puts "Error writing data: #{e}"
126
- exit 1
127
- ensure
128
- # clean-up
129
- if writer && @options[:outfile] != '-'
130
- writer.close
131
- end
132
- end
133
- end
134
-
135
- end
136
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
- require 'cript/hidr_command'
3
-
4
- describe Cript::HidrCommand do
5
-
6
- context 'parse' do
7
- it 'should parse hide options' do
8
- c = Cript::HidrCommand.new("-h -0 a -1 b -i /tmp/in.txt -o /tmp/out.txt -f -D".split(" "))
9
- c.options[:mode].should eql('hide')
10
- c.options[:b0].should eql('a')
11
- c.options[:b1].should eql('b')
12
- c.options[:infile].should eql('/tmp/in.txt')
13
- c.options[:outfile].should eql('/tmp/out.txt')
14
- c.options[:force].should be_true
15
- c.options[:debug].should be_true
16
- end
17
-
18
- it 'should parse show options' do
19
- c = Cript::HidrCommand.new("-s -0 a -1 b -i /tmp/in.txt -o /tmp/out.txt -f -D".split(" "))
20
- c.options[:mode].should eql('show')
21
- c.options[:b0].should eql('a')
22
- c.options[:b1].should eql('b')
23
- c.options[:infile].should eql('/tmp/in.txt')
24
- c.options[:outfile].should eql('/tmp/out.txt')
25
- c.options[:force].should be_true
26
- c.options[:debug].should be_true
27
- end
28
-
29
- it 'should recognize built-in hidrs' do
30
- c = Cript::HidrCommand.new("-s -b orly -i /tmp/in.txt -o /tmp/out.txt -f -D".split(" "))
31
- hidr = c.send(:build_hidr)
32
- opts = hidr.instance_variable_get(:@o)
33
- opts[:b0].should eql("\u0CA0")
34
- opts[:b1].should eql("\u005F")
35
- end
36
- end
37
- end
data/spec/hidr_spec.rb DELETED
@@ -1,43 +0,0 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
3
-
4
- describe Cript::Hidr do
5
- let(:ascii) { SecureRandom.base64(10240) }
6
- let(:bytes) { SecureRandom.random_bytes(10240) }
7
-
8
- context "ascii out" do
9
- let(:hidr) { Cript::Hidr.ascii }
10
-
11
- it 'should echo ascii' do
12
- hidr.e(ascii).should eql(ascii)
13
- end
14
-
15
- it 'should echo bytes' do
16
- hidr.e(bytes).should eql(bytes)
17
- end
18
- end
19
-
20
- context "unicode out" do
21
- let(:hidr) { Cript::Hidr.unicode }
22
-
23
- it 'should echo ascii' do
24
- hidr.e(ascii).should eql(ascii)
25
- end
26
-
27
- it 'should echo bytes' do
28
- hidr.e(bytes).should eql(bytes)
29
- end
30
- end
31
-
32
- context "orly out" do
33
- let(:hidr) { Cript::Hidr.orly }
34
-
35
- it 'should echo ascii' do
36
- hidr.e(ascii).should eql(ascii)
37
- end
38
-
39
- it 'should echo bytes' do
40
- hidr.e(bytes).should eql(bytes)
41
- end
42
- end
43
- end