byteman 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 12aa595840a63b8f3737a5f0ed88241d4db1c26d5fdac6a232d2fe2f44fdc1b4
4
+ data.tar.gz: f6e7c849df1d5194a96a18024aca9210120033b0bde2fb48ef4972c4e4998c72
5
+ SHA512:
6
+ metadata.gz: f8f5a4caed096e505a08bd44c26bd54f6eef2625018f8c628c7e7010884cde132c9893be2dd928a0922d9126c46aa987d4d2ee4b5e0ce402ae58f2d87ca7c371
7
+ data.tar.gz: 9f63095dd068bb73b346957450ddbdf776d57c953c60a49d1170543c6f71e6008c622232f2f1cdc7a994840846bb5c47cc568cb27b52c6c56a70afd48b0d3b26
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at micah.shute@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in byteman.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "pry", "~> 0.13.1", group: :development
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ byteman (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.3)
10
+ diff-lcs (1.4.2)
11
+ method_source (1.0.0)
12
+ pry (0.13.1)
13
+ coderay (~> 1.1)
14
+ method_source (~> 1.0)
15
+ rake (12.3.3)
16
+ rspec (3.9.0)
17
+ rspec-core (~> 3.9.0)
18
+ rspec-expectations (~> 3.9.0)
19
+ rspec-mocks (~> 3.9.0)
20
+ rspec-core (3.9.2)
21
+ rspec-support (~> 3.9.3)
22
+ rspec-expectations (3.9.2)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.9.0)
25
+ rspec-mocks (3.9.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.9.0)
28
+ rspec-support (3.9.3)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ byteman!
35
+ pry (~> 0.13.1)
36
+ rake (~> 12.0)
37
+ rspec (~> 3.0)
38
+
39
+ BUNDLED WITH
40
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 micahshute
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # Byteman
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/byteman`. 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 'byteman'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install byteman
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 tags, 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]/byteman. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/byteman/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Byteman project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/byteman/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ task :default => :spec
5
+
6
+ desc "opens interactive console for this program"
7
+ task :console do
8
+ require 'pry'
9
+ require_relative('./lib/byteman')
10
+ Pry.start
11
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "byteman"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/byteman/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "byteman"
5
+ spec.version = Byteman::VERSION
6
+ spec.authors = ["micahshute"]
7
+ spec.email = ["micah.shute@gmail.com"]
8
+
9
+ spec.summary = %q{Easily manipulate and transform data into different forms (e.g. byte strings, byte array buffers, hexdigests)}
10
+ spec.description = %q{Allows simple transformation of data into hex strings, hexdigest strings, integer byte arrays, etc. as well as padding your data to a certain byte length}
11
+ spec.homepage = "https://github.com/micahshute/byteman"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/micahshute/byteman"
19
+ spec.metadata["changelog_uri"] = "https://github.com/micahshute/byteman"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ end
@@ -0,0 +1,175 @@
1
+ require "byteman/version"
2
+
3
+ ##
4
+ # A simple module with methods that allow easy manipulation of data into other forms.
5
+ # Specifically focused on bytes, digests, and integer byte arrays (buffers)
6
+
7
+
8
+ module Byteman
9
+ ##
10
+ # A simple module with methods to allow you to easily manipulate
11
+ # data into different forms, such as strings and numbers to their hex digests,
12
+ # and back again, digests, numbers, and byte buffers into their bytes,
13
+ # padding
14
+
15
+
16
+ # pad args
17
+ #
18
+ # num: (named) [Array or Integer or String] Accepts an array of integers representing bytes (0-255), or an integer of any size (less than the pad size), or a byte string
19
+ #
20
+ # len: (named) [Integer] The number of bytes you want to pad this number to
21
+ #
22
+ # type: (named) [Symbol] (default: :bytes) Determines if you are padding bytes or bits. Defaults to :bytes, also accepts :bits
23
+ #
24
+ # Note that this pads 0s to the front of the number, and returns a byte string if an integer or string is the input arg, and returns an array buffer if an array buffer is entered
25
+ #
26
+ # Unexpected results will occur if the number is greater than the number of total padded byte length
27
+ def self.pad(num: nil, len: , type: :bytes)
28
+ raise ArgumentError.new("Type must be :bytes or :bits") if type != :bytes && type != :bits
29
+ if type == :bytes
30
+ if num.is_a?(Array)
31
+ overflow = len - (num.length % len)
32
+ return [0] * overflow + num
33
+ elsif num.is_a?(Integer)
34
+ hex(pad(num: int2buf(num), len: len))
35
+ elsif num.is_a?(String)
36
+ pad(num: num.unpack("C*"), len: len).pack("C*")
37
+ else
38
+ raise ArgumentError.new("Num must be a Array, Integer, or ByteString")
39
+ end
40
+ else
41
+ if num.is_a?(Integer)
42
+ bin_num = num.to_s(2)
43
+ elsif num.is_a?(String) && num.split('').all?{ |n| n == "0" || n == "1"}
44
+ bin_num = num
45
+ else
46
+ raise ArgumentError("If performing bit padding, the input must be an Integer or a string of bits")
47
+ end
48
+ overflow = len - (bin_num.length % len)
49
+ padded = "0" * overflow + bin_num
50
+ return padded
51
+ end
52
+ end
53
+
54
+
55
+ # str2digest args
56
+ #
57
+ # str: [String] the string whose bytes will be turned into a hexdigest representation of the data
58
+ #
59
+ # Returns a hexdigest string
60
+ def self.str2digest(str)
61
+ str.bytes.map do |b|
62
+ hexdigest(b)
63
+ end.join('')
64
+ end
65
+
66
+ # digest2buf args
67
+ #
68
+ # dig: [String] a string hexdigest that will be turned into an array of the represented bytes (the array will be half the length of the number of characters in the digest)
69
+ #
70
+ # Returns an integer array representing the bytes of the hexdigest
71
+ def self.digest2buf(dig)
72
+ hex2buf(hex(dig))
73
+ end
74
+
75
+ # hex2buf args
76
+ #
77
+ # hex: [String] hex string
78
+ #
79
+ # Returns an array of Integers, each representing a byte of data
80
+ def self.hex2buf(hex)
81
+ hex.unpack("C*")
82
+ end
83
+
84
+ # digest2int args
85
+ #
86
+ # dig: [String] hexdigest string
87
+ #
88
+ # Returns a byte String half the length of the hexdigest
89
+ def self.digest2int(dig)
90
+ dig.to_i(16)
91
+ end
92
+
93
+ # hex args
94
+ #
95
+ # input: [Integer or String or Array] accepts any Integer, or a hexdigest String or an integer array (byte buffer) with all numbers between 0-255 inclusive
96
+ #
97
+ # Returns a byte String.
98
+ #
99
+ # Note -> Automatically pads a 0 nibble to the front of any odd-lengthed hexdigest
100
+ def self.hex(input)
101
+ if input.is_a?(Integer)
102
+ hex(hexdigest(input))
103
+ elsif input.is_a?(String)
104
+ hd = input.length.odd? ? "0#{input}" : input
105
+ [hd].pack("H*")
106
+ elsif input.is_a?(Array)
107
+ input.pack("C*")
108
+ else
109
+ raise ArgumentError.new("Input must be a string, number, or byte array buffer")
110
+ end
111
+ end
112
+
113
+ # hexdigest args
114
+ #
115
+ # arg: [Integer or String or Array] accepts any Integer or String or Array of Integers from 0-255
116
+ #
117
+ # Returns a hexdigest string
118
+ def self.hexdigest(arg)
119
+ if arg.is_a?(Integer)
120
+ dig = arg.to_s(16)
121
+ dig.length.odd? ? "0#{dig}" : dig
122
+ elsif arg.is_a?(Array) && arg.all?{|a| a.between?(0,255)}
123
+ buf2digest(arg)
124
+ elsif arg.is_a?(String)
125
+ arg.unpack("H*").first
126
+ else
127
+ raise ArgumentError.new("Input must be an integer, Array of integers between 0-255, or String")
128
+ end
129
+ end
130
+
131
+ # buf2digest args
132
+ #
133
+ # barr: [Array] accepts an integer array (ints between 0-255 inclusive)
134
+ #
135
+ # Returns a hexdigest string
136
+ def self.buf2digest(barr)
137
+ barr.pack("C*").unpack("H*").first
138
+ end
139
+
140
+ # buf2hex args
141
+ #
142
+ # barr: [Array] accepts an integer array (ints between 0-255 inclusive)
143
+ #
144
+ # Returns a byte String
145
+ def self.buf2hex(barr)
146
+ barr.pack("C*")
147
+ end
148
+
149
+ # buf2int args
150
+ #
151
+ # barr: [Array] accepts an integer array (ints between 0-255 inclusive)
152
+ #
153
+ # Returns the Integer represeted by the byte array buffer
154
+ def self.buf2int(barr)
155
+ buf2digest(barr).to_i(16)
156
+ end
157
+
158
+ # int2buf args
159
+ #
160
+ # num: [Integer] any integer
161
+ #
162
+ # Returns an array of Integers between 0-255 inclusive, representing the byte buffer array
163
+ def self.int2buf(num)
164
+ hex(num).bytes
165
+ end
166
+
167
+ # hex2int args
168
+ #
169
+ # hex: [String]
170
+ #
171
+ # Returns the integer represented by the inputted hex string
172
+ def self.hex2int(hex)
173
+ hex.unpack("H*").first.to_i(16)
174
+ end
175
+ end
@@ -0,0 +1,3 @@
1
+ module Byteman
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: byteman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - micahshute
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Allows simple transformation of data into hex strings, hexdigest strings,
14
+ integer byte arrays, etc. as well as padding your data to a certain byte length
15
+ email:
16
+ - micah.shute@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".travis.yml"
24
+ - CODE_OF_CONDUCT.md
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/setup
32
+ - byteman.gemspec
33
+ - lib/byteman.rb
34
+ - lib/byteman/version.rb
35
+ homepage: https://github.com/micahshute/byteman
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ homepage_uri: https://github.com/micahshute/byteman
40
+ source_code_uri: https://github.com/micahshute/byteman
41
+ changelog_uri: https://github.com/micahshute/byteman
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.3.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.1.2
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Easily manipulate and transform data into different forms (e.g. byte strings,
61
+ byte array buffers, hexdigests)
62
+ test_files: []