1
1
#include "mruby.h"
2
- #include <stdio.h>
3
- #include <string.h>
4
- #include "mruby/array.h"
5
- #include "mruby/class.h"
6
2
#include "mruby/data.h"
7
- #include "mruby/string.h"
8
- #include "mruby/variable.h"
3
+ #include "polarssl/entropy.h"
9
4
10
- #include <err.h>
5
+ static void lib_entropy_free (mrb_state * mrb , void * ptr ) {
6
+ entropy_context * entropy = ptr ;
11
7
12
- void mrb_mruby_polarssl_gem_init (mrb_state * mrb ) {
13
- struct RClass * d ;
14
- d = mrb_define_module (mrb , "PolarSSL" );
8
+ if (entropy != NULL ) {
9
+ mrb_free (mrb , entropy );
10
+ }
11
+ }
12
+
13
+ static struct mrb_data_type mrb_entropy_type = { "ENTROPY" , lib_entropy_free };
14
+
15
+ static void entropycheck (mrb_state * mrb , mrb_value self , entropy_context * * entropyp ) {
16
+ entropy_context * entropy ;
17
+
18
+ entropy = (entropy_context * )DATA_PTR (self );
19
+ if (!entropy ) {
20
+ mrb_raise (mrb , E_RUNTIME_ERROR , "no entropy found (BUG?)" );
21
+ }
22
+ if (entropyp ) * entropyp = entropy ;
23
+ }
24
+
25
+ static mrb_value mrb_entropy_gather (mrb_state * mrb , mrb_value self ) {
26
+ entropy_context * entropy ;
27
+
28
+ entropycheck (mrb , self , & entropy );
29
+
30
+ if ( entropy_gather ( entropy ) == 0 ) {
31
+ return mrb_true_value ();
32
+ } else {
33
+ return mrb_false_value ();
34
+ }
15
35
}
16
36
17
- void mrb_mruby_polarssl_gem_final (mrb_state * mrb ) {
37
+ static mrb_value mrb_entropy_init (mrb_state * mrb , mrb_value self ) {
38
+ entropy_context * entropy ;
39
+
40
+ entropy = (entropy_context * )DATA_PTR (self );
41
+ if (entropy ) {
42
+ lib_entropy_free (mrb , entropy );
43
+ }
44
+ DATA_TYPE (self ) = & mrb_entropy_type ;
45
+ DATA_PTR (self ) = NULL ;
46
+
47
+ entropy = (entropy_context * )mrb_malloc (mrb , sizeof (* entropy ));
48
+ DATA_PTR (self ) = entropy ;
49
+ entropy_init (entropy );
50
+ return self ;
51
+ }
52
+
53
+ void mrb_mruby_polarssl_gem_init (mrb_state * mrb ) {
54
+ struct RClass * p , * e ;
18
55
19
- }
56
+ p = mrb_define_module (mrb , "PolarSSL" );
57
+ e = mrb_define_class_under (mrb , p , "Entropy" , mrb -> object_class );
58
+ mrb_define_method (mrb , e , "initialize" , mrb_entropy_init , MRB_ARGS_NONE ());
59
+ mrb_define_method (mrb , e , "gather" , mrb_entropy_gather , MRB_ARGS_NONE ());
60
+ }
61
+
62
+ void mrb_mruby_polarssl_gem_final (mrb_state * mrb ) {
63
+ }
0 commit comments