Method: Krypt::ASN1::ASN1Data#encode_to

Defined in:
ext/krypt/core/krypt_asn1.c

#encode_to(io) ⇒ self

  • io: an IO-like object supporting IO#write

Encodes this ASN1Data into a DER-encoded String value by writing the contents to an IO-like object. Newly created ASN1Data are DER-encoded except for the possibility of infinite length encodings. If a value with BER encoding was parsed and is not modified, the BER encoding will be preserved when encoding it again.

Returns:

  • (self)


967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
# File 'ext/krypt/core/krypt_asn1.c', line 967

static VALUE
krypt_asn1_data_encode_to(VALUE self, VALUE io)
{
    binyo_outstream *out;
    krypt_asn1_data *data;
    int result;

    int_asn1_data_get(self, data);

    out = binyo_outstream_new_value(io);
    result = int_asn1_encode_to(out, data, self);
    binyo_outstream_free(out);
    if (result == KRYPT_ERR)
  krypt_error_raise(eKryptASN1Error, "Error while encoding value");
    return self;
}