Class: PQCrypto::Seal::Padding::BucketsPolicy
- Defined in:
- lib/pq_crypto/seal/padding.rb
Instance Attribute Summary collapse
-
#buckets ⇒ Object
readonly
Returns the value of attribute buckets.
Attributes inherited from Policy
Instance Method Summary collapse
-
#initialize(values) ⇒ BucketsPolicy
constructor
A new instance of BucketsPolicy.
- #target(base_length) ⇒ Object
Methods inherited from Policy
Constructor Details
#initialize(values) ⇒ BucketsPolicy
Returns a new instance of BucketsPolicy.
95 96 97 98 99 100 101 |
# File 'lib/pq_crypto/seal/padding.rb', line 95 def initialize(values) @buckets = Array(values).map { |value| Integer(value) }.uniq.sort.freeze raise InvalidConfigurationError, "padding buckets must not be empty" if @buckets.empty? raise InvalidConfigurationError, "padding buckets must be non-negative" if @buckets.first.negative? super(Format::PADDING_BUCKETS) end |
Instance Attribute Details
#buckets ⇒ Object (readonly)
Returns the value of attribute buckets.
93 94 95 |
# File 'lib/pq_crypto/seal/padding.rb', line 93 def buckets @buckets end |
Instance Method Details
#target(base_length) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/pq_crypto/seal/padding.rb', line 103 def target(base_length) bucket = buckets.bsearch { |value| value >= Integer(base_length) } raise InvalidConfigurationError, "no padding bucket can hold envelope" unless bucket bucket end |