Method: OpenSSL::PKey::DH#to_der

Defined in:
ossl_pkey_dh.c

#to_deraString

Encodes this DH to its DER encoding. Note that any existing per-session public/private keys will not get encoded, just the Diffie-Hellman parameters will be encoded.

Returns:

  • (aString)


318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'ossl_pkey_dh.c', line 318

static VALUE
ossl_dh_to_der(VALUE self)
{
    EVP_PKEY *pkey;
    unsigned char *p;
    long len;
    VALUE str;

    GetPKeyDH(self, pkey);
    if((len = i2d_DHparams(pkey->pkey.dh, NULL)) <= 0)
  ossl_raise(eDHError, NULL);
    str = rb_str_new(0, len);
    p = (unsigned char *)RSTRING_PTR(str);
    if(i2d_DHparams(pkey->pkey.dh, &p) < 0)
  ossl_raise(eDHError, NULL);
    ossl_str_adjust(str, p);

    return str;
}