예제 #1
0
def test_spkilib():
    """Test based on spki examples draft

    The base64 encoded s-expressions form the draft are include in
    test/sexps.
    """
    from pisces.spkilib import sexp
    
    chunks = []
    chunk = []
    for line in fileinput.input('test/sexps'):
        if line.strip():
            chunk.append(line)
        else:
            chunks.append("\n".join(chunk))
            chunk = []
    chunks.append("\n".join(chunk))
    consts = eval(open("test/sexps.py").read())
    assert len(consts) == len(chunks), \
           "pisces.spkilib: error loading spkilib tests"
    for i in range(len(consts)):
        chunk = chunks[i]
        const = consts[i]
        sx1 = sexp.parse(chunk)
        sx2 = sexp.construct_seq(_cleanup(const))
        assert sx1 == sx2, \
               "pisces.spkilib: #%d: parsed s-exp differs " \
               "from constructed s-exp" % i
        enc1 = sx1.encode_canonical()
        enc2 = sx1.encode_base64()
        sx11 = sexp.parse(enc1)
        sx12 = sexp.parse(enc2)
        assert sx11 == sx12, "pisces.spkilib: s-exp parsing failed"
        assert sx11 == sx1, "pisces.spkilib: s-exp parsing failed"
        buf = str(sx1)
        if '\n' in buf:
            continue # parseText doesn't handle multi-line base64 data
        sx3 = sexp.parseText(buf)
        assert sx1 == sx3, "pisces.spkilib: parseText failed"
예제 #2
0
    def sexp(self):
	return parse(['ciphered-data', self.data])
예제 #3
0
 def sexp(self):
     return parse(['random', str(self.t), self.rand])
예제 #4
0
 def sexp(self):
     return parse(['error', self.msg])
예제 #5
0
    def sexp(self):
	return parse(['data', self.data, self.mac]) 
예제 #6
0
    def sexp(self):
	return parse(['finished', self.verify])
예제 #7
0
 def sexp(self):
     return parse(['close-notify'])
예제 #8
0
 def sexp(self):
     return parse(['client-key-exchange', self.cipher])
예제 #9
0
 def sexp(self):
     return parse(['certificate-verify', self.sig.sexp()])
예제 #10
0
 def sexp(self):
     return parse(['server-hello-done'])
예제 #11
0
 def sexp(self):
     return parse(['pre-master-secret', self.ver, self.rand.sexp()])
예제 #12
0
 def sexp(self):
     return parse(['certificate-request'])
예제 #13
0
 def sexp(self):
     return parse(['certificate', self.certs.sexp()])
예제 #14
0
 def sexp(self):
     return parse(['server-hello', self.ver,
                   object_to_sexp(self.rand), self.sessId])
예제 #15
0
 def sexp(self):
     return parse(['client-hello', self.ver,
                   object_to_sexp(self.rand)]) 
예제 #16
0
def parse(buf):
    return eval(sexp.parse(buf))