Module: Krypt::Hex

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

Defined Under Namespace

Classes: HexError

Class Method Summary collapse

Class Method Details

.Krypt::Hex.decode(data) ⇒ String

Decodes a hex-encoded string of data, which need not necessarily be a String, but must allow a conversion with to_str.

Returns:

  • (String)


203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'ext/krypt/core/krypt_hex.c', line 203

static VALUE
krypt_hex_module_decode(VALUE self, VALUE data)
{
    VALUE ret;
    uint8_t *bytes;
    size_t len;

    StringValue(data);
    len = (size_t) RSTRING_LEN((data));
    bytes = (uint8_t *) RSTRING_PTR((data));
    int_hex_process(bytes, len, KRYPT_HEX_DECODE, ret);
    return ret;
}

.Krypt::Hex.encode(data) ⇒ String

Encodes data, a String, or an object allowing conversion with to_str, in hex encoding.

Returns:

  • (String)


224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'ext/krypt/core/krypt_hex.c', line 224

static VALUE
krypt_hex_module_encode(VALUE self, VALUE data)
{
    VALUE ret;
    uint8_t *bytes;
    size_t len;

    StringValue(data);
    len = (size_t) RSTRING_LEN((data));
    bytes = (uint8_t *) RSTRING_PTR((data));
    int_hex_process(bytes, len, KRYPT_HEX_ENCODE, ret);
    rb_enc_associate(ret, rb_usascii_encoding());
    return ret;
}