110
110
def parse(self, policy):
111
111
"""Read key policy information from the provided <Policy> tree."""
112
from pskc.parse import g_e_v, g_e_i, g_e_d, namespaces
112
from pskc.parse import (
113
find, findall, findtext, findint, findtime, getint)
113
114
if policy is None:
116
self.start_date = g_e_d(policy, 'pskc:StartDate')
117
self.expiry_date = g_e_d(policy, 'pskc:ExpiryDate')
118
self.number_of_transactions = g_e_i(
117
self.start_date = findtime(policy, 'pskc:StartDate')
118
self.expiry_date = findtime(policy, 'pskc:ExpiryDate')
119
self.number_of_transactions = findint(
119
120
policy, 'pskc:NumberOfTransactions')
120
for key_usage in policy.findall(
121
'pskc:KeyUsage', namespaces=namespaces):
122
self.key_usage.append(g_e_v(key_usage, '.'))
121
for key_usage in findall(policy, 'pskc:KeyUsage'):
122
self.key_usage.append(findtext(key_usage, '.'))
124
pin_policy = policy.find(
125
'pskc:PINPolicy', namespaces=namespaces)
124
pin_policy = find(policy, 'pskc:PINPolicy')
126
125
if pin_policy is not None:
127
self.pin_key_id = pin_policy.attrib.get('PINKeyId')
128
self.pin_usage = pin_policy.attrib.get('PINUsageMode')
129
v = pin_policy.attrib.get('MaxFailedAttempts')
131
self.pin_max_failed_attemtps = int(v)
132
v = pin_policy.attrib.get('MinLength')
134
self.pin_min_length = int(v)
135
v = pin_policy.attrib.get('MaxLength')
137
self.pin_max_length = int(v)
138
self.pin_encoding = pin_policy.attrib.get('PINEncoding')
126
self.pin_key_id = pin_policy.get('PINKeyId')
127
self.pin_usage = pin_policy.get('PINUsageMode')
128
self.pin_max_failed_attemtps = getint(
129
pin_policy, 'MaxFailedAttempts')
130
self.pin_min_length = getint(pin_policy, 'MinLength')
131
self.pin_max_length = getint(pin_policy, 'MaxLength')
132
self.pin_encoding = pin_policy.get('PINEncoding')
139
133
# TODO: check if there are any other attributes set for PINPolicy
140
134
# of if there are any children and set unknown_policy_elementss