Class: Ccrypto::Java::SecretSharingEngine
- Inherits:
-
Object
- Object
- Ccrypto::Java::SecretSharingEngine
- Includes:
- DataConversion
- Defined in:
- lib/ccrypto/java/engines/secret_sharing_engine.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args, &block) ⇒ SecretSharingEngine
constructor
A new instance of SecretSharingEngine.
- #split(secVal) ⇒ Object
Methods included from DataConversion
#from_b64, #from_hex, included, #to_b64, #to_b64_mime, #to_bin, #to_hex, #to_java_bytes, #to_str
Constructor Details
#initialize(*args, &block) ⇒ SecretSharingEngine
Returns a new instance of SecretSharingEngine.
9 10 11 12 13 14 |
# File 'lib/ccrypto/java/engines/secret_sharing_engine.rb', line 9 def initialize(*args, &block) @config = args.first raise SecretSharingException, "SecretSharingConfig is required" if not @config.is_a?(Ccrypto::SecretSharingConfig) raise SecretSharingException, "split_into value must be more than 1" if not @config.split_into.to_i > 1 raise SecretSharingException, "required_parts value (#{@config.required_parts}) must be less than or equal split_into value (#{@config.split_into})." if not @config.required_parts.to_i < @config.split_into.to_i end |
Class Method Details
.combine(req, parts) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ccrypto/java/engines/secret_sharing_engine.rb', line 31 def self.combine(req, parts) jhash = java.util.HashMap.new case parts when Hash # need to lock the key to java.lang.Integer # as the automated conversion of JRuby will turn the key into # java.lang.Long instead of java.lang.Integer # Using Map with parameterize auto conversion will failed inside the Java parts.each do |k,v| if not v.is_a?(::Java::byte[]) vv = to_java_bytes(v) else vv = v end jhash.put(java.lang.Integer.new(k),vv) end when java.util.Map jhash = parts else raise SecretSharingException, "Unsupported parts of #{parts.class}" end com.codahale.shamir.Scheme.join(jhash) end |
Instance Method Details
#split(secVal) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ccrypto/java/engines/secret_sharing_engine.rb', line 16 def split(secVal) eng = com.codahale.shamir.Scheme.new(java.security.SecureRandom.new, @config.split_into.to_i, @config.required_parts.to_i) case secVal when Ccrypto::SecretKey val = secVal.to_bin when ::Java::byte[] val = secVal when String val = to_java_bytes(secVal) else raise SecretSharingException, "Unknown secret value to split (#{secVal.class})" end eng.split(val) end |