binenc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9913157fe0955aec04152db26fa91e2612f54383ff4e32ba42a0faf7df18aac5
4
+ data.tar.gz: 4b46279ae9e21e2b48afbcc7af91aaf079ddd074a067a611e40200eb5a609246
5
+ SHA512:
6
+ metadata.gz: 0a38305b16ad922f6785118cc9cda7a1f7b71b325835a8aa0191c3de2eb48b5532b783f03354e41f378e709fb69afe8146d42f85dba8f53302b61458bb64ff64
7
+ data.tar.gz: 27d850b149ffefcddd5b8cbd874d026da80bd90e4975aca07b406afdbf1b13b0506827b2b56c19396cc41cbb310b63da2c0b230b247c7bd62ad423c4a18cd0ff
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in binenc.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ binenc (0.1.0)
5
+ teLogger
6
+ toolrack
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ base58 (0.2.3)
12
+ devops_assist (0.2.0)
13
+ git_cli
14
+ git_cli_prompt
15
+ gvcs
16
+ teLogger
17
+ toolrack
18
+ tty-prompt
19
+ diff-lcs (1.5.0)
20
+ git_cli (0.9.0)
21
+ gvcs
22
+ ptools (~> 1.4.0)
23
+ tlogger
24
+ toolrack
25
+ git_cli_prompt (0.2.2)
26
+ tlogger
27
+ toolrack
28
+ tty-prompt
29
+ gvcs (0.1.0)
30
+ pastel (0.8.0)
31
+ tty-color (~> 0.5)
32
+ ptools (1.4.2)
33
+ rake (13.0.6)
34
+ rspec (3.11.0)
35
+ rspec-core (~> 3.11.0)
36
+ rspec-expectations (~> 3.11.0)
37
+ rspec-mocks (~> 3.11.0)
38
+ rspec-core (3.11.0)
39
+ rspec-support (~> 3.11.0)
40
+ rspec-expectations (3.11.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.11.0)
43
+ rspec-mocks (3.11.1)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.11.0)
46
+ rspec-support (3.11.0)
47
+ teLogger (0.1.0)
48
+ tlogger (0.26.3)
49
+ toolrack (0.18.6)
50
+ base58
51
+ tlogger
52
+ tty-color (0.6.0)
53
+ tty-cursor (0.7.1)
54
+ tty-prompt (0.23.1)
55
+ pastel (~> 0.8)
56
+ tty-reader (~> 0.8)
57
+ tty-reader (0.9.0)
58
+ tty-cursor (~> 0.7)
59
+ tty-screen (~> 0.8)
60
+ wisper (~> 2.0)
61
+ tty-screen (0.8.1)
62
+ wisper (2.0.1)
63
+
64
+ PLATFORMS
65
+ x86_64-linux
66
+
67
+ DEPENDENCIES
68
+ binenc!
69
+ devops_assist
70
+ rake (~> 13.0)
71
+ rspec (~> 3.0)
72
+
73
+ BUNDLED WITH
74
+ 2.2.28
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Binenc
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/binenc`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'binenc'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install binenc
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/binenc.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ require 'devops_assist'
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "binenc"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/binenc.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/binenc/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "binenc"
7
+ spec.version = Binenc::VERSION
8
+ spec.authors = ["Ian"]
9
+ spec.email = ["cameronian0@protonmail.com"]
10
+
11
+ spec.summary = "binenc - Binary encode decode library, normalization API for the Ruby and Java runtime"
12
+ spec.description = "Encode and decode to ASN.1 binary format. Meant to be a normalization API for Ruby and Java runtime"
13
+ spec.homepage = "https://github.com/cameronian/binenc"
14
+ spec.required_ruby_version = ">= 2.4.0"
15
+
16
+ #spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
17
+
18
+ #spec.metadata["homepage_uri"] = spec.homepage
19
+ #spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
20
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "teLogger"
34
+ spec.add_dependency "toolrack"
35
+
36
+ spec.add_development_dependency 'devops_assist'
37
+
38
+ # Uncomment to register a new dependency of your gem
39
+ # spec.add_dependency "example-gem", "~> 1.0"
40
+
41
+ # For more information and examples about making a new gem, checkout our
42
+ # guide at: https://bundler.io/guides/creating_gem.html
43
+ end
@@ -0,0 +1,86 @@
1
+
2
+ #require 'singleton'
3
+
4
+ module Binenc
5
+
6
+ # binary tagging constant helper
7
+ class BinTag
8
+ include TR::CondUtils
9
+ #include Singleton
10
+
11
+ def initialize
12
+ @constRaiseIfDup = false
13
+ @constant = { }
14
+ end
15
+
16
+ def load(&block)
17
+ instance_eval(&block)
18
+ end
19
+
20
+ ##
21
+ # DSL part
22
+ #
23
+ def define_constant(key, val, parent = nil, &block)
24
+ if @constant.keys.include?(key)
25
+ if @constRaiseIfDup
26
+ raise BinTagConstantKeyAlreadyExist, "Constant key '#{key}' already exist"
27
+ else
28
+ logger.warn "Overwriting existing key '#{key}'..."
29
+ end
30
+ end
31
+
32
+ if val.is_a?(String) and val =~ /#/
33
+ val = val.gsub("#",@parent).strip
34
+ end
35
+
36
+ @constant[key] = val
37
+
38
+ oldParent = @parent
39
+
40
+ @parent = val
41
+ if block
42
+ instance_eval(&block)
43
+ end
44
+ @parent = oldParent
45
+
46
+ end
47
+
48
+ def constant_value(key)
49
+ @constant[key]
50
+ end
51
+
52
+ def value_constant(val)
53
+ #if TR::RTUtils.on_java?
54
+ if val.is_a?(Integer)
55
+ @constant.invert[val.to_s.to_i]
56
+ else
57
+ @constant.invert[val]
58
+ end
59
+ #else
60
+ # @constant.invert[val]
61
+ #end
62
+ end
63
+
64
+ def raise_on_constant_key_duplicate=(val)
65
+ @constRaiseIfDup = val
66
+ end
67
+ def is_raise_on_constant_key_duplicate?
68
+ @constRaiseIfDup
69
+ end
70
+
71
+ ##
72
+ # End DSL
73
+ #
74
+
75
+ private
76
+ def logger
77
+ if @logger.nil?
78
+ @logger = TeLogger::Tlogger.new
79
+ @logger.tag = :bintag
80
+ end
81
+ @logger
82
+ end
83
+
84
+ end
85
+
86
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module Binenc
3
+ module BinaryObject
4
+
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+
2
+
3
+ module Binenc
4
+ class EngineFactory
5
+
6
+ def self.instance(*args, &block)
7
+ Provider.instance.provider.engine_instance(*args, &block)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,93 @@
1
+
2
+ require 'singleton'
3
+
4
+ module Binenc
5
+
6
+ class ProviderException < StandardError; end
7
+
8
+ class Provider
9
+ include Singleton
10
+ include TR::CondUtils
11
+
12
+ def register(prov)
13
+ raise ProviderException, "Provider cannot be nil" if prov.nil?
14
+ raise ProviderException, "Provider must have name" if not prov.respond_to?(:provider_name)
15
+
16
+ add_provider(prov)
17
+ end
18
+
19
+ def default_provider=(prov)
20
+ raise ProviderException, "Nil provider is not supported" if prov.nil?
21
+
22
+ case prov
23
+ when String
24
+ if is_provider_registered?(prov)
25
+ @defaultProvider = find_provider(prov)
26
+ else
27
+ raise ProviderException, "Given provider '#{prov}' to set as default has yet to be registered."
28
+ end
29
+ else
30
+ if prov.respond_to?(:provider_name)
31
+ add_provider(prov) if not is_provider_registered?(prov.provider_name)
32
+ @defaultProvider = prov
33
+ else
34
+ raise ProviderException, "Given provider to set as default does not have name"
35
+ end
36
+ end
37
+
38
+ @defaultProvider
39
+ end
40
+ def default_provider
41
+ @defaultProvider
42
+ end
43
+
44
+
45
+ def find_provider(prov)
46
+ if not_empty?(prov)
47
+ providers[prov]
48
+ else
49
+ raise ProviderException, "Cannot find nil empty provider"
50
+ end
51
+ end
52
+
53
+ def provider
54
+ raise ProviderException, "No provider is registered" if is_providers_empty?
55
+
56
+ if is_empty?(default_provider)
57
+ providers.values.first
58
+ else
59
+ default_provider
60
+ end
61
+ end
62
+
63
+
64
+ private
65
+ def add_provider(prov)
66
+ providers[prov.provider_name] = prov
67
+ logger.debug "Provider '#{prov.provider_name}' registered"
68
+ end
69
+
70
+ def is_provider_registered?(provName)
71
+ providers.keys.include?(provName)
72
+ end
73
+
74
+ def is_providers_empty?
75
+ providers.empty?
76
+ end
77
+
78
+ def providers
79
+ if @providers.nil?
80
+ @providers = {}
81
+ end
82
+ @providers
83
+ end
84
+
85
+ def logger
86
+ if @logger.nil?
87
+ @logger = Tlogger.new
88
+ end
89
+ @logger
90
+ end
91
+
92
+ end
93
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Binenc
4
+ VERSION = "0.1.0"
5
+ end
data/lib/binenc.rb ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'teLogger'
4
+ require 'toolrack'
5
+
6
+ require_relative "binenc/version"
7
+
8
+ require_relative 'binenc/provider'
9
+
10
+ require_relative 'binenc/engine_factory'
11
+
12
+ require_relative 'binenc/binary_object'
13
+
14
+ require_relative 'binenc/bin_tag/bin_tag'
15
+
16
+
17
+ module Binenc
18
+ class Error < StandardError; end
19
+
20
+ class BinencEngineException < StandardError; end
21
+
22
+ class BinTagException < StandardError; end
23
+ class BinTagConstantKeyAlreadyExist < StandardError; end
24
+ class BinTagConstantKeyNotFound < StandardError; end
25
+
26
+ class BinencDecodingError < StandardError; end
27
+ # Your code goes here...
28
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: binenc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ian
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: teLogger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: toolrack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: devops_assist
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Encode and decode to ASN.1 binary format. Meant to be a normalization
56
+ API for Ruby and Java runtime
57
+ email:
58
+ - cameronian0@protonmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".rspec"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - binenc.gemspec
71
+ - lib/binenc.rb
72
+ - lib/binenc/bin_tag/bin_tag.rb
73
+ - lib/binenc/binary_object.rb
74
+ - lib/binenc/engine_factory.rb
75
+ - lib/binenc/provider.rb
76
+ - lib/binenc/version.rb
77
+ homepage: https://github.com/cameronian/binenc
78
+ licenses: []
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.4.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.2.22
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: binenc - Binary encode decode library, normalization API for the Ruby and
99
+ Java runtime
100
+ test_files: []