Class: XXTEA

Inherits:
Object
  • Object
show all
Defined in:
lib/xxtea/version.rb,
ext/xxtea/xxtea.c

Constant Summary collapse

VERSION =
"1.1.0"
PKCS7_4_MIN8 =
ID2SYM(id_pkcs7_4_min8)
PKCS7_8 =
ID2SYM(id_pkcs7_8)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object



580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
# File 'ext/xxtea/xxtea.c', line 580

static VALUE
xxtea_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE key, opts;
    xxtea_cipher_t *cipher = xxtea_get(self);
    int padding;
    unsigned int rounds;

    rb_scan_args(argc, argv, "1:", &key, &opts);
    parse_opts(opts, &padding, &rounds);
    require_key(key, cipher->key);
    cipher->padding = padding;
    cipher->rounds = rounds;
    return self;
}

Class Method Details

.decrypt(*args) ⇒ Object



532
533
534
535
536
537
538
539
540
541
542
543
544
545
# File 'ext/xxtea/xxtea.c', line 532

static VALUE
xxtea_s_decrypt(int argc, VALUE *argv, VALUE klass)
{
    VALUE data, key, opts;
    int padding;
    unsigned int rounds;
    char keybuf[16];

    (void)klass;
    rb_scan_args(argc, argv, "2:", &data, &key, &opts);
    parse_opts(opts, &padding, &rounds);
    require_key(key, keybuf);
    return decrypt_impl(data, keybuf, padding, rounds);
}

.decrypt_hex(*args) ⇒ Object



553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# File 'ext/xxtea/xxtea.c', line 553

static VALUE
xxtea_s_decrypt_hex(int argc, VALUE *argv, VALUE klass)
{
    VALUE data, key, opts;
    int padding;
    unsigned int rounds;
    char keybuf[16];
    VALUE raw;

    rb_scan_args(argc, argv, "2:", &data, &key, &opts);
    parse_opts(opts, &padding, &rounds);
    raw = hex_to_bytes(data);
    require_key(key, keybuf);
    return decrypt_impl(raw, keybuf, padding, rounds);
}

.encrypt(*args) ⇒ Object



517
518
519
520
521
522
523
524
525
526
527
528
529
530
# File 'ext/xxtea/xxtea.c', line 517

static VALUE
xxtea_s_encrypt(int argc, VALUE *argv, VALUE klass)
{
    VALUE data, key, opts;
    int padding;
    unsigned int rounds;
    char keybuf[16];

    (void)klass;
    rb_scan_args(argc, argv, "2:", &data, &key, &opts);
    parse_opts(opts, &padding, &rounds);
    require_key(key, keybuf);
    return encrypt_impl(data, keybuf, padding, rounds);
}

.encrypt_hex(*args) ⇒ Object



547
548
549
550
551
# File 'ext/xxtea/xxtea.c', line 547

static VALUE
xxtea_s_encrypt_hex(int argc, VALUE *argv, VALUE klass)
{
    return bytes_to_hex(xxtea_s_encrypt(argc, argv, klass));
}

Instance Method Details

#decrypt(data) ⇒ Object



603
604
605
606
607
608
# File 'ext/xxtea/xxtea.c', line 603

static VALUE
xxtea_decrypt(VALUE self, VALUE data)
{
    xxtea_cipher_t *cipher = xxtea_get(self);
    return decrypt_impl(data, cipher->key, cipher->padding, cipher->rounds);
}

#decrypt_hex(data) ⇒ Object



616
617
618
619
620
621
622
# File 'ext/xxtea/xxtea.c', line 616

static VALUE
xxtea_decrypt_hex(VALUE self, VALUE data)
{
    xxtea_cipher_t *cipher = xxtea_get(self);
    VALUE raw = hex_to_bytes(data);
    return decrypt_impl(raw, cipher->key, cipher->padding, cipher->rounds);
}

#encrypt(data) ⇒ Object



596
597
598
599
600
601
# File 'ext/xxtea/xxtea.c', line 596

static VALUE
xxtea_encrypt(VALUE self, VALUE data)
{
    xxtea_cipher_t *cipher = xxtea_get(self);
    return encrypt_impl(data, cipher->key, cipher->padding, cipher->rounds);
}

#encrypt_hex(data) ⇒ Object



610
611
612
613
614
# File 'ext/xxtea/xxtea.c', line 610

static VALUE
xxtea_encrypt_hex(VALUE self, VALUE data)
{
    return bytes_to_hex(xxtea_encrypt(self, data));
}

#inspectObject



624
625
626
627
628
629
630
631
632
633
# File 'ext/xxtea/xxtea.c', line 624

static VALUE
xxtea_inspect(VALUE self)
{
    xxtea_cipher_t *cipher = xxtea_get(self);
    return rb_sprintf("#<%s:%p padding=%s rounds=%u>",
                      rb_obj_classname(self), (void *)self,
                      cipher->padding == 0 ? "false" :
                      cipher->padding == 4 ? "pkcs7_4_min8" : "pkcs7_8",
                      cipher->rounds);
}