Module: FB64
- Defined in:
- ext/fb64/fb64.c
Defined Under Namespace
Classes: DecodeError
Class Method Summary collapse
Class Method Details
.decode64(*args) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'ext/fb64/fb64.c', line 29 static VALUE fb64_decode64(int argc, VALUE *argv, VALUE self) { VALUE input; rb_scan_args(argc, argv, "1", &input); if (TYPE(input) != T_STRING) { rb_raise(rb_eTypeError, "expected a String"); } const char* src = StringValueCStr(input); size_t srclen = RSTRING_LEN( (VALUE)input); size_t outlen = ((srclen * 3) / 4) + 1; char out[outlen]; int result; result = base64_decode(src, srclen, out, &outlen, 0); if (result != 1) { rb_raise(e_DecodeError, "Error during decode"); } return rb_utf8_str_new(out, outlen); } |
.encode64(*args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'ext/fb64/fb64.c', line 9 static VALUE fb64_encode64(int argc, VALUE* argv, VALUE self) { VALUE input; rb_scan_args(argc, argv, "1", &input); if (TYPE(input) != T_STRING) { rb_raise(rb_eTypeError, "expected a String"); } const char* src = StringValueCStr(input); size_t srclen = RSTRING_LEN( (VALUE)input); size_t outlen = ((srclen * 4) / 3) + 1; char out[outlen]; base64_encode(src, srclen, out, &outlen, 0); return rb_utf8_str_new(out, outlen); } |