Permalink
Browse files

Add Image#encipher, Image#decipher

  • Loading branch information...
1 parent f405c78 commit fcaeb2395ac922584f566402b251f30c2700d1ba rmagick committed Feb 11, 2008
Showing with 92 additions and 6 deletions.
  1. +3 −0 ChangeLog
  2. +1 −0 ext/RMagick/extconf.rb
  3. +3 −1 ext/RMagick/rmagick.h
  4. +79 −1 ext/RMagick/rmimage.c
  5. +4 −2 ext/RMagick/rmmain.c
  6. +2 −2 ext/RMagick/rmutil.c
View
@@ -1,3 +1,6 @@
+RMagick 2.3.0
+ o Added Image#encipher, Image#decipher (available with ImageMagick 6.3.8-6)
+
RMagick 2.2.0
o Added Image#opaque_channel, Image#paint_transparent (available with
ImageMagick 6.3.7-10)
View
@@ -155,6 +155,7 @@ def exit_failure(msg)
"ConvertHSLToRGB", # 6.3.5-9
"ConvertRGBToHSL", # 6.3.5-9
"DistortImage", # 6.3.5
+ "EncipherImage", # 6.3.8-6
"EqualizeImageChannel", # 6.3.6-9
"ExcerptImage", # 6.3.5-8
"ExtentImage", # 6.3.1
View
@@ -1,4 +1,4 @@
-/* $Id: rmagick.h,v 1.223 2008/01/28 22:31:50 rmagick Exp $ */
+/* $Id: rmagick.h,v 1.224 2008/02/11 00:03:47 rmagick Exp $ */
/*=============================================================================
| Copyright (C) 2008 by Timothy P. Hunter
| Name: rmagick.h
@@ -814,6 +814,7 @@ extern VALUE Image_copy(VALUE);
extern VALUE Image_crop(int, VALUE *, VALUE);
extern VALUE Image_crop_bang(int, VALUE *, VALUE);
extern VALUE Image_cycle_colormap(VALUE, VALUE);
+extern VALUE Image_decipher(VALUE, VALUE);
extern VALUE Image_delete_profile(VALUE, VALUE);
extern VALUE Image_despeckle(VALUE);
extern VALUE Image_destroy_bang(VALUE);
@@ -830,6 +831,7 @@ extern VALUE Image_dup(VALUE);
extern VALUE Image_each_profile(VALUE);
extern VALUE Image_edge(int, VALUE *, VALUE);
extern VALUE Image_emboss(int, VALUE *, VALUE);
+extern VALUE Image_encipher(VALUE, VALUE);
extern VALUE Image_enhance(VALUE);
extern VALUE Image_equalize(VALUE);
extern VALUE Image_equalize_channel(int, VALUE *, VALUE);
View
@@ -1,4 +1,4 @@
-/* $Id: rmimage.c,v 1.279 2008/01/28 22:31:50 rmagick Exp $ */
+/* $Id: rmimage.c,v 1.280 2008/02/11 00:03:47 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2008 by Timothy P. Hunter
| Name: rmimage.c
@@ -3178,6 +3178,45 @@ Image_depth(VALUE self)
}
+/*
+ Method: Image#decipher(passphrase)
+ Purpose: call DecipherImage
+*/
+VALUE
+Image_decipher(VALUE self, VALUE passphrase)
+{
+#if defined(HAVE_ENCIPHERIMAGE)
+ Image *image, *new_image;
+ char *pf;
+ ExceptionInfo exception;
+ MagickBooleanType okay;
+
+ image = rm_check_destroyed(self);
+ pf = StringValuePtr(passphrase); // ensure passphrase is a string
+ GetExceptionInfo(&exception);
+
+ new_image = rm_clone_image(image);
+
+ okay = DecipherImage(new_image, pf, &exception);
+ rm_check_exception(&exception, new_image, DestroyOnError);
+ if (!okay)
+ {
+ new_image = DestroyImage(new_image);
+ rb_raise(rb_eRuntimeError, "DecipherImage failed for unknown reason.");
+ }
+
+ DestroyExceptionInfo(&exception);
+
+ return rm_image_new(new_image);
+#else
+ self = self;
+ passphrase = passphrase;
+ rm_not_implemented();
+ return (VALUE)0;
+#endif
+}
+
+
DEF_ATTR_ACCESSOR(Image, delay, ulong)
@@ -3838,6 +3877,45 @@ Image_emboss(int argc, VALUE *argv, VALUE self)
}
+/*
+ Method: Image#encipher(passphrase)
+ Purpose: call EncipherImage
+*/
+VALUE
+Image_encipher(VALUE self, VALUE passphrase)
+{
+#if defined(HAVE_ENCIPHERIMAGE)
+ Image *image, *new_image;
+ char *pf;
+ ExceptionInfo exception;
+ MagickBooleanType okay;
+
+ image = rm_check_destroyed(self);
+ pf = StringValuePtr(passphrase); // ensure passphrase is a string
+ GetExceptionInfo(&exception);
+
+ new_image = rm_clone_image(image);
+
+ okay = EncipherImage(new_image, pf, &exception);
+ rm_check_exception(&exception, new_image, DestroyOnError);
+ if (!okay)
+ {
+ new_image = DestroyImage(new_image);
+ rb_raise(rb_eRuntimeError, "EncipherImage failed for unknown reason.");
+ }
+
+ DestroyExceptionInfo(&exception);
+
+ return rm_image_new(new_image);
+#else
+ self = self;
+ passphrase = passphrase;
+ rm_not_implemented();
+ return (VALUE)0;
+#endif
+}
+
+
/*
Method: Image#endian
View
@@ -1,4 +1,4 @@
-/* $Id: rmmain.c,v 1.236 2008/01/28 22:31:50 rmagick Exp $ */
+/* $Id: rmmain.c,v 1.237 2008/02/11 00:03:47 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2008 by Timothy P. Hunter
| Name: rmmain.c
@@ -519,6 +519,7 @@ Init_RMagick2(void)
rb_define_method(Class_Image, "crop", Image_crop, -1);
rb_define_method(Class_Image, "crop!", Image_crop_bang, -1);
rb_define_method(Class_Image, "cycle_colormap", Image_cycle_colormap, 1);
+ rb_define_method(Class_Image, "decipher", Image_decipher, 1);
rb_define_method(Class_Image, "delete_profile", Image_delete_profile, 1);
rb_define_method(Class_Image, "despeckle", Image_despeckle, 0);
rb_define_method(Class_Image, "destroy!", Image_destroy_bang, 0);
@@ -535,6 +536,7 @@ Init_RMagick2(void)
rb_define_method(Class_Image, "each_profile", Image_each_profile, 0);
rb_define_method(Class_Image, "edge", Image_edge, -1);
rb_define_method(Class_Image, "emboss", Image_emboss, -1);
+ rb_define_method(Class_Image, "encipher", Image_encipher, 1);
rb_define_method(Class_Image, "enhance", Image_enhance, 0);
rb_define_method(Class_Image, "equalize", Image_equalize, 0);
rb_define_method(Class_Image, "equalize_channel", Image_equalize_channel, -1);
@@ -1687,7 +1689,7 @@ static void version_constants(void)
rb_define_const(Module_Magick, "Version", str);
sprintf(long_version,
- "This is %s ($Date: 2008/01/28 22:31:50 $) Copyright (C) 2008 by Timothy P. Hunter\n"
+ "This is %s ($Date: 2008/02/11 00:03:47 $) Copyright (C) 2008 by Timothy P. Hunter\n"
"Built with %s\n"
"Built for %s\n"
"Web page: http://rmagick.rubyforge.org\n"
View
@@ -1,4 +1,4 @@
-/* $Id: rmutil.c,v 1.146 2008/01/20 17:29:42 rmagick Exp $ */
+/* $Id: rmutil.c,v 1.147 2008/02/11 00:03:47 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2008 by Timothy P. Hunter
| Name: rmutil.c
@@ -229,7 +229,7 @@ rm_no_freeze(VALUE obj)
/*
Extern: rm_str2cstr(str, &len);
- Purpose: Supply our own version of the "obsolete" rm_str2cstr.
+ Purpose: Supply our own version of the "obsolete" rb_str2cstr.
*/
char *
rm_str2cstr(VALUE str, long *len)

0 comments on commit fcaeb23

Please sign in to comment.