예제 #1
0
def readPubKeyFromCache(_keyHash):
	path = Path.certificates(_keyHash)
	if not os.path.isfile(path) : return ''
	with open(path, 'rb') as f :
		str_ = f.read()
	(head, sep, tail) = str_.partition('\n-----END PUBLIC KEY-----')
	return ''.join((head, sep)).encode('utf-8')
예제 #2
0
def saveContactPolicy(idx, fileName):
	path = Path.certificates(fileName)
	if not os.path.isfile(path) : return ''
	with open(path, 'rb') as f :
		str_ = f.read()
	(head, sep, tail) = str_.partition('\n-----END PUBLIC KEY-----\n')
	with open(path, 'wb') as f :
		str_ = ''.join((head, sep, str(idx)))
		f.write(str_)
예제 #3
0
def readCashPolicy(str_, policy):
	fileName = hashKey(str_)
	path_ = Path.certificates(fileName)
	if os.path.isfile(path_) :
		with open(path_, 'rb') as f :
			data = f.read()
		chunks = data.split()
		policy = int(chunks[len(chunks) - 1])
	return policy
예제 #4
0
def addToCertCache(str_, policy):
	fileName = hashKey(str_)
	path_ = Path.certificates(fileName)
	if not os.path.isfile(path_) :
		with open(path_, 'wb') as f :
			f.write(''.join((str_.encode('utf-8'), str(policy))))
	else :
		with open(path_, 'rb') as f :
			data = f.read()
		chunks = data.split()
		policy = int(chunks[len(chunks) - 1])
	return policy