bp_obfuscate 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7d092da00065a034273afe71000c7f84b67fbc3e
4
- data.tar.gz: ed4de85367bae578e7af3a6e0a6c1b204bdec6b4
2
+ SHA256:
3
+ metadata.gz: 106e82e30599e71026b2683baaae7413aa2104b2471039fc380c2a4eb4a822a3
4
+ data.tar.gz: 33abf0c80f641ddb8b5fbcc4b015ddc1b281fdfc45f424a54be7162716f6fe06
5
5
  SHA512:
6
- metadata.gz: a29eb83298d7baf603669d28ebdd98782c27823e314f399d3c747012e47e72b65609b4207baddbbc7dd047e2dd7f247833f35f94f7c776dc0307a72de09dc96f
7
- data.tar.gz: 470896681fafa230fb9700dc406aa9b088e632abc01e8e12d3da058bf9a26e9227425a667f96d596970cee6edc5f0f3404c39d0aeddbec765e39ace5699bbac4
6
+ metadata.gz: f012caab3baf15ad5045b81b034aaaab26926b423875df71579f712d7bba6fcad24c15b34ebb8a3b60e3a53aba00245f390bdcb1fae5a2d65eee9a4138333ea1
7
+ data.tar.gz: 97d332424a47a08cb4e6e60e9447250ac183d74cee7f3d594f84b5b7903862fe64998ac7b79979e150275e4362b0d8377d09c9ed2b1e836fcc0e4071cfb3d728
data/CHANGELOG.md ADDED
@@ -0,0 +1,55 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.2.0] - 2026-09-08
8
+
9
+ ### Added
10
+
11
+ - Rails 8 support.
12
+ - `base64` as an explicit runtime dependency; it stopped being a default gem in
13
+ Ruby 3.4, so `require "base64"` raised `LoadError` under Bundler there.
14
+ - GitHub Actions CI covering Ruby 2.7 through 3.4 plus ruby-head.
15
+ - A real README, and this changelog.
16
+
17
+ ### Fixed
18
+
19
+ - `cipher_key` called `Rails.application.secrets`, which was removed in Rails
20
+ 7.1, raising `NoMethodError` on every encrypt/decrypt under Rails 7.1 and 8.
21
+ The key now comes from `Rails.application.secret_key_base`, falling back to
22
+ the old `secrets` lookup for Rails versions that predate it.
23
+ - `defined?(Rails)` was true whenever any Rails constant was loaded, so the key
24
+ lookup could run with a `nil` `Rails.application` and raise.
25
+ - `raise NoCipherKey` raised `NameError`, because the constant lives in
26
+ `BpObfuscate` rather than `Obfuscate`. `BpObfuscate::NoCipherKey` is now
27
+ raised as documented.
28
+ - `rescue OpenSSL::Cipher::CipherError && ArgumentError` evaluated to just
29
+ `ArgumentError`, so `decrypt` raised `CipherError` on undecryptable input
30
+ instead of returning `nil`.
31
+ - Added the missing `require "digest"`, which had been working only via
32
+ whatever else happened to load it.
33
+ - `rake` failed with "Don't know how to build task 'spec'"; the `:spec` task is
34
+ now defined.
35
+
36
+ ### Changed
37
+
38
+ - `required_ruby_version` is now `>= 2.7`.
39
+ - Relaxed the `bundler ~> 1.13` and `rake ~> 10.0` development pins, which
40
+ could not resolve on a Ruby new enough to run Rails 8.
41
+ - Development and CI files are no longer packaged into the built gem.
42
+
43
+ ## [0.1.1] - 2017-04-30
44
+
45
+ ### Fixed
46
+
47
+ - Deprecation warning from `OpenSSL::Cipher::Cipher`.
48
+
49
+ ## [0.1.0] - 2017-01-31
50
+
51
+ - Initial release.
52
+
53
+ [0.2.0]: https://github.com/burningpony/bp_obfuscate/compare/v0.1.1...v0.2.0
54
+ [0.1.1]: https://github.com/burningpony/bp_obfuscate/compare/v0.1.0...v0.1.1
55
+ [0.1.0]: https://github.com/burningpony/bp_obfuscate/releases/tag/v0.1.0
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # BpObfuscate
2
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/bp_obfuscate`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![CI](https://github.com/burningpony/bp_obfuscate/actions/workflows/ci.yml/badge.svg)](https://github.com/burningpony/bp_obfuscate/actions/workflows/ci.yml)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ A simple wrapper around OpenSSL to easily encrypt/obfuscate data.
6
+
7
+ Inside a Rails application the key comes from the app's `secret_key_base`;
8
+ outside of Rails it comes from `ENV["SECRET_KEY_BASE"]`. Works on Rails 4.1
9
+ through Rails 8.
6
10
 
7
11
  ## Installation
8
12
 
@@ -12,30 +16,37 @@ Add this line to your application's Gemfile:
12
16
  gem 'bp_obfuscate'
13
17
  ```
14
18
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
19
+ And then run `bundle`. Or install it yourself as:
20
20
 
21
21
  $ gem install bp_obfuscate
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ ```ruby
26
+ token = Obfuscate.encrypt("user-42") # => "rIMK7MWO-u-gLdi7qVKU8A=="
27
+ Obfuscate.decrypt(token) # => "user-42"
28
+ Obfuscate.decrypt("garbage") # => nil
29
+ ```
30
+
31
+ `decrypt` returns `nil` instead of raising when it can't decrypt a value, so
32
+ it's safe to call on untrusted input such as a URL parameter.
33
+
34
+ If no key is available, `BpObfuscate::NoCipherKey` is raised.
26
35
 
27
36
  ## Development
28
37
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+ Run `bin/setup` to install dependencies, `bundle exec rspec` for the tests, and
39
+ `bin/console` for an interactive prompt.
30
40
 
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).
41
+ To release a new version, update the version number in `version.rb` and run
42
+ `bundle exec rake release`.
32
43
 
33
44
  ## Contributing
34
45
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bp_obfuscate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
-
46
+ Bug reports and pull requests are welcome on GitHub at
47
+ https://github.com/rposborne/bp_obfuscate.
37
48
 
38
49
  ## License
39
50
 
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
-
51
+ Available as open source under the terms of the
52
+ [MIT License](http://opensource.org/licenses/MIT).
data/bp_obfuscate.gemspec CHANGED
@@ -9,18 +9,37 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Russell Osborne"]
10
10
  spec.email = ["russell@burningpony.com"]
11
11
 
12
- spec.summary = "A simple wrapper to Open ssl to easily encrypt/obfuscate data."
13
- spec.homepage = "https://burningpony.com"
12
+ spec.summary = "A simple wrapper around OpenSSL to easily encrypt/obfuscate data."
13
+ spec.description = "A small wrapper around OpenSSL for encrypting and obfuscating " \
14
+ "short values such as ids in URLs. Derives its key from a Rails " \
15
+ "application's secret_key_base, or from ENV[\"SECRET_KEY_BASE\"] " \
16
+ "outside of Rails."
17
+ spec.homepage = "https://github.com/burningpony/bp_obfuscate"
14
18
  spec.license = "MIT"
15
19
 
20
+ spec.metadata = {
21
+ "homepage_uri" => spec.homepage,
22
+ "source_code_uri" => spec.homepage,
23
+ "changelog_uri" => "#{spec.homepage}/blob/master/CHANGELOG.md",
24
+ "bug_tracker_uri" => "#{spec.homepage}/issues",
25
+ "rubygems_mfa_required" => "true"
26
+ }
27
+
16
28
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
- f.match(%r{^(test|spec|features)/})
29
+ f.match(%r{^(test|spec|features)/}) ||
30
+ f.match(%r{^(\.github/|\.gitignore|\.rspec|Gemfile|Rakefile|bin/|CODE_OF_CONDUCT\.md)})
18
31
  end
19
32
  spec.bindir = "exe"
20
33
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
34
  spec.require_paths = ["lib"]
22
35
 
23
- spec.add_development_dependency "bundler", "~> 1.13"
24
- spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.required_ruby_version = ">= 2.7"
37
+
38
+ # base64 stopped being a default gem in Ruby 3.4, so it has to be declared.
39
+ # Deliberately open-ended: it is a stdlib shim, so any future version will do.
40
+ spec.add_dependency "base64", ">= 0.1"
41
+
42
+ spec.add_development_dependency "bundler", ">= 1.13", "< 5"
43
+ spec.add_development_dependency "rake", ">= 12.0", "< 14"
25
44
  spec.add_development_dependency "rspec", "~> 3.0"
26
45
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  require "openssl"
3
3
  require "base64"
4
+ require "digest"
4
5
 
5
6
  module Obfuscate
6
7
  class << self
@@ -9,21 +10,16 @@ module Obfuscate
9
10
  end
10
11
 
11
12
  def cipher_key
12
- if defined?(Rails)
13
- Rails.application.secrets.secret_key_base
14
- elsif ENV["SECRET_KEY_BASE"]
15
- ENV["SECRET_KEY_BASE"]
16
- else
17
- raise NoCipherKey, "you must have a an SECRET_KEY_BASE or be in a rails enviroment"
18
- end
13
+ rails_cipher_key || ENV["SECRET_KEY_BASE"] ||
14
+ raise(BpObfuscate::NoCipherKey, "you must have a an SECRET_KEY_BASE or be in a rails enviroment")
19
15
  end
20
16
 
21
17
  def decrypt(value)
22
18
  c = cipher.decrypt
23
19
  c.key = Digest::SHA256.digest(cipher_key)
24
20
  c.update(Base64.urlsafe_decode64(value.to_s)) + c.final
25
- rescue OpenSSL::Cipher::CipherError && ArgumentError
26
- return nil
21
+ rescue OpenSSL::Cipher::CipherError, ArgumentError
22
+ nil
27
23
  end
28
24
 
29
25
  def encrypt(value)
@@ -31,5 +27,20 @@ module Obfuscate
31
27
  c.key = Digest::SHA256.digest(cipher_key)
32
28
  Base64.urlsafe_encode64(c.update(value.to_s) + c.final)
33
29
  end
30
+
31
+ private
32
+
33
+ # Rails.application.secrets was removed in Rails 7.1, so read the key from
34
+ # the application itself, which resolves credentials/ENV on every version
35
+ # since Rails 4.1.
36
+ def rails_cipher_key
37
+ return nil unless defined?(Rails) && Rails.respond_to?(:application) && Rails.application
38
+
39
+ if Rails.application.respond_to?(:secret_key_base)
40
+ Rails.application.secret_key_base
41
+ elsif Rails.application.respond_to?(:secrets)
42
+ Rails.application.secrets.secret_key_base
43
+ end
44
+ end
34
45
  end
35
46
  end
@@ -1,3 +1,3 @@
1
1
  module BpObfuscate
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
metadata CHANGED
@@ -1,43 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bp_obfuscate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russell Osborne
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-30 00:00:00.000000000 Z
11
+ date: 2026-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: base64
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - "~>"
31
+ - - ">="
18
32
  - !ruby/object:Gem::Version
19
33
  version: '1.13'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '5'
20
37
  type: :development
21
38
  prerelease: false
22
39
  version_requirements: !ruby/object:Gem::Requirement
23
40
  requirements:
24
- - - "~>"
41
+ - - ">="
25
42
  - !ruby/object:Gem::Version
26
43
  version: '1.13'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '5'
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: rake
29
49
  requirement: !ruby/object:Gem::Requirement
30
50
  requirements:
31
- - - "~>"
51
+ - - ">="
32
52
  - !ruby/object:Gem::Version
33
- version: '10.0'
53
+ version: '12.0'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '14'
34
57
  type: :development
35
58
  prerelease: false
36
59
  version_requirements: !ruby/object:Gem::Requirement
37
60
  requirements:
38
- - - "~>"
61
+ - - ">="
39
62
  - !ruby/object:Gem::Version
40
- version: '10.0'
63
+ version: '12.0'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '14'
41
67
  - !ruby/object:Gem::Dependency
42
68
  name: rspec
43
69
  requirement: !ruby/object:Gem::Requirement
@@ -52,31 +78,32 @@ dependencies:
52
78
  - - "~>"
53
79
  - !ruby/object:Gem::Version
54
80
  version: '3.0'
55
- description:
81
+ description: A small wrapper around OpenSSL for encrypting and obfuscating short values
82
+ such as ids in URLs. Derives its key from a Rails application's secret_key_base,
83
+ or from ENV["SECRET_KEY_BASE"] outside of Rails.
56
84
  email:
57
85
  - russell@burningpony.com
58
86
  executables: []
59
87
  extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
62
- - ".gitignore"
63
- - ".rspec"
64
- - CODE_OF_CONDUCT.md
65
- - Gemfile
90
+ - CHANGELOG.md
66
91
  - LICENSE.txt
67
92
  - README.md
68
- - Rakefile
69
- - bin/console
70
- - bin/setup
71
93
  - bp_obfuscate.gemspec
72
94
  - lib/bp_obfuscate.rb
73
95
  - lib/bp_obfuscate/obfuscate.rb
74
96
  - lib/bp_obfuscate/version.rb
75
- homepage: https://burningpony.com
97
+ homepage: https://github.com/burningpony/bp_obfuscate
76
98
  licenses:
77
99
  - MIT
78
- metadata: {}
79
- post_install_message:
100
+ metadata:
101
+ homepage_uri: https://github.com/burningpony/bp_obfuscate
102
+ source_code_uri: https://github.com/burningpony/bp_obfuscate
103
+ changelog_uri: https://github.com/burningpony/bp_obfuscate/blob/master/CHANGELOG.md
104
+ bug_tracker_uri: https://github.com/burningpony/bp_obfuscate/issues
105
+ rubygems_mfa_required: 'true'
106
+ post_install_message:
80
107
  rdoc_options: []
81
108
  require_paths:
82
109
  - lib
@@ -84,16 +111,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
111
  requirements:
85
112
  - - ">="
86
113
  - !ruby/object:Gem::Version
87
- version: '0'
114
+ version: '2.7'
88
115
  required_rubygems_version: !ruby/object:Gem::Requirement
89
116
  requirements:
90
117
  - - ">="
91
118
  - !ruby/object:Gem::Version
92
119
  version: '0'
93
120
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.6.11
96
- signing_key:
121
+ rubygems_version: 3.5.22
122
+ signing_key:
97
123
  specification_version: 4
98
- summary: A simple wrapper to Open ssl to easily encrypt/obfuscate data.
124
+ summary: A simple wrapper around OpenSSL to easily encrypt/obfuscate data.
99
125
  test_files: []
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
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 russell@burningpony.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 [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in bp_obfuscate.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
- task default: :spec
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "bp_obfuscate"
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
data/bin/setup DELETED
@@ -1,8 +0,0 @@
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