Module: CcipherFactory::Encoding

Defined in:
lib/ccipher_factory/encoding/asn1.rb

Defined Under Namespace

Classes: EncoderError, InsufficientData

Class Method Summary collapse

Class Method Details

.extract_meta(buf, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ccipher_factory/encoding/asn1.rb', line 9

def self.extract_meta(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
    meta = buf.read(len)

    if block
      block.call(meta, buf.read(cpos-len))
    else
      meta
    end

    #rescue OpenSSL::ASN1::ASN1Error => ex
  rescue Ccrypto::ASN1EngineException => ex
    logger.error ex
    buf.seek(cpos)
    raise InsufficientData
  end

end