Class: XXTEA
- Inherits:
-
Object
- Object
- XXTEA
- Defined in:
- lib/xxtea/version.rb,
ext/xxtea/xxtea.c
Constant Summary collapse
- VERSION =
"1.2.0"- PKCS7_4_MIN8 =
ID2SYM(id_pkcs7_4_min8)
- PKCS7_8 =
ID2SYM(id_pkcs7_8)
- LENGTH_WORD_PREFIX =
ID2SYM(id_length_word_prefix)
- LENGTH_WORD_SUFFIX =
ID2SYM(id_length_word_suffix)
Class Method Summary collapse
- .decrypt(*args) ⇒ Object
- .decrypt_hex(*args) ⇒ Object
- .encrypt(*args) ⇒ Object
- .encrypt_hex(*args) ⇒ Object
Instance Method Summary collapse
- #decrypt(data) ⇒ Object
- #decrypt_hex(data) ⇒ Object
- #encrypt(data) ⇒ Object
- #encrypt_hex(data) ⇒ Object
- #initialize(*args) ⇒ Object constructor
- #inspect ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 |
# File 'ext/xxtea/xxtea.c', line 668
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
620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
# File 'ext/xxtea/xxtea.c', line 620
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
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
# File 'ext/xxtea/xxtea.c', line 641
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
605 606 607 608 609 610 611 612 613 614 615 616 617 618 |
# File 'ext/xxtea/xxtea.c', line 605
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
635 636 637 638 639 |
# File 'ext/xxtea/xxtea.c', line 635
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
691 692 693 694 695 696 |
# File 'ext/xxtea/xxtea.c', line 691
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
704 705 706 707 708 709 710 |
# File 'ext/xxtea/xxtea.c', line 704
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
684 685 686 687 688 689 |
# File 'ext/xxtea/xxtea.c', line 684
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
698 699 700 701 702 |
# File 'ext/xxtea/xxtea.c', line 698
static VALUE
xxtea_encrypt_hex(VALUE self, VALUE data)
{
return bytes_to_hex(xxtea_encrypt(self, data));
}
|
#inspect ⇒ Object
712 713 714 715 716 717 718 719 720 721 722 723 |
# File 'ext/xxtea/xxtea.c', line 712
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 == 1 ? "length_word_suffix" :
cipher->padding == 2 ? "length_word_prefix" :
cipher->padding == 4 ? "pkcs7_4_min8" : "pkcs7_8",
cipher->rounds);
}
|