pike.git / lib / modules / Standards.pmod / ASN1.pmod / Decode.pmod

version» Context lines:

pike.git/lib/modules/Standards.pmod/ASN1.pmod/Decode.pmod:78:   }      //! @param data   //! An instance of Stdio.Buffer containing the DER encoded data.   //!   //! @param types   //! A mapping from combined tag numbers to classes from or derived   //! from @[Standards.ASN1.Types]. Combined tag numbers may be   //! generated using @[Standards.ASN1.Types.make_combined_tag].   //! + //! @param secure + //! Will fail if the encoded ASN.1 isn't in its canonical encoding. + //!   //! @returns   //! An object from @[Standards.ASN1.Types] or, either   //! @[Standards.ASN1.Decode.Primitive] or   //! @[Standards.ASN1.Decode.constructed], if the type is unknown.   //! Throws an exception if the data could not be decoded.   //!   //! @fixme   //! Handling of implicit and explicit ASN.1 tagging, as well as   //! other context dependence, is next to non_existant.   .Types.Object der_decode(Stdio.Buffer data, -  mapping(int:program(.Types.Object)) types) +  mapping(int:program(.Types.Object)) types, +  void|int(0..1) secure)   {    [int(0..3) cls, int constructed, int(0..) tag] = read_identifier(data);       int len = data->read_int8();    // if( !cls && !constructed && !tag && !len )    // error("End-of-contents not supported.\n");    if( !cls && !tag )    error("Tag 0 reserved for BER encoding.\n");    if (len & 0x80)    {
pike.git/lib/modules/Standards.pmod/ASN1.pmod/Decode.pmod:123:       if (constructed)    {    DBG("Decoding constructed %O\n", p);       if (!p)    {    array(.Types.Object) elements = ({ });       while (sizeof(data)) -  elements += ({ der_decode(data, types) }); +  elements += ({ der_decode(data, types, secure) });       if (cls==2 && sizeof(elements)==1)    {    // Context-specific constructed compound with a single element.    // ==> Probably a TaggedType.    DBG("Probable tagged type.\n");    return .Types.MetaExplicit(2, tag)(elements[0]);    }       DBG("Unknown constructed type.\n");
pike.git/lib/modules/Standards.pmod/ASN1.pmod/Decode.pmod:148:    res->cls = cls;    res->tag = tag;    res->begin_decode_constructed((string(8bit))data);       // Ask object which types it expects for field i, decode it, and    // record the decoded object    for(int i = 0; sizeof(data); i++)    {    DBG("Element %d\n", i);    res->decode_constructed_element -  (i, der_decode(data, -  res->element_types(i, types))); +  (i, der_decode(data, res->element_types(i, types), secure));    }    return res;    }       DBG("Decoding Primitive\n");       if (p)    {    .Types.Object res = ([program]p)();    res->cls = cls;    res->tag = tag; -  return res->decode_primitive((string(8bit))data, this, types); +  return res->decode_primitive((string(8bit))data, this, types, secure);    }       return Primitive(cls, tag, (string(8bit))data);   }      #define U(x) .Types.make_combined_tag(0, (x))      mapping(int:program(.Types.Object)) universal_types =   ([ U(1) : .Types.Boolean,    U(2) : .Types.Integer,
pike.git/lib/modules/Standards.pmod/ASN1.pmod/Decode.pmod:227:   //! either @[Standards.ASN1.Decode.Primitive] or   //! @[Standards.ASN1.Decode.Constructed] if the type is unknown.   .Types.Object simple_der_decode(string(0..255) data,    mapping(int:program(.Types.Object))|void types)   {    types = types ? universal_types+[mapping]types : universal_types;    return der_decode(Stdio.Buffer(data)->set_error_mode(1), [mapping]types);   }      //! Works just like @[simple_der_decode], except it will return - //! @expr{0@} if there is trailing data in the provided ASN.1 @[data]. + //! @expr{0@} on errors, including if there is leading or trailing + //! data in the provided ASN.1 @[data].   //!   //! @seealso   //! @[simple_der_decode]   object(.Types.Object)|zero secure_der_decode(string(0..255) data,    mapping(int:program(.Types.Object))|void types)   {    types = types ? universal_types+[mapping]types : universal_types;    Stdio.Buffer buf = Stdio.Buffer(data)->set_error_mode(1); -  .Types.Object ret = der_decode(buf, [mapping]types); +  catch { +  .Types.Object ret = der_decode(buf, [mapping]types, 1);    if( sizeof(buf) ) return 0;    return ret; -  +  }; +  return 0;   }