forked from xmlsec/python-xmlsec
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.pyx
More file actions
152 lines (100 loc) · 4.26 KB
/
template.pyx
File metadata and controls
152 lines (100 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals, division
from lxml.includes.etreepublic cimport import_lxml__etree
import_lxml__etree()
from lxml.includes.etreepublic cimport _Element, elementFactory
from lxml.includes.tree cimport const_xmlChar, xmlNode, xmlStrdup
from .constants cimport _Transform
from .utils cimport *
from .template cimport *
def create(_Element node not None,
_Transform c14n_method not None,
_Transform sign_method not None,
name=None,
ns=None):
cdef xmlNode* c_node
cdef const_xmlChar* c_name = _b(name)
cdef const_xmlChar* c_ns = _b(ns)
c_node = xmlSecTmplSignatureCreateNsPref(
node._doc._c_doc, c14n_method.target, sign_method.target, c_name, c_ns)
return elementFactory(node._doc, c_node)
def add_reference(_Element node not None,
_Transform digest_method not None,
id=None, uri=None, type=None):
cdef xmlNode* c_node
cdef const_xmlChar* c_id = _b(id)
cdef const_xmlChar* c_uri = _b(uri)
cdef const_xmlChar* c_type = _b(type)
c_node = xmlSecTmplSignatureAddReference(
node._c_node, digest_method.target, c_id, c_uri, c_type)
return elementFactory(node._doc, c_node)
def add_transform(_Element node not None, _Transform transform not None):
cdef xmlNode* c_node
c_node = xmlSecTmplReferenceAddTransform(
node._c_node, transform.target)
return elementFactory(node._doc, c_node)
def ensure_key_info(_Element node not None, id=None):
cdef xmlNode* c_node
cdef const_xmlChar* c_id = _b(id)
c_node = xmlSecTmplSignatureEnsureKeyInfo(node._c_node, c_id)
return elementFactory(node._doc, c_node)
def add_key_name(_Element node not None, name=None):
cdef xmlNode* c_node
cdef const_xmlChar* c_name = _b(name)
c_node = xmlSecTmplKeyInfoAddKeyName(node._c_node, c_name)
return elementFactory(node._doc, c_node)
def add_key_value(_Element node not None):
cdef xmlNode* c_node
c_node = xmlSecTmplKeyInfoAddKeyValue(node._c_node)
return elementFactory(node._doc, c_node)
def add_x509_data(_Element node not None):
cdef xmlNode* c_node
c_node = xmlSecTmplKeyInfoAddX509Data(node._c_node)
return elementFactory(node._doc, c_node)
def add_encrypted_key(_Element node not None,
_Transform method not None,
id=None,
type=None,
recipient=None):
"""Adds <enc:EncryptedKey/> node with given attributes to the <dsig:KeyInfo/> node keyInfoNode.
"""
cdef xmlNode* c_node
cdef const_xmlChar* c_id = _b(id)
cdef const_xmlChar* c_type = _b(type)
cdef const_xmlChar* c_recipient = _b(recipient)
c_node = xmlSecTmplKeyInfoAddEncryptedKey(node._c_node, method.target, c_id, c_type, c_recipient)
return elementFactory(node._doc, c_node)
def encrypted_data_create(_Element node not None,
_Transform method not None,
id=None,
type=None,
mime_type=None,
encoding=None,
ns=None):
"""
Creates new <{ns}:EncryptedData /> node for encryption template.
"""
cdef xmlNode* c_node
cdef const_xmlChar* c_id = _b(id)
cdef const_xmlChar* c_type = _b(type)
cdef const_xmlChar* c_mtype = _b(mime_type)
cdef const_xmlChar* c_encoding = _b(encoding)
c_node = xmlSecTmplEncDataCreate(
node._doc._c_doc, method.target, c_id, c_type, c_mtype, c_encoding)
if ns is not None:
c_node.ns.prefix = xmlStrdup(_b(ns))
return elementFactory(node._doc, c_node)
def encrypted_data_ensure_key_info(_Element node not None, id=None, ns=None):
"""
Adds <{ns}:KeyInfo/> to the <enc:EncryptedData/> node encNode.
"""
cdef xmlNode* c_node
cdef const_xmlChar* c_id = _b(id)
c_node = xmlSecTmplEncDataEnsureKeyInfo(node._c_node, c_id)
if ns is not None:
c_node.ns.prefix = xmlStrdup(_b(ns))
return elementFactory(node._doc, c_node)
def encrypted_data_ensure_cipher_value(_Element node not None):
cdef xmlNode* c_node
c_node = xmlSecTmplEncDataEnsureCipherValue(node._c_node)
return elementFactory(node._doc, c_node)