CryptX

 view release on metacpan or  search on metacpan

CryptX.xs  view on Meta::CPAN

    }
    else if (strEQ(type, "OCTET_STRING")) {
        STRLEN vlen = 0;
        const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : "";
        s_asn1_append_tlv(aTHX_ out, 0x04, data, (unsigned long)vlen);
    }
    else if (strEQ(type, "BIT_STRING")) {
        STRLEN vlen = 0;
        const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : "";
        SV **sv_bits = hv_fetchs(node, "bits", 0);
        unsigned long nbits = (sv_bits && SvOK(*sv_bits)) ? (unsigned long)SvUV(*sv_bits) : (unsigned long)(vlen * 8);
        unsigned long nbytes = (nbits + 7) / 8;
        unsigned char unused = (nbytes > 0) ? (unsigned char)(8 * nbytes - nbits) : 0;
        unsigned long content_len = 1 + nbytes;
        unsigned char *content;

        Newxz(content, content_len, unsigned char);
        content[0] = unused;
        if (nbytes > 0 && vlen > 0) {
            Copy(data, content + 1, nbytes < (unsigned long)vlen ? nbytes : (unsigned long)vlen, unsigned char);
            if (unused > 0) content[nbytes] &= (unsigned char)(0xFF << unused);
        }
        s_asn1_append_tlv(aTHX_ out, 0x03, content, content_len);
        Safefree(content);
    }
    else if (strEQ(type, "UTF8_STRING")) {
        STRLEN vlen = 0;
        const char *data = (sv_value && SvOK(*sv_value)) ? SvPVutf8(*sv_value, vlen) : "";
        s_asn1_append_tlv(aTHX_ out, 0x0C, data, (unsigned long)vlen);
    }
    else if (strEQ(type, "IA5_STRING")) {
        STRLEN vlen = 0;
        const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : "";
        s_asn1_append_tlv(aTHX_ out, 0x16, data, (unsigned long)vlen);
    }
    else if (strEQ(type, "PRINTABLE_STRING")) {
        STRLEN vlen = 0;
        const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : "";
        s_asn1_append_tlv(aTHX_ out, 0x13, data, (unsigned long)vlen);
    }
    else if (strEQ(type, "TELETEX_STRING")) {
        STRLEN vlen = 0;
        const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : "";
        s_asn1_append_tlv(aTHX_ out, 0x14, data, (unsigned long)vlen);
    }
    else if (strEQ(type, "UTCTIME")) {
        STRLEN vlen = 0;
        const char *data = (sv_value && SvOK(*sv_value)) ? SvPV(*sv_value, vlen) : "";
        s_asn1_append_tlv(aTHX_ out, 0x17, data, (unsigned long)vlen);
    }
    else if (strEQ(type, "GENERALIZEDTIME")) {
        STRLEN vlen = 0;
        const char *data = (sv_value && SvOK(*sv_value)) ? SvPV(*sv_value, vlen) : "";
        s_asn1_append_tlv(aTHX_ out, 0x18, data, (unsigned long)vlen);
    }
    else if (strEQ(type, "SEQUENCE") || strEQ(type, "SET")) {
        unsigned char tag = strEQ(type, "SEQUENCE") ? 0x30 : 0x31;
        if (sv_value && SvROK(*sv_value) && SvTYPE(SvRV(*sv_value)) == SVt_PVAV) {
            SV *content = newSVpvn("", 0);
            s_asn1_encode_nodes(aTHX_ content, (AV *)SvRV(*sv_value));
            { STRLEN clen; const char *cdata = SvPV(content, clen);
              s_asn1_append_tlv(aTHX_ out, tag, cdata, (unsigned long)clen); }
            SvREFCNT_dec(content);
        } else {
            s_asn1_append_tlv(aTHX_ out, tag, NULL, 0);
        }
    }
    else if (strEQ(type, "CUSTOM")) {
        SV **sv_class  = hv_fetchs(node, "class", 0);
        SV **sv_constr = hv_fetchs(node, "constructed", 0);
        SV **sv_tag    = hv_fetchs(node, "tag", 0);
        unsigned int klass = (sv_class && SvOK(*sv_class)) ? (unsigned int)SvIV(*sv_class) : 2;
        unsigned int pc    = (sv_constr && SvOK(*sv_constr) && SvIV(*sv_constr)) ? 1 : 0;
        unsigned long tag  = (sv_tag && SvOK(*sv_tag)) ? (unsigned long)SvUV(*sv_tag) : 0;

        if (pc && sv_value && SvROK(*sv_value) && SvTYPE(SvRV(*sv_value)) == SVt_PVAV) {
            SV *content = newSVpvn("", 0);
            s_asn1_encode_nodes(aTHX_ content, (AV *)SvRV(*sv_value));
            { STRLEN clen; const char *cdata = SvPV(content, clen);
              s_asn1_append_custom_tlv(aTHX_ out, klass, pc, tag, cdata, (unsigned long)clen); }
            SvREFCNT_dec(content);
        } else {
            STRLEN vlen = 0;
            const char *data = (sv_value && SvOK(*sv_value)) ? SvPVbyte(*sv_value, vlen) : "";
            s_asn1_append_custom_tlv(aTHX_ out, klass, pc, tag, data, (unsigned long)vlen);
        }
    }
    else {
        croak("FATAL: asn1_encode: unsupported type '%s'", type);
    }
}
/* --- end Crypt::ASN1 encoder helpers ------------------------------------- */

typedef struct cbc_struct {             /* used by Crypt::Mode::CBC */
  int cipher_id, cipher_rounds;
  symmetric_CBC state;
  unsigned char pad[MAXBLOCKSIZE];
  int padlen;
  int padding_mode;
  int direction;
} *Crypt__Mode__CBC;

typedef struct ecb_struct {             /* used by Crypt::Mode::ECB */
  int cipher_id, cipher_rounds;
  symmetric_ECB state;
  unsigned char pad[MAXBLOCKSIZE];
  int padlen;
  int padding_mode;
  int direction;
} *Crypt__Mode__ECB;

typedef struct cfb_struct {             /* used by Crypt::Mode::CFB */
  int cipher_id, cipher_rounds;
  symmetric_CFB state;
  int direction;
} *Crypt__Mode__CFB;

typedef struct ctr_struct {             /* used by Crypt::Mode::CTR */
  int cipher_id, cipher_rounds;
  int ctr_mode_param;
  symmetric_CTR state;
  int direction;
} *Crypt__Mode__CTR;

typedef struct f8_struct {              /* used by Crypt::Mode::F8 */
  int cipher_id, cipher_rounds;
  symmetric_F8 state;
  int direction;
} *Crypt__Mode__F8;

typedef struct lrw_struct {             /* used by Crypt::Mode::LRW */
  int cipher_id, cipher_rounds;
  symmetric_LRW state;
  int direction;
} *Crypt__Mode__LRW;

typedef struct ofb_struct {             /* used by Crypt::Mode::OFB */
  int cipher_id, cipher_rounds;
  symmetric_OFB state;
  int direction;



( run in 0.810 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )