vacman_controller 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70e83106c486e3e2055b0a10215f1895fceb4e2d
4
- data.tar.gz: 3c57b77c49ac9cbc9b8baeaf0cc350d902abe489
3
+ metadata.gz: 718f0e9098056c9546ccd49309c2aef13b8fd1da
4
+ data.tar.gz: a10a4e19da9752526d224b01440506c3e93244f9
5
5
  SHA512:
6
- metadata.gz: 28a07e0dcce49bf04fd089be86472e35fc2ab5e5ed7fc01f724e6ded8173bde1edbd253d3890b86a2d578e430265b002b5693ad42455af26a25262c7ec7dd67e
7
- data.tar.gz: 7ee6a428246bcee1c417cae5cf0c9ddc5180813efab448b793d7444813b9c737eef6913c0ab4a19ec77b32c5e0e9192d1c146c3dff7e7fbdd8a2305ec3b6a08c
6
+ metadata.gz: 7f54254895c1d350a44bcbbb2dfd327f20429e51b1bc3cec0b7ae7eadf5e8c9e0c2775bc8f6c5f0c4d1f9b89fea7d53bf6b4737a52e53293efe46a5d8093dc09
7
+ data.tar.gz: eb7ebc7004676464142abd4220193f1e05de741925918a418c40ff76fb8d53f45a30a84a48f10c46fa88f50b4a098faeecf20658f9421143f6d0c6d26fc9737e
@@ -18,12 +18,33 @@ static void vacman_raise_error(const char* method, int error_code) {
18
18
  /*
19
19
  * convert a ruby hash to TDigipassBlob structure
20
20
  */
21
+ static VALUE rbhash_get_key(VALUE token, const char *property, int type) {
22
+ VALUE ret = rb_hash_aref(token, rb_str_new2(property));
23
+
24
+ if (ret == Qnil) {
25
+ rb_raise(e_vacmanerror, "invalid token object given: %s property is nil", property);
26
+ return Qnil;
27
+ }
28
+
29
+ if (!RB_TYPE_P(ret, type)) {
30
+ rb_raise(e_vacmanerror, "invalid token object given: %s property is not of the correct type", property);
31
+ return Qnil;
32
+ }
33
+
34
+ return ret;
35
+ }
36
+
21
37
  static void rbhash_to_digipass(VALUE token, TDigipassBlob* dpdata) {
22
- VALUE blob = rb_hash_aref(token, rb_str_new2("blob"));
23
- VALUE serial = rb_hash_aref(token, rb_str_new2("serial"));
24
- VALUE app_name = rb_hash_aref(token, rb_str_new2("app_name"));
25
- VALUE flag1 = rb_hash_aref(token, rb_str_new2("flags1"));
26
- VALUE flag2 = rb_hash_aref(token, rb_str_new2("flags2"));
38
+ if (!RB_TYPE_P(token, T_HASH)) {
39
+ rb_raise(e_vacmanerror, "invalid token object given, requires an hash");
40
+ return;
41
+ }
42
+
43
+ VALUE blob = rbhash_get_key(token, "blob", T_STRING);
44
+ VALUE serial = rbhash_get_key(token, "serial", T_STRING);
45
+ VALUE app_name = rbhash_get_key(token, "app_name", T_STRING);
46
+ VALUE flag1 = rbhash_get_key(token, "flags1", T_FIXNUM);
47
+ VALUE flag2 = rbhash_get_key(token, "flags2", T_FIXNUM);
27
48
 
28
49
  memset(dpdata, 0, sizeof(*dpdata));
29
50
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vacman_controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcus Lankenau