Package keyczar :: Module util
[hide private]
[frames] | no frames]

Module util

source code

Utility functions for keyczar package.


Author: arkajit.dey@gmail.com (Arkajit Dey)

Functions [hide private]
 
ASN1Sequence(*vals) source code
 
ParseASN1Sequence(seq) source code
 
ParsePkcs8(pkcs8) source code
 
ExportRsaPkcs8(params) source code
 
ExportDsaPkcs8(params) source code
 
ParseX509(x509) source code
 
ExportRsaX509(params) source code
 
ExportDsaX509(params) source code
string
MakeDsaSig(r, s)
Given the raw parameters of a DSA signature, return a Base64 signature.
source code
tuple
ParseDsaSig(sig)
Given a raw byte string, return tuple of DSA signature parameters.
source code
 
MakeEmsaMessage(msg, modulus_size)
Algorithm EMSA_PKCS1-v1_5 from PKCS 1 version 2
source code
 
BinToBytes(bits)
Convert bit string to byte string.
source code
 
BytesToBin(bytes)
Convert byte string to bit string.
source code
 
_PadByte(bits)
Pad a string of bits with zeros to make its length a multiple of 8.
source code
 
IntToBin(n) source code
 
BigIntToBytes(n)
Return a big-endian byte string representation of an arbitrary length n.
source code
 
IntToBytes(n)
Return byte string of 4 big-endian ordered bytes representing n.
source code
 
BytesToInt(bytes) source code
 
Xor(a, b)
Return a ^ b as a byte string where a and b are byte strings.
source code
 
_PadBytes(bytes, n)
Prepend a byte string with n zero bytes.
source code
 
_TrimBytes(bytes)
Trim leading zero bytes.
source code
 
RandBytes(n)
Return n random bytes.
source code
 
Hash(*inputs)
Return a SHA-1 hash over a variable number of inputs.
source code
string
Encode(s)
Return Base64 encoding of s.
source code
string
Decode(s)
Return decoded version of given Base64 string.
source code
 
WriteFile(data, loc)
Writes data to file at given location.
source code
string
ReadFile(loc)
Read data from file at given location.
source code
string
MGF(seed, mlen)
Mask Generation Function (MGF1) with SHA-1 as hash.
source code
Variables [hide private]
  HLEN = 20
  RSA_OID = ObjectIdentifier('1.2.840.113549.1.1.1')
  RSA_PARAMS = ['n', 'e', 'd', 'p', 'q', 'dp', 'dq', 'invq']
  DSA_OID = ObjectIdentifier('1.2.840.10040.4.1')
  DSA_PARAMS = ['p', 'q', 'g']
  SHA1RSA_OID = ObjectIdentifier('1.2.840.113549.1.1.5')
  SHA1_OID = ObjectIdentifier('1.3.14.3.2.26')
Function Details [hide private]

MakeDsaSig(r, s)

source code 

Given the raw parameters of a DSA signature, return a Base64 signature.

Parameters:
  • r (long int) - parameter r of DSA signature
  • s (long int) - parameter s of DSA signature
Returns: string
raw byte string formatted as an ASN.1 sequence of r and s

ParseDsaSig(sig)

source code 

Given a raw byte string, return tuple of DSA signature parameters.

Parameters:
  • sig (string) - byte string of ASN.1 representation
Returns: tuple
parameters r, s as a tuple
Raises:
  • KeyczarErrror - if the DSA signature format is invalid

Encode(s)

source code 

Return Base64 encoding of s. Suppress padding characters (=).

Uses URL-safe alphabet: - replaces +, _ replaces /. Will convert s of type unicode to string type first.

Parameters:
  • s (string) - string to encode as Base64
Returns: string
Base64 representation of s.

Decode(s)

source code 

Return decoded version of given Base64 string. Ignore whitespace.

Uses URL-safe alphabet: - replaces +, _ replaces /. Will convert s of type unicode to string type first.

Parameters:
  • s (string) - Base64 string to decode
Returns: string
original string that was encoded as Base64
Raises:
  • Base64DecodingError - If length of string (ignoring whitespace) is one more than a multiple of four.

WriteFile(data, loc)

source code 

Writes data to file at given location.

Parameters:
  • data (string) - contents to be written to file
  • loc (string) - name of file to write to
Raises:
  • KeyczarError - if unable to write to file because of IOError

ReadFile(loc)

source code 

Read data from file at given location.

Parameters:
  • loc (string) - name of file to read from
Returns: string
contents of the file
Raises:
  • KeyczarError - if unable to read from file because of IOError

MGF(seed, mlen)

source code 

Mask Generation Function (MGF1) with SHA-1 as hash.

Parameters:
  • seed (string) - used to generate mask, a byte string
  • mlen (integer) - desired length of mask
Returns: string
mask, byte string of length mlen
Raises:
  • KeyczarError - if mask length too long, > 2^32 * hash_length