
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
A RubyGem to parse and validate barcodes.
Add this line to your application's Gemfile:
gem "barcodevalidation"
And then execute:
$ bundle
Or install it yourself as:
$ gem install barcodevalidation
The main API is BarcodeValidation.scan
. It accepts a single argument,
and it's pretty flexible about what you give it.
gtin = BarcodeValidation.scan("937179-004167")
# => #<BarcodeValidation::GTIN::GTIN12(937179004167)>
gtin.to_s # => "937179004167"
gtin.valid? # => true
gtin.check_digit # => #<BarcodeValidation::GTIN::CheckDigit(7)>
gtin.first(6) # => #<BarcodeValidation::DigitSequence(937179)>
gtin.slice(0..5) # => #<BarcodeValidation::DigitSequence(937179)>
gtin.to_gtin_13 # => #<BarcodeValidation::GTIN::GTIN13(0937179004167)>
gtin.to_all_valid
# => [#<BarcodeValidation::GTIN::GTIN12(937179004167)>,
#<BarcodeValidation::GTIN::GTIN123(0937179004167)>]
bad = BarcodeValidation.scan(937_179_004_162)
# => #<BarcodeValidation::InvalidGTIN(937179004162)>
bad.valid? # => false
bad.check_digit # => #<BarcodeValidation::GTIN::CheckDigit(2) invalid: expected 7>
bad.check_digit.valid? # => false
bad.check_digit.actual # => #<BarcodeValidation::Digit(2)>
bad.check_digit.expected # => #<BarcodeValidation::Digit(7)>
bad.to_gtin_13 # => #<BarcodeValidation::InvalidGTIN(937179004162)>
bad.to_all_valid # => []
If the standard GTINs provided are not enough for your needs, you can implement your own by subclassing BarcodeValidation::GTIN::Base
or any of its subclasses. If your custom class overlaps with a default class or one of your other custom classes, you can declare prioritize_before <other class>
to re-order their evaluation order.
An example:
# A custom class that handles any length GTIN as long as it starts with "123".
# Note that we must still provide a VALID_LENGTH to allow transcoding to other GTINs by zero-padding.
# Due to this inheriting from Base, it is automatically registered and added to the end of the list of classes to check if it `handles?` an input.
class MyCustomGTIN < BarcodeValidation::GTIN::Base
VALID_LENGTH = 20
def self.handles?(input)
input.start_with?("123") && input.length <= VALID_LENGTH
end
# Custom validity check
def valid?
self.class.handles?(input) && check_digit.valid?
end
end
# A custom implementation of GTIN13, which addresses a subset of the GTIN13 range.
class MyCustomGTIN13 < BarcodeValidation::GTIN::GTIN13
# Ensure we get a chance to handle GTINs before our parent,
# so we can handle the subset we care about and have our parent handle the rest.
prioritize_before BarcodeValidation::GTIN::GTIN13
def self.handles?(input)
input.start_with?("123") && super
end
def valid?
input.start_with?("123") && super
end
end
Download the code from GitHub:
git clone git@github.com:marketplacer/barcodevalidation.git
Set up dependencies using Bundler:
cd barcodevalidation
bin/setup
Start the interactive development console:
bin/console
Run a build:
bin/rake
StandardRB is used to enforce coding standards.
bin/standardrb
Code is automatically tested with each push on Buildkite. Assuming all tests pass, commits on main
will be parsed with Semantic Release to produce new Git tags, and to publish to RubyGems.
This project's structure is inspired by the Bundler skeleton for a new
Gem, created using bundler gem barcodevalidation
.
.bundle/config
: Configuration for Bundler.ruby-version
: Gives rvm, rbenv, chruby etc. a Ruby version to useGemfile
: Lists RubyGem dependencies, to be installed by BundlerRakefile
: Defines Rake tasksbin/
: Contains binstubs, useful for development tasks
bundle
: Runs Bundler, in the correct wayconsole
: development console (equiv. to bin/bundle exec pry
)rake
: Runs Rake (equivalent to bin/bundle exec rake
)standardrb
: Runs standardrb (equivalent to bin/bundle exec standardrb
)setup
: Sets up the project to be ready for developmentconfig/boot.rb
: Prepares dependencies before loading the librarylib/
: Source files; this directory is added to Ruby's load pathscript/ci
: The script run by Buildkite to start a buildThis project is licensed under the MIT License. See LICENSE.md for the full text.
FAQs
Unknown package
We found that barcodevalidation demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.