mirror of
https://github.com/OpenKMIP/PyKMIP.git
synced 2025-07-19 20:14:27 +02:00
Fix flake8 warnings to reflect modern Python style
This commit is contained in:
parent
7648ea801b
commit
c012a430aa
@ -151,44 +151,44 @@ class SecretFactory(object):
|
|||||||
return OpaqueObject()
|
return OpaqueObject()
|
||||||
|
|
||||||
def _build_key_block(self, value):
|
def _build_key_block(self, value):
|
||||||
key_type = value.get('key_format_type')
|
key_type = value.get('key_format_type')
|
||||||
key_compression_type = value.get('key_compression_type')
|
key_compression_type = value.get('key_compression_type')
|
||||||
key_value = value.get('key_value')
|
key_value = value.get('key_value')
|
||||||
cryptographic_algorithm = value.get('cryptographic_algorithm')
|
cryptographic_algorithm = value.get('cryptographic_algorithm')
|
||||||
cryptographic_length = value.get('cryptographic_length')
|
cryptographic_length = value.get('cryptographic_length')
|
||||||
key_wrapping_data = value.get('key_wrapping_data')
|
key_wrapping_data = value.get('key_wrapping_data')
|
||||||
|
|
||||||
key_format_type = KeyFormatType(key_type)
|
key_format_type = KeyFormatType(key_type)
|
||||||
|
|
||||||
key_comp_type = None
|
key_comp_type = None
|
||||||
if key_compression_type is not None:
|
if key_compression_type is not None:
|
||||||
key_comp_type = KeyBlock.KeyCompressionType(
|
key_comp_type = KeyBlock.KeyCompressionType(
|
||||||
key_compression_type)
|
key_compression_type)
|
||||||
|
|
||||||
key_material = KeyMaterial(key_value)
|
key_material = KeyMaterial(key_value)
|
||||||
key_value = KeyValue(key_material)
|
key_value = KeyValue(key_material)
|
||||||
|
|
||||||
crypto_algorithm = None
|
crypto_algorithm = None
|
||||||
if cryptographic_algorithm is not None:
|
if cryptographic_algorithm is not None:
|
||||||
crypto_algorithm = CryptographicAlgorithm(
|
crypto_algorithm = CryptographicAlgorithm(
|
||||||
cryptographic_algorithm
|
cryptographic_algorithm
|
||||||
)
|
)
|
||||||
|
|
||||||
crypto_length = None
|
crypto_length = None
|
||||||
if cryptographic_length is not None:
|
if cryptographic_length is not None:
|
||||||
crypto_length = CryptographicLength(cryptographic_length)
|
crypto_length = CryptographicLength(cryptographic_length)
|
||||||
|
|
||||||
key_wrap_data = None
|
key_wrap_data = None
|
||||||
if key_wrapping_data:
|
if key_wrapping_data:
|
||||||
# TODO (peter-hamilton) This currently isn't used in the tests
|
# TODO (peter-hamilton) This currently isn't used in the tests
|
||||||
# TODO (peter-hamilton) but needs to be updated to properly
|
# TODO (peter-hamilton) but needs to be updated to properly
|
||||||
# TODO (peter-hamilton) create a KeyWrappingData object.
|
# TODO (peter-hamilton) create a KeyWrappingData object.
|
||||||
key_wrap_data = KeyWrappingData(**key_wrapping_data)
|
key_wrap_data = KeyWrappingData(**key_wrapping_data)
|
||||||
|
|
||||||
key_block = KeyBlock(key_format_type,
|
key_block = KeyBlock(key_format_type,
|
||||||
key_comp_type,
|
key_comp_type,
|
||||||
key_value,
|
key_value,
|
||||||
crypto_algorithm,
|
crypto_algorithm,
|
||||||
crypto_length,
|
crypto_length,
|
||||||
key_wrap_data)
|
key_wrap_data)
|
||||||
return key_block
|
return key_block
|
||||||
|
@ -215,7 +215,7 @@ class Integer(Base):
|
|||||||
self.value = unpack(self.pack_string, istream.read(self.length))[0]
|
self.value = unpack(self.pack_string, istream.read(self.length))[0]
|
||||||
pad = unpack(self.pack_string, istream.read(self.padding_length))[0]
|
pad = unpack(self.pack_string, istream.read(self.padding_length))[0]
|
||||||
|
|
||||||
if pad is not 0:
|
if pad != 0:
|
||||||
raise exceptions.ReadValueError(
|
raise exceptions.ReadValueError(
|
||||||
Integer.__name__,
|
Integer.__name__,
|
||||||
'pad',
|
'pad',
|
||||||
@ -595,7 +595,7 @@ class Enumeration(Base):
|
|||||||
pad = unpack('!I', istream.read(Enumeration.LENGTH))[0]
|
pad = unpack('!I', istream.read(Enumeration.LENGTH))[0]
|
||||||
|
|
||||||
# Verify that the padding bytes are zero bytes.
|
# Verify that the padding bytes are zero bytes.
|
||||||
if pad is not 0:
|
if pad != 0:
|
||||||
raise exceptions.InvalidPaddingBytes("padding bytes must be zero")
|
raise exceptions.InvalidPaddingBytes("padding bytes must be zero")
|
||||||
|
|
||||||
self.validate()
|
self.validate()
|
||||||
@ -823,7 +823,7 @@ class TextString(Base):
|
|||||||
if self.padding_length < self.PADDING_SIZE:
|
if self.padding_length < self.PADDING_SIZE:
|
||||||
for _ in range(self.padding_length):
|
for _ in range(self.padding_length):
|
||||||
pad = unpack('!B', istream.read(1))[0]
|
pad = unpack('!B', istream.read(1))[0]
|
||||||
if pad is not 0:
|
if pad != 0:
|
||||||
raise exceptions.ReadValueError(
|
raise exceptions.ReadValueError(
|
||||||
TextString.__name__,
|
TextString.__name__,
|
||||||
'pad',
|
'pad',
|
||||||
@ -918,7 +918,7 @@ class ByteString(Base):
|
|||||||
if self.padding_length < self.PADDING_SIZE:
|
if self.padding_length < self.PADDING_SIZE:
|
||||||
for _ in range(self.padding_length):
|
for _ in range(self.padding_length):
|
||||||
pad = unpack('!B', istream.read(1))[0]
|
pad = unpack('!B', istream.read(1))[0]
|
||||||
if pad is not 0:
|
if pad != 0:
|
||||||
raise exceptions.ReadValueError(
|
raise exceptions.ReadValueError(
|
||||||
TextString.__name__,
|
TextString.__name__,
|
||||||
'pad',
|
'pad',
|
||||||
@ -1058,7 +1058,7 @@ class Interval(Base):
|
|||||||
pad = unpack('!I', istream.read(Interval.LENGTH))[0]
|
pad = unpack('!I', istream.read(Interval.LENGTH))[0]
|
||||||
|
|
||||||
# Verify that the padding bytes are zero bytes.
|
# Verify that the padding bytes are zero bytes.
|
||||||
if pad is not 0:
|
if pad != 0:
|
||||||
raise exceptions.InvalidPaddingBytes("padding bytes must be zero")
|
raise exceptions.InvalidPaddingBytes("padding bytes must be zero")
|
||||||
|
|
||||||
self.validate()
|
self.validate()
|
||||||
|
@ -1559,7 +1559,7 @@ class KmipEngine(object):
|
|||||||
if attribute_name == 'Name':
|
if attribute_name == 'Name':
|
||||||
names = attr
|
names = attr
|
||||||
if attribute_value not in names:
|
if attribute_value not in names:
|
||||||
break
|
break
|
||||||
# TODO: filtering on other attributes
|
# TODO: filtering on other attributes
|
||||||
else:
|
else:
|
||||||
managed_objects_filtered.append(managed_object)
|
managed_objects_filtered.append(managed_object)
|
||||||
@ -2045,12 +2045,12 @@ class KmipEngine(object):
|
|||||||
"for encryption."
|
"for encryption."
|
||||||
)
|
)
|
||||||
|
|
||||||
if enums.CryptographicUsageMask.ENCRYPT not in \
|
masks = managed_object.cryptographic_usage_masks
|
||||||
managed_object.cryptographic_usage_masks:
|
if enums.CryptographicUsageMask.ENCRYPT not in masks:
|
||||||
raise exceptions.PermissionDenied(
|
raise exceptions.PermissionDenied(
|
||||||
"The Encrypt bit must be set in the encryption key's "
|
"The Encrypt bit must be set in the encryption key's "
|
||||||
"cryptographic usage mask."
|
"cryptographic usage mask."
|
||||||
)
|
)
|
||||||
|
|
||||||
result = self._cryptography_engine.encrypt(
|
result = self._cryptography_engine.encrypt(
|
||||||
cryptographic_parameters.cryptographic_algorithm,
|
cryptographic_parameters.cryptographic_algorithm,
|
||||||
@ -2108,12 +2108,12 @@ class KmipEngine(object):
|
|||||||
"for decryption."
|
"for decryption."
|
||||||
)
|
)
|
||||||
|
|
||||||
if enums.CryptographicUsageMask.DECRYPT not in \
|
masks = managed_object.cryptographic_usage_masks
|
||||||
managed_object.cryptographic_usage_masks:
|
if enums.CryptographicUsageMask.DECRYPT not in masks:
|
||||||
raise exceptions.PermissionDenied(
|
raise exceptions.PermissionDenied(
|
||||||
"The Decrypt bit must be set in the decryption key's "
|
"The Decrypt bit must be set in the decryption key's "
|
||||||
"cryptographic usage mask."
|
"cryptographic usage mask."
|
||||||
)
|
)
|
||||||
|
|
||||||
result = self._cryptography_engine.decrypt(
|
result = self._cryptography_engine.decrypt(
|
||||||
cryptographic_parameters.cryptographic_algorithm,
|
cryptographic_parameters.cryptographic_algorithm,
|
||||||
@ -2251,12 +2251,12 @@ class KmipEngine(object):
|
|||||||
"Object is not in a state that can be used for MACing."
|
"Object is not in a state that can be used for MACing."
|
||||||
)
|
)
|
||||||
|
|
||||||
if enums.CryptographicUsageMask.MAC_GENERATE not in \
|
masks = managed_object.cryptographic_usage_masks
|
||||||
managed_object.cryptographic_usage_masks:
|
if enums.CryptographicUsageMask.MAC_GENERATE not in masks:
|
||||||
raise exceptions.PermissionDenied(
|
raise exceptions.PermissionDenied(
|
||||||
"MAC Generate must be set in the object's cryptographic "
|
"MAC Generate must be set in the object's cryptographic "
|
||||||
"usage mask"
|
"usage mask"
|
||||||
)
|
)
|
||||||
|
|
||||||
result = self._cryptography_engine.mac(
|
result = self._cryptography_engine.mac(
|
||||||
algorithm,
|
algorithm,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user