Ruby  1.9.3p551(2014-11-13revision48407)
ossl_x509revoked.c
Go to the documentation of this file.
1 /*
2  * $Id: ossl_x509revoked.c 31128 2011-03-19 03:30:59Z akr $
3  * 'OpenSSL for Ruby' project
4  * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
5  * All rights reserved.
6  */
7 /*
8  * This program is licenced under the same licence as Ruby.
9  * (See the file 'LICENCE'.)
10  */
11 #include "ossl.h"
12 
13 #define WrapX509Rev(klass, obj, rev) do { \
14  if (!(rev)) { \
15  ossl_raise(rb_eRuntimeError, "REV wasn't initialized!"); \
16  } \
17  (obj) = Data_Wrap_Struct((klass), 0, X509_REVOKED_free, (rev)); \
18 } while (0)
19 #define GetX509Rev(obj, rev) do { \
20  Data_Get_Struct((obj), X509_REVOKED, (rev)); \
21  if (!(rev)) { \
22  ossl_raise(rb_eRuntimeError, "REV wasn't initialized!"); \
23  } \
24 } while (0)
25 #define SafeGetX509Rev(obj, rev) do { \
26  OSSL_Check_Kind((obj), cX509Rev); \
27  GetX509Rev((obj), (rev)); \
28 } while (0)
29 
30 /*
31  * Classes
32  */
35 
36 /*
37  * PUBLIC
38  */
39 VALUE
40 ossl_x509revoked_new(X509_REVOKED *rev)
41 {
42  X509_REVOKED *new;
43  VALUE obj;
44 
45  if (!rev) {
46  new = X509_REVOKED_new();
47  } else {
48  new = X509_REVOKED_dup(rev);
49  }
50  if (!new) {
52  }
53  WrapX509Rev(cX509Rev, obj, new);
54 
55  return obj;
56 }
57 
58 X509_REVOKED *
60 {
61  X509_REVOKED *rev, *new;
62 
63  SafeGetX509Rev(obj, rev);
64  if (!(new = X509_REVOKED_dup(rev))) {
66  }
67 
68  return new;
69 }
70 
71 /*
72  * PRIVATE
73  */
74 static VALUE
76 {
77  X509_REVOKED *rev;
78  VALUE obj;
79 
80  if (!(rev = X509_REVOKED_new())) {
82  }
83  WrapX509Rev(klass, obj, rev);
84 
85  return obj;
86 }
87 
88 static VALUE
90 {
91  /* EMPTY */
92  return self;
93 }
94 
95 static VALUE
97 {
98  X509_REVOKED *rev;
99 
100  GetX509Rev(self, rev);
101 
102  return asn1integer_to_num(rev->serialNumber);
103 }
104 
105 static VALUE
107 {
108  X509_REVOKED *rev;
109 
110  GetX509Rev(self, rev);
111  rev->serialNumber = num_to_asn1integer(num, rev->serialNumber);
112 
113  return num;
114 }
115 
116 static VALUE
118 {
119  X509_REVOKED *rev;
120 
121  GetX509Rev(self, rev);
122 
123  return asn1time_to_time(rev->revocationDate);
124 }
125 
126 static VALUE
128 {
129  X509_REVOKED *rev;
130  time_t sec;
131 
132  sec = time_to_time_t(time);
133  GetX509Rev(self, rev);
134  if (!X509_time_adj(rev->revocationDate, 0, &sec)) {
136  }
137 
138  return time;
139 }
140 /*
141  * Gets X509v3 extensions as array of X509Ext objects
142  */
143 static VALUE
145 {
146  X509_REVOKED *rev;
147  int count, i;
148  X509_EXTENSION *ext;
149  VALUE ary;
150 
151  GetX509Rev(self, rev);
152  count = X509_REVOKED_get_ext_count(rev);
153  if (count < 0) {
154  OSSL_Debug("count < 0???");
155  return rb_ary_new();
156  }
157  ary = rb_ary_new2(count);
158  for (i=0; i<count; i++) {
159  ext = X509_REVOKED_get_ext(rev, i);
160  rb_ary_push(ary, ossl_x509ext_new(ext));
161  }
162 
163  return ary;
164 }
165 
166 /*
167  * Sets X509_EXTENSIONs
168  */
169 static VALUE
171 {
172  X509_REVOKED *rev;
173  X509_EXTENSION *ext;
174  int i;
175  VALUE item;
176 
177  Check_Type(ary, T_ARRAY);
178  for (i=0; i<RARRAY_LEN(ary); i++) {
180  }
181  GetX509Rev(self, rev);
182  sk_X509_EXTENSION_pop_free(rev->extensions, X509_EXTENSION_free);
183  rev->extensions = NULL;
184  for (i=0; i<RARRAY_LEN(ary); i++) {
185  item = RARRAY_PTR(ary)[i];
186  ext = DupX509ExtPtr(item);
187  if(!X509_REVOKED_add_ext(rev, ext, -1)) {
189  }
190  }
191 
192  return ary;
193 }
194 
195 static VALUE
197 {
198  X509_REVOKED *rev;
199 
200  GetX509Rev(self, rev);
201  if(!X509_REVOKED_add_ext(rev, DupX509ExtPtr(ext), -1)) {
203  }
204 
205  return ext;
206 }
207 
208 /*
209  * INIT
210  */
211 void
213 {
215 
217 
220 
228 }
229 
static VALUE ossl_x509revoked_add_extension(VALUE self, VALUE ext)
RARRAY_PTR(q->result)[0]
void Init_ossl_x509revoked(void)
volatile VALUE ary
Definition: tcltklib.c:9700
static VALUE ossl_x509revoked_get_serial(VALUE self)
int count
Definition: encoding.c:50
static VALUE ossl_x509revoked_set_time(VALUE self, VALUE time)
unsigned long VALUE
Definition: ruby.h:88
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:740
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:515
#define Check_Type(v, t)
Definition: ruby.h:459
static VALUE ossl_x509revoked_initialize(int argc, VALUE *argv, VALUE self)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE cX509Ext
Definition: ossl_x509ext.c:45
#define RARRAY_LEN(ARRAY)
Definition: generator.h:39
VALUE asn1time_to_time(ASN1_TIME *time)
Definition: ossl_asn1.c:32
#define T_ARRAY
Definition: ruby.h:420
X509_EXTENSION * DupX509ExtPtr(VALUE)
Definition: ossl_x509ext.c:82
X509_REVOKED * DupX509RevokedPtr(VALUE)
time_t time_to_time_t(VALUE time)
Definition: ossl_asn1.c:85
#define GetX509Rev(obj, rev)
static VALUE ossl_x509revoked_set_serial(VALUE self, VALUE num)
VALUE cX509Rev
n NULL
Definition: yaml2byte.c:134
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1246
VALUE rb_ary_new(void)
Definition: array.c:339
static VALUE VALUE obj
Definition: tcltklib.c:3147
#define SafeGetX509Rev(obj, rev)
VALUE eOSSLError
Definition: ossl.c:255
VALUE ossl_x509ext_new(X509_EXTENSION *)
Definition: ossl_x509ext.c:53
VALUE * argv
Definition: tcltklib.c:1962
#define X509_REVOKED_dup(rev)
int argc
Definition: tcltklib.c:1961
static VALUE ossl_x509revoked_set_extensions(VALUE self, VALUE ary)
VALUE mX509
Definition: ossl_x509.c:13
VALUE ossl_x509revoked_new(X509_REVOKED *)
#define OSSL_Debug
Definition: ossl.h:205
static VALUE ossl_x509revoked_get_time(VALUE self)
#define OSSL_Check_Kind(obj, klass)
Definition: ossl.h:90
klass
Definition: tcltklib.c:3493
void ossl_raise(VALUE exc, const char *fmt,...)
Definition: ossl.c:324
static VALUE ossl_x509revoked_alloc(VALUE klass)
VALUE eX509RevError
VALUE rb_ary_new2(long capa)
Definition: array.c:332
static VALUE ossl_x509revoked_get_extensions(VALUE self)
VALUE asn1integer_to_num(ASN1_INTEGER *ai)
Definition: ossl_asn1.c:105
ssize_t i
Definition: bigdecimal.c:5519
#define WrapX509Rev(klass, obj, rev)
VALUE time
Definition: tcltklib.c:1857
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1210
ASN1_INTEGER * num_to_asn1integer(VALUE obj, ASN1_INTEGER *ai)
Definition: ossl_asn1.c:157