nokogiri-xmlsec 0.0.3 → 0.0.4

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: 5ce9aa5774cf601b1d61c7a91d1a40b54ccc1707
4
- data.tar.gz: 09ddf766c88fd311c714f1d64f20ba8c2be1de55
3
+ metadata.gz: 071248ba595e25283ee6987fb5ac39a111a86eab
4
+ data.tar.gz: 48e03d326c3b0b65e4dc4980c9a59836591c3d9a
5
5
  SHA512:
6
- metadata.gz: 8dc8f5fb6f6523d39572a633e91b1948dc4fb3b956082e50919dbfb06565872b2d26ac3ffce27aa3a3cf79fe5e264235ecb25900e9ef3b4169a31687848bed30
7
- data.tar.gz: de1fb73e0f83c43c9f4f1de2afcc13f7b65a7b41dedacc727b37341ea325f54e03f7764ced670e1c946bcbcb51994edce0dadf2e398bd03661a09362f6731f76
6
+ metadata.gz: 5ba83c44cd6e92e403639d093cec53678bf2ffc3afaa284b8cbfd7a5da752ee81b0b140e41f83408fc4e07166ec783a2badbfa5841adab9a0789a734ea211ced
7
+ data.tar.gz: 697783269c10f6114b47af84e124b58ed7ff746f79ce86d2429c5b7e9268e8eece8273679b646a0438e2b5b49d28fa8d267a5616ac67eaa9c95d939744d5823a
@@ -0,0 +1,43 @@
1
+ #include "xmlsecrb.h"
2
+
3
+ VALUE set_id_attribute(VALUE self, VALUE rb_attr_name) {
4
+ xmlNodePtr node;
5
+ xmlAttrPtr attr;
6
+ xmlAttrPtr tmp;
7
+ xmlChar *name;
8
+ const xmlChar *idName;
9
+
10
+ Data_Get_Struct(self, xmlNode, node);
11
+ Check_Type(rb_attr_name, T_STRING);
12
+ idName = (const xmlChar *)RSTRING_PTR(rb_attr_name);
13
+
14
+ // find pointer to id attribute
15
+ attr = xmlHasProp(node, idName);
16
+ if((attr == NULL) || (attr->children == NULL)) {
17
+ rb_raise(rb_eRuntimeError, "Can't find attribute to add register as id");
18
+ return Qfalse;
19
+ }
20
+
21
+ // get the attribute (id) value
22
+ name = xmlNodeListGetString(node->doc, attr->children, 1);
23
+ if(name == NULL) {
24
+ rb_raise(rb_eRuntimeError, "Attribute %s has no value", idName);
25
+ return Qfalse;
26
+ }
27
+
28
+ // check that we don't have that id already registered
29
+ tmp = xmlGetID(node->doc, name);
30
+ if(tmp != NULL) {
31
+ // rb_raise(rb_eRuntimeError, "Attribute %s is already an ID", idName);
32
+ xmlFree(name);
33
+ return Qfalse;
34
+ }
35
+
36
+ // finally register id
37
+ xmlAddID(NULL, node->doc, name, attr);
38
+
39
+ // and do not forget to cleanup
40
+ xmlFree(name);
41
+
42
+ return Qtrue;
43
+ }
@@ -1,6 +1,7 @@
1
1
  #include "xmlsecrb.h"
2
2
 
3
3
  VALUE rb_cNokogiri_XML_Document = T_NIL;
4
+ VALUE rb_cNokogiri_XML_Node = T_NIL;
4
5
  VALUE rb_eSigningError = T_NIL;
5
6
  VALUE rb_eVerificationError = T_NIL;
6
7
  VALUE rb_eKeystoreError = T_NIL;
@@ -12,6 +13,7 @@ void Init_Nokogiri_ext() {
12
13
  VALUE Nokogiri = rb_define_module("Nokogiri");
13
14
  VALUE Nokogiri_XML = rb_define_module_under(Nokogiri, "XML");
14
15
  rb_cNokogiri_XML_Document = rb_const_get(Nokogiri_XML, rb_intern("Document"));
16
+ rb_cNokogiri_XML_Node = rb_const_get(Nokogiri_XML, rb_intern("Node"));
15
17
 
16
18
  rb_define_method(rb_cNokogiri_XML_Document, "sign_with_key", sign_with_key, 2);
17
19
  rb_define_method(rb_cNokogiri_XML_Document, "sign_with_certificate", sign_with_certificate, 3);
@@ -20,6 +22,7 @@ void Init_Nokogiri_ext() {
20
22
  rb_define_method(rb_cNokogiri_XML_Document, "verify_with_certificates", verify_signature_with_certificates, 1);
21
23
  rb_define_method(rb_cNokogiri_XML_Document, "encrypt_with_key", encrypt_with_key, 2);
22
24
  rb_define_method(rb_cNokogiri_XML_Document, "decrypt_with_key", decrypt_with_key, 2);
25
+ rb_define_method(rb_cNokogiri_XML_Node, "set_id_attribute", set_id_attribute, 1);
23
26
 
24
27
  rb_eSigningError = rb_define_class_under(XMLSec, "SigningError", rb_eRuntimeError);
25
28
  rb_eVerificationError = rb_define_class_under(XMLSec, "VerificationError", rb_eRuntimeError);
@@ -75,7 +75,7 @@ VALUE verify_signature_with_certificates(VALUE self, VALUE rb_certs) {
75
75
 
76
76
  // verify signature
77
77
  if(xmlSecDSigCtxVerify(dsigCtx, node) < 0) {
78
- rb_raise(rb_eVerificationError, "signature could not be verified");
78
+ rb_raise(rb_eVerificationError, "error occurred during signature verification");
79
79
  goto done;
80
80
  }
81
81
 
@@ -25,6 +25,7 @@ VALUE verify_signature_with_named_keys(VALUE self, VALUE rb_keys);
25
25
  VALUE verify_signature_with_certificates(VALUE self, VALUE rb_certs);
26
26
  VALUE encrypt_with_key(VALUE self, VALUE rb_key_name, VALUE rb_key);
27
27
  VALUE decrypt_with_key(VALUE self, VALUE rb_key_name, VALUE rb_key);
28
+ VALUE set_id_attribute(VALUE self, VALUE rb_attr_name);
28
29
 
29
30
  void Init_Nokogiri_ext(void);
30
31
 
@@ -87,7 +87,7 @@ class Nokogiri::XML::Document
87
87
  if opts[:key]
88
88
  encrypt_with_key opts[:name].to_s, opts[:key]
89
89
  else
90
- raise "private :key is required for encryption"
90
+ raise "public :key is required for encryption"
91
91
  end
92
92
  self
93
93
  end
@@ -1,3 +1,3 @@
1
1
  module Xmlsec
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokogiri-xmlsec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin MacKenzie IV
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-28 00:00:00.000000000 Z
11
+ date: 2013-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -132,6 +132,7 @@ files:
132
132
  - ext/nokogiri_ext_xmlsec/init.c
133
133
  - ext/nokogiri_ext_xmlsec/nokogiri_decrypt_with_key.c
134
134
  - ext/nokogiri_ext_xmlsec/nokogiri_encrypt_with_key.c
135
+ - ext/nokogiri_ext_xmlsec/nokogiri_helpers_set_attribute_id.c
135
136
  - ext/nokogiri_ext_xmlsec/nokogiri_init.c
136
137
  - ext/nokogiri_ext_xmlsec/nokogiri_sign_certificate.c
137
138
  - ext/nokogiri_ext_xmlsec/nokogiri_sign_rsa.c