xfcc_parser_ruby 0.1.2-x86_64-darwin

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: a704bfb54f31497eb99c050ecf220ac4b49ccd524146be63e819da0205dc0db3
4
+ data.tar.gz: fadead9b705f06e41c8eb93de2f1296fc2cb5023e3b504ef477f3f2b840c7bcc
5
+ SHA512:
6
+ metadata.gz: 590db45980bcda68f3e88e0d6675eee850bb8913e0de4ba5c11379b43b257ce705b1fbfe565634ce11291acacc56fc710186b93ef3a1e32d841033c3b3ff5da3
7
+ data.tar.gz: 967b798e519a1edefba2cc0e20fe5d7733e78ebe5729577919145355b171f915b265a80eb2a3d73bedfb7fda56ef0dc37dc1e0f3e0d739ab3a4910922569903f
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ inherit_mode:
2
+ merge:
3
+ - Exclude
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.6
7
+ Exclude:
8
+ - 'test/**/*'
9
+
10
+ Style/StringLiterals:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Style/StringLiteralsInInterpolation:
15
+ Enabled: true
16
+ EnforcedStyle: double_quotes
17
+
18
+ Layout/LineLength:
19
+ Max: 120
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.1.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ <a name="v0.1.2"></a>
2
+ ## v0.1.2 (2023-03-30)
3
+
4
+
5
+
6
+
7
+ <a name="v0.1.1"></a>
8
+ ## v0.1.1 (2023-03-28)
9
+
10
+
11
+
12
+
13
+ <a name="v0.1.0"></a>
14
+ ## v0.1.0 (2023-03-28)
15
+
16
+
17
+ #### Features
18
+
19
+ * Initial working copy ([ea243fad](ea243fad))
20
+
21
+
22
+
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at frederick888@tsundere.moe. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Cargo.lock ADDED
@@ -0,0 +1,134 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 3
4
+
5
+ [[package]]
6
+ name = "heck"
7
+ version = "0.4.1"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
10
+
11
+ [[package]]
12
+ name = "lazy_static"
13
+ version = "1.4.0"
14
+ source = "registry+https://github.com/rust-lang/crates.io-index"
15
+ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
16
+
17
+ [[package]]
18
+ name = "libc"
19
+ version = "0.2.140"
20
+ source = "registry+https://github.com/rust-lang/crates.io-index"
21
+ checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
22
+
23
+ [[package]]
24
+ name = "memchr"
25
+ version = "2.5.0"
26
+ source = "registry+https://github.com/rust-lang/crates.io-index"
27
+ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
28
+
29
+ [[package]]
30
+ name = "minimal-lexical"
31
+ version = "0.2.1"
32
+ source = "registry+https://github.com/rust-lang/crates.io-index"
33
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
34
+
35
+ [[package]]
36
+ name = "nom"
37
+ version = "7.1.3"
38
+ source = "registry+https://github.com/rust-lang/crates.io-index"
39
+ checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
40
+ dependencies = [
41
+ "memchr",
42
+ "minimal-lexical",
43
+ ]
44
+
45
+ [[package]]
46
+ name = "proc-macro2"
47
+ version = "1.0.53"
48
+ source = "registry+https://github.com/rust-lang/crates.io-index"
49
+ checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73"
50
+ dependencies = [
51
+ "unicode-ident",
52
+ ]
53
+
54
+ [[package]]
55
+ name = "quote"
56
+ version = "1.0.26"
57
+ source = "registry+https://github.com/rust-lang/crates.io-index"
58
+ checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
59
+ dependencies = [
60
+ "proc-macro2",
61
+ ]
62
+
63
+ [[package]]
64
+ name = "rustversion"
65
+ version = "1.0.12"
66
+ source = "registry+https://github.com/rust-lang/crates.io-index"
67
+ checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06"
68
+
69
+ [[package]]
70
+ name = "rutie"
71
+ version = "0.8.4"
72
+ source = "registry+https://github.com/rust-lang/crates.io-index"
73
+ checksum = "5d97db4cbb9739b48364c38cc9a6ebabdc07b42bd87b60ab448e1f29eaebb2ac"
74
+ dependencies = [
75
+ "lazy_static",
76
+ "libc",
77
+ ]
78
+
79
+ [[package]]
80
+ name = "strum"
81
+ version = "0.24.1"
82
+ source = "registry+https://github.com/rust-lang/crates.io-index"
83
+ checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"
84
+ dependencies = [
85
+ "strum_macros",
86
+ ]
87
+
88
+ [[package]]
89
+ name = "strum_macros"
90
+ version = "0.24.3"
91
+ source = "registry+https://github.com/rust-lang/crates.io-index"
92
+ checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59"
93
+ dependencies = [
94
+ "heck",
95
+ "proc-macro2",
96
+ "quote",
97
+ "rustversion",
98
+ "syn",
99
+ ]
100
+
101
+ [[package]]
102
+ name = "syn"
103
+ version = "1.0.109"
104
+ source = "registry+https://github.com/rust-lang/crates.io-index"
105
+ checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
106
+ dependencies = [
107
+ "proc-macro2",
108
+ "quote",
109
+ "unicode-ident",
110
+ ]
111
+
112
+ [[package]]
113
+ name = "unicode-ident"
114
+ version = "1.0.8"
115
+ source = "registry+https://github.com/rust-lang/crates.io-index"
116
+ checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
117
+
118
+ [[package]]
119
+ name = "xfcc-parser"
120
+ version = "0.1.1"
121
+ source = "registry+https://github.com/rust-lang/crates.io-index"
122
+ checksum = "35af20d7a78613f4cf414dc567269560f5edc5eed91ce87a2793874b093883ff"
123
+ dependencies = [
124
+ "nom",
125
+ "strum",
126
+ ]
127
+
128
+ [[package]]
129
+ name = "xfcc_parser_ruby"
130
+ version = "0.1.2"
131
+ dependencies = [
132
+ "rutie",
133
+ "xfcc-parser",
134
+ ]
data/Cargo.toml ADDED
@@ -0,0 +1,21 @@
1
+ [package]
2
+ name = "xfcc_parser_ruby"
3
+ version = "0.1.2"
4
+ authors = ["Frederick Zhang <frederick888@tsundere.moe>"]
5
+ edition = "2021"
6
+ description = "Envoy x-forwarded-client-cert (XFCC) parser written in Rust for Ruby"
7
+ repository = "https://github.com/Frederick888/xfcc_parser_ruby/"
8
+ license = "BSD-3-Clause"
9
+ keywords = ["envoy", "xfcc", "http"]
10
+ categories = ["parser-implementations", "web-programming"]
11
+
12
+ [dependencies]
13
+ rutie = "0.8.4"
14
+ xfcc-parser = "0.1.1"
15
+
16
+ [lib]
17
+ name = "xfcc_parser_ruby"
18
+ crate-type = ["cdylib"]
19
+
20
+ [profile.release]
21
+ strip = "debuginfo"
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem"s dependencies in xfcc_parser_ruby.gemspec
6
+ gemspec
7
+
8
+ gem "rutie", "~> 0.0.3"
9
+
10
+ gem "minitest", "~> 5.0"
11
+ gem "rake", "~> 13.0"
12
+ gem "rake-compiler", "~> 1.2.1"
13
+ gem "rb_sys"
14
+ gem "rubocop", "~> 1.21"
15
+ gem "rufo"
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ xfcc_parser_ruby (0.1.2-x86_64-darwin)
5
+ rutie (~> 0.0.3)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ json (2.6.3)
12
+ minitest (5.18.0)
13
+ parallel (1.22.1)
14
+ parser (3.2.1.1)
15
+ ast (~> 2.4.1)
16
+ rainbow (3.1.1)
17
+ rake (13.0.6)
18
+ rake-compiler (1.2.1)
19
+ rake
20
+ rb_sys (0.9.69)
21
+ regexp_parser (2.7.0)
22
+ rexml (3.2.5)
23
+ rubocop (1.48.1)
24
+ json (~> 2.3)
25
+ parallel (~> 1.10)
26
+ parser (>= 3.2.0.0)
27
+ rainbow (>= 2.2.2, < 4.0)
28
+ regexp_parser (>= 1.8, < 3.0)
29
+ rexml (>= 3.2.5, < 4.0)
30
+ rubocop-ast (>= 1.26.0, < 2.0)
31
+ ruby-progressbar (~> 1.7)
32
+ unicode-display_width (>= 2.4.0, < 3.0)
33
+ rubocop-ast (1.27.0)
34
+ parser (>= 3.2.1.0)
35
+ ruby-progressbar (1.13.0)
36
+ rufo (0.13.0)
37
+ rutie (0.0.4)
38
+ unicode-display_width (2.4.2)
39
+
40
+ PLATFORMS
41
+ x86_64-darwin-19
42
+ x86_64-darwin-21
43
+ x86_64-linux
44
+
45
+ DEPENDENCIES
46
+ minitest (~> 5.0)
47
+ rake (~> 13.0)
48
+ rake-compiler (~> 1.2.1)
49
+ rb_sys
50
+ rubocop (~> 1.21)
51
+ rufo
52
+ rutie (~> 0.0.3)
53
+ xfcc_parser_ruby!
54
+
55
+ BUNDLED WITH
56
+ 2.4.1
data/Justfile ADDED
@@ -0,0 +1,39 @@
1
+ set shell := ["bash", "+u", "-c"]
2
+
3
+ default:
4
+ bundle install
5
+ bundle exec rake
6
+
7
+ test:
8
+ bundle exec rake test
9
+
10
+ build:
11
+ bundle exec rake build
12
+
13
+ clean:
14
+ git clean -dfx -- lib pkg/* tmp
15
+
16
+ release version:
17
+ set -e
18
+ @if [[ "{{version}}" == v* ]]; then printf 'Must not have v-prefix\n'; exit 1; fi
19
+ # changelog
20
+ if [[ "{{version}}" != *"-"* ]]; then \
21
+ last_tag="$(git tag -l --sort version:refname | grep -v -- - | tail -n1)"; \
22
+ clog --from="$last_tag" --setversion=v{{version}} -o ./CHANGELOG.md; \
23
+ git add ./CHANGELOG.md; \
24
+ fi
25
+ # rust
26
+ sed 's/^version = ".*"$/version = "{{version}}"/' -i ./Cargo.toml
27
+ git add ./Cargo.toml
28
+ # ruby
29
+ sed 's/VERSION = ".*"$/VERSION = "{{version}}"/' -i ./lib/xfcc_parser_ruby/version.rb
30
+ # update lock files and test
31
+ just
32
+ git add ./Cargo.lock ./Gemfile.lock ./lib/xfcc_parser_ruby/version.rb
33
+ # commit and tag
34
+ git status
35
+ git diff --exit-code
36
+ git commit -m 'chore: Bump version to {{version}}'
37
+ git tag v{{version}}
38
+
39
+ # vim: set filetype=just :
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, Frederick Zhang
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # XfccParserRuby
2
+
3
+ Wrapper of Envoy [`x-forwarded-client-cert`][1] (XFCC) header parser [`xfcc-parser`][2].
4
+
5
+ ## Installation
6
+
7
+ First download the [Rust][3] toolchain >= 1.56.0 if you would like to install the source gem.
8
+
9
+ Then install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add xfcc_parser_ruby
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install xfcc_parser_ruby
16
+
17
+ Note that some distributions have different names for `libruby`, and if you've installed the gems with bundled binaries, you'll see errors like `libruby.so.3.0: cannot open shared object file: No such file or directory` when you load the library.
18
+
19
+ In this case, you can either link the `libruby` shared library to `libruby.[so|dylib|dll].[<version>]`, or simply install the source gem instead.
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require "xfcc_parser_ruby"
25
+
26
+ XfccParserRuby::Parser.element_list("By=http://example.com;URI=http://test.com")
27
+ ```
28
+
29
+ ## Development
30
+
31
+ First make sure you've installed the [Rust][3] toolchain >= 1.56.0.
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ 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).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Frederick888/xfcc_parser_ruby. 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/Frederick888/xfcc_parser_ruby/blob/master/CODE_OF_CONDUCT.md).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the XfccParserRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Frederick888/xfcc_parser_ruby/blob/master/CODE_OF_CONDUCT.md).
44
+
45
+ [1]: https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers#x-forwarded-client-cert
46
+ [2]: https://github.com/Frederick888/xfcc-parser
47
+ [3]: https://www.rust-lang.org/tools/install
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/extensiontask"
5
+ require "rake/testtask"
6
+
7
+ task build: :compile
8
+
9
+ GEMSPEC = Gem::Specification.load("xfcc_parser_ruby.gemspec")
10
+ RUBY_MINOR_VERSION = RUBY_VERSION.split(".")[0..1].join(".")
11
+
12
+ Rake::ExtensionTask.new("xfcc_parser_ruby", GEMSPEC) do |ext|
13
+ ext.lib_dir = "lib/#{RUBY_MINOR_VERSION}"
14
+ ext.ext_dir = "."
15
+ end
16
+
17
+ desc "Compile with debug symbols"
18
+ task "compile:debug" do
19
+ ENV["RB_SYS_CARGO_PROFILE"] = "dev"
20
+ Rake::Task["compile"].invoke
21
+ end
22
+
23
+ Rake::TestTask.new(:test) do |t|
24
+ t.libs << "test"
25
+ t.libs << "lib"
26
+ t.test_files = FileList["test/**/test_*.rb"]
27
+ end
28
+
29
+ require "rubocop/rake_task"
30
+
31
+ RuboCop::RakeTask.new
32
+
33
+ task default: %i[build test rubocop]
data/extconf.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "rb_sys/mkmf"
5
+
6
+ create_rust_makefile("xfcc_parser_ruby") do |r|
7
+ r.profile = ENV.fetch("RB_SYS_CARGO_PROFILE", :release).to_sym
8
+ end
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module XfccParserRuby
4
+ VERSION = "0.1.2"
5
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "xfcc_parser_ruby/version"
4
+ require "rutie"
5
+
6
+ # Envoy x-forwarded-client-cert (XFCC) parser
7
+ module XfccParserRuby
8
+ class XfccError < ::StandardError; end
9
+
10
+ # An XFCC element containing info of a client certificate
11
+ class Element
12
+ attr_accessor :by, :hash, :cert, :chain, :subject, :uri, :dns
13
+
14
+ def initialize(*args)
15
+ @by, @hash, @cert, @chain, @subject, @uri, @dns = args
16
+ end
17
+ end
18
+
19
+ RUBY_MINOR_VERSION = RUBY_VERSION.split(".")[0..1].join(".")
20
+ lib_path = "../lib/#{RUBY_MINOR_VERSION}"
21
+ Gem.path.each do |p|
22
+ if p.include? "/vendor/bundle/"
23
+ lib_path = "../lib/#{RUBY_MINOR_VERSION}"
24
+ break
25
+ end
26
+ if File.exist? "#{p}/gems/xfcc_parser_ruby-#{VERSION}/lib/xfcc_parser_ruby.so"
27
+ lib_path = "../lib"
28
+ break
29
+ end
30
+ end
31
+ Rutie.new(:xfcc_parser_ruby,
32
+ lib_prefix: "",
33
+ lib_path: lib_path,
34
+ lib_suffix: RbConfig::CONFIG["DLEXT"]).init "Init_xfcc_parser_ruby", __dir__
35
+ end
data/src/lib.rs ADDED
@@ -0,0 +1,106 @@
1
+ use std::borrow::{Borrow, Cow};
2
+
3
+ use rutie::types::Value;
4
+ use rutie::{
5
+ class, methods, AnyException, AnyObject, Array, Class, Exception, Module, NilClass, Object,
6
+ RString, VerifiedObject, VM,
7
+ };
8
+
9
+ class!(Parser);
10
+
11
+ methods!(
12
+ Parser,
13
+ _rtself,
14
+ fn pub_element_list(input: RString) -> Array {
15
+ let ruby_string = input.map_err(VM::raise_ex).unwrap();
16
+
17
+ let elements = xfcc_parser::element_list(ruby_string.to_str().as_bytes())
18
+ .map_err(|e| AnyException::new("XfccParserRuby::XfccError", Some(&e.to_string())))
19
+ .map_err(VM::raise_ex)
20
+ .unwrap();
21
+ let mut result: Array = Array::new();
22
+ for element in elements.iter() {
23
+ result.push(Element::new(element).to_any_object());
24
+ }
25
+
26
+ result
27
+ }
28
+ );
29
+
30
+ pub struct Element {
31
+ value: Value,
32
+ }
33
+
34
+ impl Element {
35
+ pub fn new(rust_element: &xfcc_parser::Element) -> Self {
36
+ let by = Self::to_ruby_array(&rust_element.by);
37
+ let hash = Self::to_ruby_string(&rust_element.hash);
38
+ let cert = Self::to_ruby_string(&rust_element.cert);
39
+ let chain = Self::to_ruby_string(&rust_element.chain);
40
+ let subject = Self::to_ruby_string(&rust_element.subject);
41
+ let uri = Self::to_ruby_array(&rust_element.uri);
42
+ let dns = Self::to_ruby_array(&rust_element.dns);
43
+
44
+ let arguments = [by, hash, cert, chain, subject, uri, dns];
45
+
46
+ let instance = Class::from_existing("XfccParserRuby")
47
+ .get_nested_class("Element")
48
+ .new_instance(&arguments);
49
+
50
+ Self {
51
+ value: instance.value(),
52
+ }
53
+ }
54
+
55
+ pub fn to_any_object(&self) -> AnyObject {
56
+ AnyObject::from(self.value())
57
+ }
58
+
59
+ fn to_ruby_array(value: &[Cow<str>]) -> AnyObject {
60
+ value
61
+ .iter()
62
+ .map(|s| RString::new_utf8(s).to_any_object())
63
+ .collect::<Array>()
64
+ .to_any_object()
65
+ }
66
+
67
+ fn to_ruby_string(value: &Option<Cow<str>>) -> AnyObject {
68
+ match value {
69
+ Some(s) => RString::new_utf8(s.borrow()).to_any_object(),
70
+ None => NilClass::new().to_any_object(),
71
+ }
72
+ }
73
+ }
74
+
75
+ impl From<Value> for Element {
76
+ fn from(value: Value) -> Self {
77
+ Self { value }
78
+ }
79
+ }
80
+
81
+ impl Object for Element {
82
+ #[inline]
83
+ fn value(&self) -> Value {
84
+ self.value
85
+ }
86
+ }
87
+
88
+ impl VerifiedObject for Element {
89
+ fn is_correct_type<T: Object>(object: &T) -> bool {
90
+ Class::from_existing("Element").case_equals(object)
91
+ }
92
+
93
+ fn error_message() -> &'static str {
94
+ "Error converting to Element"
95
+ }
96
+ }
97
+
98
+ #[allow(non_snake_case)]
99
+ #[no_mangle]
100
+ pub extern "C" fn Init_xfcc_parser_ruby() {
101
+ Module::from_existing("XfccParserRuby")
102
+ .define_nested_class("Parser", None)
103
+ .define(|klass| {
104
+ klass.def_self("element_list", pub_element_list);
105
+ });
106
+ }
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/xfcc_parser_ruby/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ binary_gem = !ENV["XFCC_PARSER_RUBY_BINARY_GEM"].nil?
7
+
8
+ spec.name = "xfcc_parser_ruby"
9
+ spec.version = XfccParserRuby::VERSION
10
+ spec.authors = ["Frederick Zhang"]
11
+ spec.email = ["frederick888@tsundere.moe"]
12
+ spec.license = "BSD-3-Clause"
13
+
14
+ spec.summary = "Envoy x-forwarded-client-cert (XFCC) parser"
15
+ spec.description = "Envoy x-forwarded-client-cert (XFCC) parser written in Rust for Ruby"
16
+ spec.homepage = "https://github.com/Frederick888/xfcc_parser_ruby/"
17
+ spec.required_ruby_version = [">= 2.6.0", "< 3.2.0"]
18
+ spec.required_rubygems_version = ">= 3.3.11"
19
+ spec.platform = Gem::Platform.local.tap { |p| p.version = nil } if binary_gem
20
+
21
+ # spec.metadata['allowed_push_host'] = "TODO: Set to your gem server 'https://example.com'"
22
+
23
+ spec.metadata["homepage_uri"] = spec.homepage
24
+ spec.metadata["source_code_uri"] = spec.homepage
25
+ spec.metadata["changelog_uri"] = "https://github.com/Frederick888/xfcc_parser_ruby/blob/master/CHANGELOG.md"
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(__dir__) do
30
+ `git ls-files -z`.split("\x0").reject do |f|
31
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
32
+ end
33
+ end
34
+ spec.files += Dir["lib/*/xfcc_parser_ruby.#{RbConfig::CONFIG["DLEXT"]}"] if binary_gem
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+ spec.extensions = ["Cargo.toml"] unless binary_gem
39
+
40
+ # Uncomment to register a new dependency of your gem
41
+ spec.add_dependency "rutie", "~> 0.0.3"
42
+ spec.add_development_dependency "minitest", "~> 5.0"
43
+ spec.add_development_dependency "rake", "~> 13.0"
44
+ spec.add_development_dependency "rake-compiler", "~> 1.2.1"
45
+ spec.add_development_dependency "rb_sys"
46
+ spec.add_development_dependency "rubocop", "~> 1.21"
47
+ spec.add_development_dependency "rufo"
48
+
49
+ # For more information and examples about making a new gem, check out our
50
+ # guide at: https://bundler.io/guides/creating_gem.html
51
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xfcc_parser_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: x86_64-darwin
6
+ authors:
7
+ - Frederick Zhang
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rutie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake-compiler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rb_sys
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.21'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.21'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rufo
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Envoy x-forwarded-client-cert (XFCC) parser written in Rust for Ruby
112
+ email:
113
+ - frederick888@tsundere.moe
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".rubocop.yml"
119
+ - ".tool-versions"
120
+ - CHANGELOG.md
121
+ - CODE_OF_CONDUCT.md
122
+ - Cargo.lock
123
+ - Cargo.toml
124
+ - Gemfile
125
+ - Gemfile.lock
126
+ - Justfile
127
+ - LICENSE
128
+ - README.md
129
+ - Rakefile
130
+ - extconf.rb
131
+ - lib/2.6/xfcc_parser_ruby.bundle
132
+ - lib/2.7/xfcc_parser_ruby.bundle
133
+ - lib/3.0/xfcc_parser_ruby.bundle
134
+ - lib/3.1/xfcc_parser_ruby.bundle
135
+ - lib/xfcc_parser_ruby.rb
136
+ - lib/xfcc_parser_ruby/version.rb
137
+ - src/lib.rs
138
+ - xfcc_parser_ruby.gemspec
139
+ homepage: https://github.com/Frederick888/xfcc_parser_ruby/
140
+ licenses:
141
+ - BSD-3-Clause
142
+ metadata:
143
+ homepage_uri: https://github.com/Frederick888/xfcc_parser_ruby/
144
+ source_code_uri: https://github.com/Frederick888/xfcc_parser_ruby/
145
+ changelog_uri: https://github.com/Frederick888/xfcc_parser_ruby/blob/master/CHANGELOG.md
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: 2.6.0
155
+ - - "<"
156
+ - !ruby/object:Gem::Version
157
+ version: 3.2.0
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: 3.3.11
163
+ requirements: []
164
+ rubygems_version: 3.4.10
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: Envoy x-forwarded-client-cert (XFCC) parser
168
+ test_files: []