Permalink
Browse files

Adding the C code

  • Loading branch information...
caius committed Aug 24, 2010
1 parent d68036d commit 81ed6c6fe9ca35a8c50cb09b2ee95fb7617a4ffb
Showing with 40 additions and 0 deletions.
  1. +34 −0 ext/c_crypt/c_crypt.c
  2. +6 −0 ext/c_crypt/extconf.rb
View
@@ -0,0 +1,34 @@
+#include <ruby.h>
+#include <crypt.h>
+
+// Define our module constant
+VALUE CCrypt = Qnil;
+
+// Prototype this
+void Init_c_crypt();
+
+// Prototype CCrypt.crypt3
+VALUE method_crypt3();
+
+// Define our module & method
+void Init_c_crypt() {
+ CCrypt = rb_define_module("CCrypt");
+ int arg_count = 2;
+ rb_define_module_function(CCrypt, "crypt3", method_crypt3, arg_count);
+}
+
+// Implement CCrypt.crypt3
+VALUE method_crypt3(VALUE self, VALUE str_arg, VALUE salt_arg) {
+ char* str = RSTRING(str_arg)->ptr;
+ char* salt = RSTRING(salt_arg)->ptr;
+
+// printf("str: %s\n", str);
+// printf("salt: %s\n", salt);
+
+ char *hashed = crypt(str, salt);
+
+// printf("hashed: %s\n", hashed);
+
+ return rb_str_new2(hashed);
+}
+
View
@@ -0,0 +1,6 @@
+require 'mkmf'
+
+dir_config("c_crypt")
+
+create_makefile("c_crypt")
+

0 comments on commit 81ed6c6

Please sign in to comment.