From 7da8c2b70ed47acf59854406ca931d00f3ff9a90 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Wed, 10 Feb 2016 20:21:01 +0300 Subject: [PATCH] mock: Remove unused code https://bugzilla.gnome.org/show_bug.cgi?id=761834 --- libsecret/mock/aes.py | 58 --------------------------------------- libsecret/mock/hkdf.py | 14 +--------- libsecret/mock/service.py | 1 - 3 files changed, 1 insertion(+), 72 deletions(-) diff --git a/libsecret/mock/aes.py b/libsecret/mock/aes.py index 2265fab..79b1459 100644 --- a/libsecret/mock/aes.py +++ b/libsecret/mock/aes.py @@ -11,8 +11,6 @@ # Licensed under the Apache License, Version 2.0 # http://www.apache.org/licenses/ # -import os -import sys import math def append_PKCS7_padding(s): @@ -587,62 +585,6 @@ class AESModeOfOperation(object): return bytes(result) -def encryptData(key, data, mode=AESModeOfOperation.modeOfOperation["CBC"]): - """encrypt `data` using `key` - - `key` should be a string of bytes. - - returned cipher is a string of bytes prepended with the initialization - vector. - - """ - key = map(ord, key) - if mode == AESModeOfOperation.modeOfOperation["CBC"]: - data = append_PKCS7_padding(data) - keysize = len(key) - assert keysize in AES.keySize.values(), 'invalid key size: %s' % keysize - # create a new iv using random data - iv = [ord(i) for i in os.urandom(16)] - moo = AESModeOfOperation() - (mode, length, ciph) = moo.encrypt(data, mode, key, keysize, iv) - # With padding, the original length does not need to be known. It's a bad - # idea to store the original message length. - # prepend the iv. - return ''.join(map(chr, iv)) + ''.join(map(chr, ciph)) - -def decryptData(key, data, mode=AESModeOfOperation.modeOfOperation["CBC"]): - """decrypt `data` using `key` - - `key` should be a string of bytes. - - `data` should have the initialization vector prepended as a string of - ordinal values. - - """ - - key = map(ord, key) - keysize = len(key) - assert keysize in AES.keySize.values(), 'invalid key size: %s' % keysize - # iv is first 16 bytes - iv = map(ord, data[:16]) - data = map(ord, data[16:]) - moo = AESModeOfOperation() - decr = moo.decrypt(data, None, mode, key, keysize, iv) - if mode == AESModeOfOperation.modeOfOperation["CBC"]: - decr = strip_PKCS7_padding(decr) - return decr - -def generateRandomKey(keysize): - """Generates a key from random data of length `keysize`. - - The returned key is a string of bytes. - - """ - if keysize not in (16, 24, 32): - emsg = 'Invalid keysize, %s. Should be one of (16, 24, 32).' - raise ValueError(emsg % keysize) - return os.urandom(keysize) - if __name__ == "__main__": moo = AESModeOfOperation() cleartext = "This is a test!" diff --git a/libsecret/mock/hkdf.py b/libsecret/mock/hkdf.py index 5e8ee9b..4a967eb 100644 --- a/libsecret/mock/hkdf.py +++ b/libsecret/mock/hkdf.py @@ -18,8 +18,6 @@ # system libcryptopp. import hashlib, hmac -import math -from binascii import a2b_hex, b2a_hex class HKDF(object): def __init__(self, ikm, L, salt=None, info=None, digestmod = None): @@ -50,19 +48,9 @@ class HKDF(object): #expand PRK def expand(self): - N = math.ceil(float(self.keylen)/self.hashlen) T = b"" temp = b"" i=0x01 - '''while len(T)<2*self.keylen : - msg = temp - msg += self.info - msg += b2a_hex(chr(i)) - h = hmac.new(self.prk, a2b_hex(msg), self.digest_cons) - temp = b2a_hex(h.digest()) - i += 1 - T += temp - ''' while len(T)