##// END OF EJS Templates
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)

File last commit:

r836:9ee107b9 decentral
r836:9ee107b9 decentral
Show More
signature.py
67 lines | 2.0 KiB | text/x-python | PythonLexer
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827 import xml.etree.ElementTree as et
neko259
Added signature model. Use signatures in posts
r820 from django.db import models
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827 ATTR_KEY = 'key'
ATTR_KEY_TYPE = 'type'
ATTR_LOCAL_ID = 'local-id'
neko259
Added signature model. Use signatures in posts
r820 class GlobalId(models.Model):
class Meta:
app_label = 'boards'
def __init__(self, *args, **kwargs):
models.Model.__init__(self, *args, **kwargs)
if 'key' in kwargs and 'key_type' in kwargs and 'local_id' in kwargs:
self.key = kwargs['key']
self.key_type = kwargs['key_type']
self.local_id = kwargs['local_id']
key = models.TextField()
key_type = models.TextField()
local_id = models.IntegerField()
def __str__(self):
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 return '%s | %s | %d' % (self.key_type, self.key, self.local_id)
neko259
Added signature model. Use signatures in posts
r820
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 def to_xml_element(self, element: et.Element):
neko259
Generate GET request and response (not full yet). Add global id to the posts...
r827 """
Exports global id to an XML element.
"""
element.set(ATTR_KEY, self.key)
element.set(ATTR_KEY_TYPE, self.key_type)
element.set(ATTR_LOCAL_ID, str(self.local_id))
neko259
Added GET request handler, command for key generation. Changed KeyPair format for ecdsa (use to_string instead of to_pem because it's shorter)
r836 @staticmethod
def from_xml_element(element: et.Element, existing=False):
"""
Parses XML id tag and gets global id from it.
Arguments:
element -- the XML 'id' element
existing -- if this is False, a new instance of GlobalId will be
created. Otherwise, we will search for an existing GlobalId instance
and throw DoesNotExist if there isn't one.
"""
if existing:
return GlobalId.objects.get(key=element.get(ATTR_KEY),
key_type=element.get(ATTR_KEY_TYPE),
local_id=int(element.get(
ATTR_LOCAL_ID)))
else:
return GlobalId(key=element.get(ATTR_KEY),
key_type=element.get(ATTR_KEY_TYPE),
local_id=int(element.get(ATTR_LOCAL_ID)))
neko259
Added signature model. Use signatures in posts
r820
class Signature(models.Model):
class Meta:
app_label = 'boards'
key_type = models.TextField()
key = models.TextField()
signature = models.TextField()