'Returns the key length to pass to the cipher/kdf. The PKCS#5 spec does
not specify a way to store the RC5 key length, however this tends not
to be a problem since OpenSSL does not support RC5 in PKCS#8 and OS X
does not provide an RC5 cipher for use in the Security Transforms
library.
:raises:
ValueError - when the key length can not be determined
:return:
An integer representing the length in bytes'

@property
def key_length(self):

    encryption_algo = self[u'algorithm'].native
    if (encryption_algo[0:3] == u'aes'):
        return {u'aes128_': 16, u'aes192_': 24, u'aes256_': 32}[encryption_algo[0:7]]
    cipher_lengths = {u'des': 8, u'tripledes_3key': 24}
    if (encryption_algo in cipher_lengths):
        return cipher_lengths[encryption_algo]
    if (encryption_algo == u'rc2'):
        rc2_params = self[u'parameters'].parsed[u'encryption_scheme'][u'parameters'].parsed
        rc2_parameter_version = rc2_params[u'rc2_parameter_version'].native
        encoded_key_bits_map = {160: 5, 120: 8, 58: 16}
        if (rc2_parameter_version in encoded_key_bits_map):
            return encoded_key_bits_map[rc2_parameter_version]
        if (rc2_parameter_version >= 256):
            return rc2_parameter_version
        if (rc2_parameter_version is None):
            return 4
        raise ValueError(unwrap(u'\n                                                                Invalid    RC2    parameter    version    found    in    EncryptionAlgorithm\n                                                                parameters\n                                                                '))
    if (encryption_algo == u'pbes2'):
        key_length = self[u'parameters'][u'key_derivation_func'][u'parameters'][u'key_length'].native
        if (key_length is not None):
            return key_length
        return self[u'parameters'][u'encryption_scheme'].key_length
    if (encryption_algo.find(u'.') == (-1)):
        return {u'pbes1_md2_des': 8, u'pbes1_md5_des': 8, u'pbes1_md2_rc2': 8, u'pbes1_md5_rc2': 8, u'pbes1_sha1_des': 8, u'pbes1_sha1_rc2': 8, u'pkcs12_sha1_rc4_128': 16, u'pkcs12_sha1_rc4_40': 5, u'pkcs12_sha1_tripledes_3key': 24, u'pkcs12_sha1_tripledes_2key': 16, u'pkcs12_sha1_rc2_128': 16, u'pkcs12_sha1_rc2_40': 5}[encryption_algo]
    raise ValueError(unwrap(u'\n                                                Unrecognized    encryption    algorithm    "%s"\n                                                ', encryption_algo))
