Class: CcipherBox::BinStruct
- Inherits:
-
Object
- Object
- CcipherBox::BinStruct
- Includes:
- Singleton
- Defined in:
- lib/ccipher_box/bin_struct.rb
Instance Method Summary collapse
- #find_struct(buf, &block) ⇒ Object
- #struct(key, ver = "1.0") ⇒ Object
- #struct_fields_from_bin(bin, *args) ⇒ Object
- #struct_from_bin(bin) ⇒ Object
Instance Method Details
#find_struct(buf, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ccipher_box/bin_struct.rb', line 25 def find_struct(buf, &block) cpos = buf.pos begin #len = find_asn1_length(buf.string) len = Ccrypto::ASN1.engine.asn1_length(buf.bytes) #logger.debug "Found meta length : #{len}" if not logger.nil? raise InsufficientData if len == 0 buf.rewind = buf.read(len) if block block.call(, buf.read(cpos-len)) else end #rescue OpenSSL::ASN1::ASN1Error => ex rescue Ccrypto::ASN1EngineException => ex logger.error ex buf.seek(cpos) raise InsufficientData end end |
#struct(key, ver = "1.0") ⇒ Object
9 10 11 12 |
# File 'lib/ccipher_box/bin_struct.rb', line 9 def struct(key, ver = "1.0") st = structure(ver)[key] st.clone if not st.nil? end |
#struct_fields_from_bin(bin, *args) ⇒ Object
21 22 23 |
# File 'lib/ccipher_box/bin_struct.rb', line 21 def struct_fields_from_bin(bin, *args) Binenc::EngineFactory.instance(:bin_struct).value_from_bin_struct(bin, *args) end |
#struct_from_bin(bin) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/ccipher_box/bin_struct.rb', line 14 def struct_from_bin(bin) type, ver = struct_fields_from_bin(bin, 0, 1) c = CBTag.value_constant(type) st = struct(c, translate_version(ver)) st.from_bin(bin) if not st.nil? end |