partition
stringclasses 3
values | func_name
stringlengths 1
134
| docstring
stringlengths 1
46.9k
| path
stringlengths 4
223
| original_string
stringlengths 75
104k
| code
stringlengths 75
104k
| docstring_tokens
listlengths 1
1.97k
| repo
stringlengths 7
55
| language
stringclasses 1
value | url
stringlengths 87
315
| code_tokens
listlengths 19
28.4k
| sha
stringlengths 40
40
|
|---|---|---|---|---|---|---|---|---|---|---|---|
test
|
multiline_import
|
Return True if import is spans multiples lines.
|
autoflake.py
|
def multiline_import(line, previous_line=''):
"""Return True if import is spans multiples lines."""
for symbol in '()':
if symbol in line:
return True
# Ignore doctests.
if line.lstrip().startswith('>'):
return True
return multiline_statement(line, previous_line)
|
def multiline_import(line, previous_line=''):
"""Return True if import is spans multiples lines."""
for symbol in '()':
if symbol in line:
return True
# Ignore doctests.
if line.lstrip().startswith('>'):
return True
return multiline_statement(line, previous_line)
|
[
"Return",
"True",
"if",
"import",
"is",
"spans",
"multiples",
"lines",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L247-L257
|
[
"def",
"multiline_import",
"(",
"line",
",",
"previous_line",
"=",
"''",
")",
":",
"for",
"symbol",
"in",
"'()'",
":",
"if",
"symbol",
"in",
"line",
":",
"return",
"True",
"# Ignore doctests.",
"if",
"line",
".",
"lstrip",
"(",
")",
".",
"startswith",
"(",
"'>'",
")",
":",
"return",
"True",
"return",
"multiline_statement",
"(",
"line",
",",
"previous_line",
")"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
multiline_statement
|
Return True if this is part of a multiline statement.
|
autoflake.py
|
def multiline_statement(line, previous_line=''):
"""Return True if this is part of a multiline statement."""
for symbol in '\\:;':
if symbol in line:
return True
sio = io.StringIO(line)
try:
list(tokenize.generate_tokens(sio.readline))
return previous_line.rstrip().endswith('\\')
except (SyntaxError, tokenize.TokenError):
return True
|
def multiline_statement(line, previous_line=''):
"""Return True if this is part of a multiline statement."""
for symbol in '\\:;':
if symbol in line:
return True
sio = io.StringIO(line)
try:
list(tokenize.generate_tokens(sio.readline))
return previous_line.rstrip().endswith('\\')
except (SyntaxError, tokenize.TokenError):
return True
|
[
"Return",
"True",
"if",
"this",
"is",
"part",
"of",
"a",
"multiline",
"statement",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L260-L271
|
[
"def",
"multiline_statement",
"(",
"line",
",",
"previous_line",
"=",
"''",
")",
":",
"for",
"symbol",
"in",
"'\\\\:;'",
":",
"if",
"symbol",
"in",
"line",
":",
"return",
"True",
"sio",
"=",
"io",
".",
"StringIO",
"(",
"line",
")",
"try",
":",
"list",
"(",
"tokenize",
".",
"generate_tokens",
"(",
"sio",
".",
"readline",
")",
")",
"return",
"previous_line",
".",
"rstrip",
"(",
")",
".",
"endswith",
"(",
"'\\\\'",
")",
"except",
"(",
"SyntaxError",
",",
"tokenize",
".",
"TokenError",
")",
":",
"return",
"True"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
filter_from_import
|
Parse and filter ``from something import a, b, c``.
Return line without unused import modules, or `pass` if all of the
module in import is unused.
|
autoflake.py
|
def filter_from_import(line, unused_module):
"""Parse and filter ``from something import a, b, c``.
Return line without unused import modules, or `pass` if all of the
module in import is unused.
"""
(indentation, imports) = re.split(pattern=r'\bimport\b',
string=line, maxsplit=1)
base_module = re.search(pattern=r'\bfrom\s+([^ ]+)',
string=indentation).group(1)
# Create an imported module list with base module name
# ex ``from a import b, c as d`` -> ``['a.b', 'a.c as d']``
imports = re.split(pattern=r',', string=imports.strip())
imports = [base_module + '.' + x.strip() for x in imports]
# We compare full module name (``a.module`` not `module`) to
# guarantee the exact same module as detected from pyflakes.
filtered_imports = [x.replace(base_module + '.', '')
for x in imports if x not in unused_module]
# All of the import in this statement is unused
if not filtered_imports:
return get_indentation(line) + 'pass' + get_line_ending(line)
indentation += 'import '
return (
indentation +
', '.join(sorted(filtered_imports)) +
get_line_ending(line))
|
def filter_from_import(line, unused_module):
"""Parse and filter ``from something import a, b, c``.
Return line without unused import modules, or `pass` if all of the
module in import is unused.
"""
(indentation, imports) = re.split(pattern=r'\bimport\b',
string=line, maxsplit=1)
base_module = re.search(pattern=r'\bfrom\s+([^ ]+)',
string=indentation).group(1)
# Create an imported module list with base module name
# ex ``from a import b, c as d`` -> ``['a.b', 'a.c as d']``
imports = re.split(pattern=r',', string=imports.strip())
imports = [base_module + '.' + x.strip() for x in imports]
# We compare full module name (``a.module`` not `module`) to
# guarantee the exact same module as detected from pyflakes.
filtered_imports = [x.replace(base_module + '.', '')
for x in imports if x not in unused_module]
# All of the import in this statement is unused
if not filtered_imports:
return get_indentation(line) + 'pass' + get_line_ending(line)
indentation += 'import '
return (
indentation +
', '.join(sorted(filtered_imports)) +
get_line_ending(line))
|
[
"Parse",
"and",
"filter",
"from",
"something",
"import",
"a",
"b",
"c",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L274-L304
|
[
"def",
"filter_from_import",
"(",
"line",
",",
"unused_module",
")",
":",
"(",
"indentation",
",",
"imports",
")",
"=",
"re",
".",
"split",
"(",
"pattern",
"=",
"r'\\bimport\\b'",
",",
"string",
"=",
"line",
",",
"maxsplit",
"=",
"1",
")",
"base_module",
"=",
"re",
".",
"search",
"(",
"pattern",
"=",
"r'\\bfrom\\s+([^ ]+)'",
",",
"string",
"=",
"indentation",
")",
".",
"group",
"(",
"1",
")",
"# Create an imported module list with base module name",
"# ex ``from a import b, c as d`` -> ``['a.b', 'a.c as d']``",
"imports",
"=",
"re",
".",
"split",
"(",
"pattern",
"=",
"r','",
",",
"string",
"=",
"imports",
".",
"strip",
"(",
")",
")",
"imports",
"=",
"[",
"base_module",
"+",
"'.'",
"+",
"x",
".",
"strip",
"(",
")",
"for",
"x",
"in",
"imports",
"]",
"# We compare full module name (``a.module`` not `module`) to",
"# guarantee the exact same module as detected from pyflakes.",
"filtered_imports",
"=",
"[",
"x",
".",
"replace",
"(",
"base_module",
"+",
"'.'",
",",
"''",
")",
"for",
"x",
"in",
"imports",
"if",
"x",
"not",
"in",
"unused_module",
"]",
"# All of the import in this statement is unused",
"if",
"not",
"filtered_imports",
":",
"return",
"get_indentation",
"(",
"line",
")",
"+",
"'pass'",
"+",
"get_line_ending",
"(",
"line",
")",
"indentation",
"+=",
"'import '",
"return",
"(",
"indentation",
"+",
"', '",
".",
"join",
"(",
"sorted",
"(",
"filtered_imports",
")",
")",
"+",
"get_line_ending",
"(",
"line",
")",
")"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
break_up_import
|
Return line with imports on separate lines.
|
autoflake.py
|
def break_up_import(line):
"""Return line with imports on separate lines."""
assert '\\' not in line
assert '(' not in line
assert ')' not in line
assert ';' not in line
assert '#' not in line
assert not line.lstrip().startswith('from')
newline = get_line_ending(line)
if not newline:
return line
(indentation, imports) = re.split(pattern=r'\bimport\b',
string=line, maxsplit=1)
indentation += 'import '
assert newline
return ''.join([indentation + i.strip() + newline
for i in sorted(imports.split(','))])
|
def break_up_import(line):
"""Return line with imports on separate lines."""
assert '\\' not in line
assert '(' not in line
assert ')' not in line
assert ';' not in line
assert '#' not in line
assert not line.lstrip().startswith('from')
newline = get_line_ending(line)
if not newline:
return line
(indentation, imports) = re.split(pattern=r'\bimport\b',
string=line, maxsplit=1)
indentation += 'import '
assert newline
return ''.join([indentation + i.strip() + newline
for i in sorted(imports.split(','))])
|
[
"Return",
"line",
"with",
"imports",
"on",
"separate",
"lines",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L307-L327
|
[
"def",
"break_up_import",
"(",
"line",
")",
":",
"assert",
"'\\\\'",
"not",
"in",
"line",
"assert",
"'('",
"not",
"in",
"line",
"assert",
"')'",
"not",
"in",
"line",
"assert",
"';'",
"not",
"in",
"line",
"assert",
"'#'",
"not",
"in",
"line",
"assert",
"not",
"line",
".",
"lstrip",
"(",
")",
".",
"startswith",
"(",
"'from'",
")",
"newline",
"=",
"get_line_ending",
"(",
"line",
")",
"if",
"not",
"newline",
":",
"return",
"line",
"(",
"indentation",
",",
"imports",
")",
"=",
"re",
".",
"split",
"(",
"pattern",
"=",
"r'\\bimport\\b'",
",",
"string",
"=",
"line",
",",
"maxsplit",
"=",
"1",
")",
"indentation",
"+=",
"'import '",
"assert",
"newline",
"return",
"''",
".",
"join",
"(",
"[",
"indentation",
"+",
"i",
".",
"strip",
"(",
")",
"+",
"newline",
"for",
"i",
"in",
"sorted",
"(",
"imports",
".",
"split",
"(",
"','",
")",
")",
"]",
")"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
filter_code
|
Yield code with unused imports removed.
|
autoflake.py
|
def filter_code(source, additional_imports=None,
expand_star_imports=False,
remove_all_unused_imports=False,
remove_duplicate_keys=False,
remove_unused_variables=False,
ignore_init_module_imports=False,
):
"""Yield code with unused imports removed."""
imports = SAFE_IMPORTS
if additional_imports:
imports |= frozenset(additional_imports)
del additional_imports
messages = check(source)
if ignore_init_module_imports:
marked_import_line_numbers = frozenset()
else:
marked_import_line_numbers = frozenset(
unused_import_line_numbers(messages))
marked_unused_module = collections.defaultdict(lambda: [])
for line_number, module_name in unused_import_module_name(messages):
marked_unused_module[line_number].append(module_name)
if expand_star_imports and not (
# See explanations in #18.
re.search(r'\b__all__\b', source) or
re.search(r'\bdel\b', source)
):
marked_star_import_line_numbers = frozenset(
star_import_used_line_numbers(messages))
if len(marked_star_import_line_numbers) > 1:
# Auto expanding only possible for single star import
marked_star_import_line_numbers = frozenset()
else:
undefined_names = []
for line_number, undefined_name, _ \
in star_import_usage_undefined_name(messages):
undefined_names.append(undefined_name)
if not undefined_names:
marked_star_import_line_numbers = frozenset()
else:
marked_star_import_line_numbers = frozenset()
if remove_unused_variables:
marked_variable_line_numbers = frozenset(
unused_variable_line_numbers(messages))
else:
marked_variable_line_numbers = frozenset()
if remove_duplicate_keys:
marked_key_line_numbers = frozenset(
duplicate_key_line_numbers(messages, source))
else:
marked_key_line_numbers = frozenset()
line_messages = get_messages_by_line(messages)
sio = io.StringIO(source)
previous_line = ''
for line_number, line in enumerate(sio.readlines(), start=1):
if '#' in line:
yield line
elif line_number in marked_import_line_numbers:
yield filter_unused_import(
line,
unused_module=marked_unused_module[line_number],
remove_all_unused_imports=remove_all_unused_imports,
imports=imports,
previous_line=previous_line)
elif line_number in marked_variable_line_numbers:
yield filter_unused_variable(line)
elif line_number in marked_key_line_numbers:
yield filter_duplicate_key(line, line_messages[line_number],
line_number, marked_key_line_numbers,
source)
elif line_number in marked_star_import_line_numbers:
yield filter_star_import(line, undefined_names)
else:
yield line
previous_line = line
|
def filter_code(source, additional_imports=None,
expand_star_imports=False,
remove_all_unused_imports=False,
remove_duplicate_keys=False,
remove_unused_variables=False,
ignore_init_module_imports=False,
):
"""Yield code with unused imports removed."""
imports = SAFE_IMPORTS
if additional_imports:
imports |= frozenset(additional_imports)
del additional_imports
messages = check(source)
if ignore_init_module_imports:
marked_import_line_numbers = frozenset()
else:
marked_import_line_numbers = frozenset(
unused_import_line_numbers(messages))
marked_unused_module = collections.defaultdict(lambda: [])
for line_number, module_name in unused_import_module_name(messages):
marked_unused_module[line_number].append(module_name)
if expand_star_imports and not (
# See explanations in #18.
re.search(r'\b__all__\b', source) or
re.search(r'\bdel\b', source)
):
marked_star_import_line_numbers = frozenset(
star_import_used_line_numbers(messages))
if len(marked_star_import_line_numbers) > 1:
# Auto expanding only possible for single star import
marked_star_import_line_numbers = frozenset()
else:
undefined_names = []
for line_number, undefined_name, _ \
in star_import_usage_undefined_name(messages):
undefined_names.append(undefined_name)
if not undefined_names:
marked_star_import_line_numbers = frozenset()
else:
marked_star_import_line_numbers = frozenset()
if remove_unused_variables:
marked_variable_line_numbers = frozenset(
unused_variable_line_numbers(messages))
else:
marked_variable_line_numbers = frozenset()
if remove_duplicate_keys:
marked_key_line_numbers = frozenset(
duplicate_key_line_numbers(messages, source))
else:
marked_key_line_numbers = frozenset()
line_messages = get_messages_by_line(messages)
sio = io.StringIO(source)
previous_line = ''
for line_number, line in enumerate(sio.readlines(), start=1):
if '#' in line:
yield line
elif line_number in marked_import_line_numbers:
yield filter_unused_import(
line,
unused_module=marked_unused_module[line_number],
remove_all_unused_imports=remove_all_unused_imports,
imports=imports,
previous_line=previous_line)
elif line_number in marked_variable_line_numbers:
yield filter_unused_variable(line)
elif line_number in marked_key_line_numbers:
yield filter_duplicate_key(line, line_messages[line_number],
line_number, marked_key_line_numbers,
source)
elif line_number in marked_star_import_line_numbers:
yield filter_star_import(line, undefined_names)
else:
yield line
previous_line = line
|
[
"Yield",
"code",
"with",
"unused",
"imports",
"removed",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L330-L411
|
[
"def",
"filter_code",
"(",
"source",
",",
"additional_imports",
"=",
"None",
",",
"expand_star_imports",
"=",
"False",
",",
"remove_all_unused_imports",
"=",
"False",
",",
"remove_duplicate_keys",
"=",
"False",
",",
"remove_unused_variables",
"=",
"False",
",",
"ignore_init_module_imports",
"=",
"False",
",",
")",
":",
"imports",
"=",
"SAFE_IMPORTS",
"if",
"additional_imports",
":",
"imports",
"|=",
"frozenset",
"(",
"additional_imports",
")",
"del",
"additional_imports",
"messages",
"=",
"check",
"(",
"source",
")",
"if",
"ignore_init_module_imports",
":",
"marked_import_line_numbers",
"=",
"frozenset",
"(",
")",
"else",
":",
"marked_import_line_numbers",
"=",
"frozenset",
"(",
"unused_import_line_numbers",
"(",
"messages",
")",
")",
"marked_unused_module",
"=",
"collections",
".",
"defaultdict",
"(",
"lambda",
":",
"[",
"]",
")",
"for",
"line_number",
",",
"module_name",
"in",
"unused_import_module_name",
"(",
"messages",
")",
":",
"marked_unused_module",
"[",
"line_number",
"]",
".",
"append",
"(",
"module_name",
")",
"if",
"expand_star_imports",
"and",
"not",
"(",
"# See explanations in #18.",
"re",
".",
"search",
"(",
"r'\\b__all__\\b'",
",",
"source",
")",
"or",
"re",
".",
"search",
"(",
"r'\\bdel\\b'",
",",
"source",
")",
")",
":",
"marked_star_import_line_numbers",
"=",
"frozenset",
"(",
"star_import_used_line_numbers",
"(",
"messages",
")",
")",
"if",
"len",
"(",
"marked_star_import_line_numbers",
")",
">",
"1",
":",
"# Auto expanding only possible for single star import",
"marked_star_import_line_numbers",
"=",
"frozenset",
"(",
")",
"else",
":",
"undefined_names",
"=",
"[",
"]",
"for",
"line_number",
",",
"undefined_name",
",",
"_",
"in",
"star_import_usage_undefined_name",
"(",
"messages",
")",
":",
"undefined_names",
".",
"append",
"(",
"undefined_name",
")",
"if",
"not",
"undefined_names",
":",
"marked_star_import_line_numbers",
"=",
"frozenset",
"(",
")",
"else",
":",
"marked_star_import_line_numbers",
"=",
"frozenset",
"(",
")",
"if",
"remove_unused_variables",
":",
"marked_variable_line_numbers",
"=",
"frozenset",
"(",
"unused_variable_line_numbers",
"(",
"messages",
")",
")",
"else",
":",
"marked_variable_line_numbers",
"=",
"frozenset",
"(",
")",
"if",
"remove_duplicate_keys",
":",
"marked_key_line_numbers",
"=",
"frozenset",
"(",
"duplicate_key_line_numbers",
"(",
"messages",
",",
"source",
")",
")",
"else",
":",
"marked_key_line_numbers",
"=",
"frozenset",
"(",
")",
"line_messages",
"=",
"get_messages_by_line",
"(",
"messages",
")",
"sio",
"=",
"io",
".",
"StringIO",
"(",
"source",
")",
"previous_line",
"=",
"''",
"for",
"line_number",
",",
"line",
"in",
"enumerate",
"(",
"sio",
".",
"readlines",
"(",
")",
",",
"start",
"=",
"1",
")",
":",
"if",
"'#'",
"in",
"line",
":",
"yield",
"line",
"elif",
"line_number",
"in",
"marked_import_line_numbers",
":",
"yield",
"filter_unused_import",
"(",
"line",
",",
"unused_module",
"=",
"marked_unused_module",
"[",
"line_number",
"]",
",",
"remove_all_unused_imports",
"=",
"remove_all_unused_imports",
",",
"imports",
"=",
"imports",
",",
"previous_line",
"=",
"previous_line",
")",
"elif",
"line_number",
"in",
"marked_variable_line_numbers",
":",
"yield",
"filter_unused_variable",
"(",
"line",
")",
"elif",
"line_number",
"in",
"marked_key_line_numbers",
":",
"yield",
"filter_duplicate_key",
"(",
"line",
",",
"line_messages",
"[",
"line_number",
"]",
",",
"line_number",
",",
"marked_key_line_numbers",
",",
"source",
")",
"elif",
"line_number",
"in",
"marked_star_import_line_numbers",
":",
"yield",
"filter_star_import",
"(",
"line",
",",
"undefined_names",
")",
"else",
":",
"yield",
"line",
"previous_line",
"=",
"line"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
get_messages_by_line
|
Return dictionary that maps line number to message.
|
autoflake.py
|
def get_messages_by_line(messages):
"""Return dictionary that maps line number to message."""
line_messages = {}
for message in messages:
line_messages[message.lineno] = message
return line_messages
|
def get_messages_by_line(messages):
"""Return dictionary that maps line number to message."""
line_messages = {}
for message in messages:
line_messages[message.lineno] = message
return line_messages
|
[
"Return",
"dictionary",
"that",
"maps",
"line",
"number",
"to",
"message",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L414-L419
|
[
"def",
"get_messages_by_line",
"(",
"messages",
")",
":",
"line_messages",
"=",
"{",
"}",
"for",
"message",
"in",
"messages",
":",
"line_messages",
"[",
"message",
".",
"lineno",
"]",
"=",
"message",
"return",
"line_messages"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
filter_star_import
|
Return line with the star import expanded.
|
autoflake.py
|
def filter_star_import(line, marked_star_import_undefined_name):
"""Return line with the star import expanded."""
undefined_name = sorted(set(marked_star_import_undefined_name))
return re.sub(r'\*', ', '.join(undefined_name), line)
|
def filter_star_import(line, marked_star_import_undefined_name):
"""Return line with the star import expanded."""
undefined_name = sorted(set(marked_star_import_undefined_name))
return re.sub(r'\*', ', '.join(undefined_name), line)
|
[
"Return",
"line",
"with",
"the",
"star",
"import",
"expanded",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L422-L425
|
[
"def",
"filter_star_import",
"(",
"line",
",",
"marked_star_import_undefined_name",
")",
":",
"undefined_name",
"=",
"sorted",
"(",
"set",
"(",
"marked_star_import_undefined_name",
")",
")",
"return",
"re",
".",
"sub",
"(",
"r'\\*'",
",",
"', '",
".",
"join",
"(",
"undefined_name",
")",
",",
"line",
")"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
filter_unused_import
|
Return line if used, otherwise return None.
|
autoflake.py
|
def filter_unused_import(line, unused_module, remove_all_unused_imports,
imports, previous_line=''):
"""Return line if used, otherwise return None."""
if multiline_import(line, previous_line):
return line
is_from_import = line.lstrip().startswith('from')
if ',' in line and not is_from_import:
return break_up_import(line)
package = extract_package_name(line)
if not remove_all_unused_imports and package not in imports:
return line
if ',' in line:
assert is_from_import
return filter_from_import(line, unused_module)
else:
# We need to replace import with "pass" in case the import is the
# only line inside a block. For example,
# "if True:\n import os". In such cases, if the import is
# removed, the block will be left hanging with no body.
return (get_indentation(line) +
'pass' +
get_line_ending(line))
|
def filter_unused_import(line, unused_module, remove_all_unused_imports,
imports, previous_line=''):
"""Return line if used, otherwise return None."""
if multiline_import(line, previous_line):
return line
is_from_import = line.lstrip().startswith('from')
if ',' in line and not is_from_import:
return break_up_import(line)
package = extract_package_name(line)
if not remove_all_unused_imports and package not in imports:
return line
if ',' in line:
assert is_from_import
return filter_from_import(line, unused_module)
else:
# We need to replace import with "pass" in case the import is the
# only line inside a block. For example,
# "if True:\n import os". In such cases, if the import is
# removed, the block will be left hanging with no body.
return (get_indentation(line) +
'pass' +
get_line_ending(line))
|
[
"Return",
"line",
"if",
"used",
"otherwise",
"return",
"None",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L428-L453
|
[
"def",
"filter_unused_import",
"(",
"line",
",",
"unused_module",
",",
"remove_all_unused_imports",
",",
"imports",
",",
"previous_line",
"=",
"''",
")",
":",
"if",
"multiline_import",
"(",
"line",
",",
"previous_line",
")",
":",
"return",
"line",
"is_from_import",
"=",
"line",
".",
"lstrip",
"(",
")",
".",
"startswith",
"(",
"'from'",
")",
"if",
"','",
"in",
"line",
"and",
"not",
"is_from_import",
":",
"return",
"break_up_import",
"(",
"line",
")",
"package",
"=",
"extract_package_name",
"(",
"line",
")",
"if",
"not",
"remove_all_unused_imports",
"and",
"package",
"not",
"in",
"imports",
":",
"return",
"line",
"if",
"','",
"in",
"line",
":",
"assert",
"is_from_import",
"return",
"filter_from_import",
"(",
"line",
",",
"unused_module",
")",
"else",
":",
"# We need to replace import with \"pass\" in case the import is the",
"# only line inside a block. For example,",
"# \"if True:\\n import os\". In such cases, if the import is",
"# removed, the block will be left hanging with no body.",
"return",
"(",
"get_indentation",
"(",
"line",
")",
"+",
"'pass'",
"+",
"get_line_ending",
"(",
"line",
")",
")"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
filter_unused_variable
|
Return line if used, otherwise return None.
|
autoflake.py
|
def filter_unused_variable(line, previous_line=''):
"""Return line if used, otherwise return None."""
if re.match(EXCEPT_REGEX, line):
return re.sub(r' as \w+:$', ':', line, count=1)
elif multiline_statement(line, previous_line):
return line
elif line.count('=') == 1:
split_line = line.split('=')
assert len(split_line) == 2
value = split_line[1].lstrip()
if ',' in split_line[0]:
return line
if is_literal_or_name(value):
# Rather than removing the line, replace with it "pass" to avoid
# a possible hanging block with no body.
value = 'pass' + get_line_ending(line)
return get_indentation(line) + value
else:
return line
|
def filter_unused_variable(line, previous_line=''):
"""Return line if used, otherwise return None."""
if re.match(EXCEPT_REGEX, line):
return re.sub(r' as \w+:$', ':', line, count=1)
elif multiline_statement(line, previous_line):
return line
elif line.count('=') == 1:
split_line = line.split('=')
assert len(split_line) == 2
value = split_line[1].lstrip()
if ',' in split_line[0]:
return line
if is_literal_or_name(value):
# Rather than removing the line, replace with it "pass" to avoid
# a possible hanging block with no body.
value = 'pass' + get_line_ending(line)
return get_indentation(line) + value
else:
return line
|
[
"Return",
"line",
"if",
"used",
"otherwise",
"return",
"None",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L456-L476
|
[
"def",
"filter_unused_variable",
"(",
"line",
",",
"previous_line",
"=",
"''",
")",
":",
"if",
"re",
".",
"match",
"(",
"EXCEPT_REGEX",
",",
"line",
")",
":",
"return",
"re",
".",
"sub",
"(",
"r' as \\w+:$'",
",",
"':'",
",",
"line",
",",
"count",
"=",
"1",
")",
"elif",
"multiline_statement",
"(",
"line",
",",
"previous_line",
")",
":",
"return",
"line",
"elif",
"line",
".",
"count",
"(",
"'='",
")",
"==",
"1",
":",
"split_line",
"=",
"line",
".",
"split",
"(",
"'='",
")",
"assert",
"len",
"(",
"split_line",
")",
"==",
"2",
"value",
"=",
"split_line",
"[",
"1",
"]",
".",
"lstrip",
"(",
")",
"if",
"','",
"in",
"split_line",
"[",
"0",
"]",
":",
"return",
"line",
"if",
"is_literal_or_name",
"(",
"value",
")",
":",
"# Rather than removing the line, replace with it \"pass\" to avoid",
"# a possible hanging block with no body.",
"value",
"=",
"'pass'",
"+",
"get_line_ending",
"(",
"line",
")",
"return",
"get_indentation",
"(",
"line",
")",
"+",
"value",
"else",
":",
"return",
"line"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
filter_duplicate_key
|
Return '' if first occurrence of the key otherwise return `line`.
|
autoflake.py
|
def filter_duplicate_key(line, message, line_number, marked_line_numbers,
source, previous_line=''):
"""Return '' if first occurrence of the key otherwise return `line`."""
if marked_line_numbers and line_number == sorted(marked_line_numbers)[0]:
return ''
return line
|
def filter_duplicate_key(line, message, line_number, marked_line_numbers,
source, previous_line=''):
"""Return '' if first occurrence of the key otherwise return `line`."""
if marked_line_numbers and line_number == sorted(marked_line_numbers)[0]:
return ''
return line
|
[
"Return",
"if",
"first",
"occurrence",
"of",
"the",
"key",
"otherwise",
"return",
"line",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L479-L485
|
[
"def",
"filter_duplicate_key",
"(",
"line",
",",
"message",
",",
"line_number",
",",
"marked_line_numbers",
",",
"source",
",",
"previous_line",
"=",
"''",
")",
":",
"if",
"marked_line_numbers",
"and",
"line_number",
"==",
"sorted",
"(",
"marked_line_numbers",
")",
"[",
"0",
"]",
":",
"return",
"''",
"return",
"line"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
dict_entry_has_key
|
Return True if `line` is a dict entry that uses `key`.
Return False for multiline cases where the line should not be removed by
itself.
|
autoflake.py
|
def dict_entry_has_key(line, key):
"""Return True if `line` is a dict entry that uses `key`.
Return False for multiline cases where the line should not be removed by
itself.
"""
if '#' in line:
return False
result = re.match(r'\s*(.*)\s*:\s*(.*),\s*$', line)
if not result:
return False
try:
candidate_key = ast.literal_eval(result.group(1))
except (SyntaxError, ValueError):
return False
if multiline_statement(result.group(2)):
return False
return candidate_key == key
|
def dict_entry_has_key(line, key):
"""Return True if `line` is a dict entry that uses `key`.
Return False for multiline cases where the line should not be removed by
itself.
"""
if '#' in line:
return False
result = re.match(r'\s*(.*)\s*:\s*(.*),\s*$', line)
if not result:
return False
try:
candidate_key = ast.literal_eval(result.group(1))
except (SyntaxError, ValueError):
return False
if multiline_statement(result.group(2)):
return False
return candidate_key == key
|
[
"Return",
"True",
"if",
"line",
"is",
"a",
"dict",
"entry",
"that",
"uses",
"key",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L488-L510
|
[
"def",
"dict_entry_has_key",
"(",
"line",
",",
"key",
")",
":",
"if",
"'#'",
"in",
"line",
":",
"return",
"False",
"result",
"=",
"re",
".",
"match",
"(",
"r'\\s*(.*)\\s*:\\s*(.*),\\s*$'",
",",
"line",
")",
"if",
"not",
"result",
":",
"return",
"False",
"try",
":",
"candidate_key",
"=",
"ast",
".",
"literal_eval",
"(",
"result",
".",
"group",
"(",
"1",
")",
")",
"except",
"(",
"SyntaxError",
",",
"ValueError",
")",
":",
"return",
"False",
"if",
"multiline_statement",
"(",
"result",
".",
"group",
"(",
"2",
")",
")",
":",
"return",
"False",
"return",
"candidate_key",
"==",
"key"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
is_literal_or_name
|
Return True if value is a literal or a name.
|
autoflake.py
|
def is_literal_or_name(value):
"""Return True if value is a literal or a name."""
try:
ast.literal_eval(value)
return True
except (SyntaxError, ValueError):
pass
if value.strip() in ['dict()', 'list()', 'set()']:
return True
# Support removal of variables on the right side. But make sure
# there are no dots, which could mean an access of a property.
return re.match(r'^\w+\s*$', value)
|
def is_literal_or_name(value):
"""Return True if value is a literal or a name."""
try:
ast.literal_eval(value)
return True
except (SyntaxError, ValueError):
pass
if value.strip() in ['dict()', 'list()', 'set()']:
return True
# Support removal of variables on the right side. But make sure
# there are no dots, which could mean an access of a property.
return re.match(r'^\w+\s*$', value)
|
[
"Return",
"True",
"if",
"value",
"is",
"a",
"literal",
"or",
"a",
"name",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L513-L526
|
[
"def",
"is_literal_or_name",
"(",
"value",
")",
":",
"try",
":",
"ast",
".",
"literal_eval",
"(",
"value",
")",
"return",
"True",
"except",
"(",
"SyntaxError",
",",
"ValueError",
")",
":",
"pass",
"if",
"value",
".",
"strip",
"(",
")",
"in",
"[",
"'dict()'",
",",
"'list()'",
",",
"'set()'",
"]",
":",
"return",
"True",
"# Support removal of variables on the right side. But make sure",
"# there are no dots, which could mean an access of a property.",
"return",
"re",
".",
"match",
"(",
"r'^\\w+\\s*$'",
",",
"value",
")"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
useless_pass_line_numbers
|
Yield line numbers of unneeded "pass" statements.
|
autoflake.py
|
def useless_pass_line_numbers(source):
"""Yield line numbers of unneeded "pass" statements."""
sio = io.StringIO(source)
previous_token_type = None
last_pass_row = None
last_pass_indentation = None
previous_line = ''
for token in tokenize.generate_tokens(sio.readline):
token_type = token[0]
start_row = token[2][0]
line = token[4]
is_pass = (token_type == tokenize.NAME and line.strip() == 'pass')
# Leading "pass".
if (start_row - 1 == last_pass_row and
get_indentation(line) == last_pass_indentation and
token_type in ATOMS and
not is_pass):
yield start_row - 1
if is_pass:
last_pass_row = start_row
last_pass_indentation = get_indentation(line)
# Trailing "pass".
if (is_pass and
previous_token_type != tokenize.INDENT and
not previous_line.rstrip().endswith('\\')):
yield start_row
previous_token_type = token_type
previous_line = line
|
def useless_pass_line_numbers(source):
"""Yield line numbers of unneeded "pass" statements."""
sio = io.StringIO(source)
previous_token_type = None
last_pass_row = None
last_pass_indentation = None
previous_line = ''
for token in tokenize.generate_tokens(sio.readline):
token_type = token[0]
start_row = token[2][0]
line = token[4]
is_pass = (token_type == tokenize.NAME and line.strip() == 'pass')
# Leading "pass".
if (start_row - 1 == last_pass_row and
get_indentation(line) == last_pass_indentation and
token_type in ATOMS and
not is_pass):
yield start_row - 1
if is_pass:
last_pass_row = start_row
last_pass_indentation = get_indentation(line)
# Trailing "pass".
if (is_pass and
previous_token_type != tokenize.INDENT and
not previous_line.rstrip().endswith('\\')):
yield start_row
previous_token_type = token_type
previous_line = line
|
[
"Yield",
"line",
"numbers",
"of",
"unneeded",
"pass",
"statements",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L529-L561
|
[
"def",
"useless_pass_line_numbers",
"(",
"source",
")",
":",
"sio",
"=",
"io",
".",
"StringIO",
"(",
"source",
")",
"previous_token_type",
"=",
"None",
"last_pass_row",
"=",
"None",
"last_pass_indentation",
"=",
"None",
"previous_line",
"=",
"''",
"for",
"token",
"in",
"tokenize",
".",
"generate_tokens",
"(",
"sio",
".",
"readline",
")",
":",
"token_type",
"=",
"token",
"[",
"0",
"]",
"start_row",
"=",
"token",
"[",
"2",
"]",
"[",
"0",
"]",
"line",
"=",
"token",
"[",
"4",
"]",
"is_pass",
"=",
"(",
"token_type",
"==",
"tokenize",
".",
"NAME",
"and",
"line",
".",
"strip",
"(",
")",
"==",
"'pass'",
")",
"# Leading \"pass\".",
"if",
"(",
"start_row",
"-",
"1",
"==",
"last_pass_row",
"and",
"get_indentation",
"(",
"line",
")",
"==",
"last_pass_indentation",
"and",
"token_type",
"in",
"ATOMS",
"and",
"not",
"is_pass",
")",
":",
"yield",
"start_row",
"-",
"1",
"if",
"is_pass",
":",
"last_pass_row",
"=",
"start_row",
"last_pass_indentation",
"=",
"get_indentation",
"(",
"line",
")",
"# Trailing \"pass\".",
"if",
"(",
"is_pass",
"and",
"previous_token_type",
"!=",
"tokenize",
".",
"INDENT",
"and",
"not",
"previous_line",
".",
"rstrip",
"(",
")",
".",
"endswith",
"(",
"'\\\\'",
")",
")",
":",
"yield",
"start_row",
"previous_token_type",
"=",
"token_type",
"previous_line",
"=",
"line"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
filter_useless_pass
|
Yield code with useless "pass" lines removed.
|
autoflake.py
|
def filter_useless_pass(source):
"""Yield code with useless "pass" lines removed."""
try:
marked_lines = frozenset(useless_pass_line_numbers(source))
except (SyntaxError, tokenize.TokenError):
marked_lines = frozenset()
sio = io.StringIO(source)
for line_number, line in enumerate(sio.readlines(), start=1):
if line_number not in marked_lines:
yield line
|
def filter_useless_pass(source):
"""Yield code with useless "pass" lines removed."""
try:
marked_lines = frozenset(useless_pass_line_numbers(source))
except (SyntaxError, tokenize.TokenError):
marked_lines = frozenset()
sio = io.StringIO(source)
for line_number, line in enumerate(sio.readlines(), start=1):
if line_number not in marked_lines:
yield line
|
[
"Yield",
"code",
"with",
"useless",
"pass",
"lines",
"removed",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L564-L574
|
[
"def",
"filter_useless_pass",
"(",
"source",
")",
":",
"try",
":",
"marked_lines",
"=",
"frozenset",
"(",
"useless_pass_line_numbers",
"(",
"source",
")",
")",
"except",
"(",
"SyntaxError",
",",
"tokenize",
".",
"TokenError",
")",
":",
"marked_lines",
"=",
"frozenset",
"(",
")",
"sio",
"=",
"io",
".",
"StringIO",
"(",
"source",
")",
"for",
"line_number",
",",
"line",
"in",
"enumerate",
"(",
"sio",
".",
"readlines",
"(",
")",
",",
"start",
"=",
"1",
")",
":",
"if",
"line_number",
"not",
"in",
"marked_lines",
":",
"yield",
"line"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
get_indentation
|
Return leading whitespace.
|
autoflake.py
|
def get_indentation(line):
"""Return leading whitespace."""
if line.strip():
non_whitespace_index = len(line) - len(line.lstrip())
return line[:non_whitespace_index]
else:
return ''
|
def get_indentation(line):
"""Return leading whitespace."""
if line.strip():
non_whitespace_index = len(line) - len(line.lstrip())
return line[:non_whitespace_index]
else:
return ''
|
[
"Return",
"leading",
"whitespace",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L577-L583
|
[
"def",
"get_indentation",
"(",
"line",
")",
":",
"if",
"line",
".",
"strip",
"(",
")",
":",
"non_whitespace_index",
"=",
"len",
"(",
"line",
")",
"-",
"len",
"(",
"line",
".",
"lstrip",
"(",
")",
")",
"return",
"line",
"[",
":",
"non_whitespace_index",
"]",
"else",
":",
"return",
"''"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
get_line_ending
|
Return line ending.
|
autoflake.py
|
def get_line_ending(line):
"""Return line ending."""
non_whitespace_index = len(line.rstrip()) - len(line)
if not non_whitespace_index:
return ''
else:
return line[non_whitespace_index:]
|
def get_line_ending(line):
"""Return line ending."""
non_whitespace_index = len(line.rstrip()) - len(line)
if not non_whitespace_index:
return ''
else:
return line[non_whitespace_index:]
|
[
"Return",
"line",
"ending",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L586-L592
|
[
"def",
"get_line_ending",
"(",
"line",
")",
":",
"non_whitespace_index",
"=",
"len",
"(",
"line",
".",
"rstrip",
"(",
")",
")",
"-",
"len",
"(",
"line",
")",
"if",
"not",
"non_whitespace_index",
":",
"return",
"''",
"else",
":",
"return",
"line",
"[",
"non_whitespace_index",
":",
"]"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
fix_code
|
Return code with all filtering run on it.
|
autoflake.py
|
def fix_code(source, additional_imports=None, expand_star_imports=False,
remove_all_unused_imports=False, remove_duplicate_keys=False,
remove_unused_variables=False, ignore_init_module_imports=False):
"""Return code with all filtering run on it."""
if not source:
return source
# pyflakes does not handle "nonlocal" correctly.
if 'nonlocal' in source:
remove_unused_variables = False
filtered_source = None
while True:
filtered_source = ''.join(
filter_useless_pass(''.join(
filter_code(
source,
additional_imports=additional_imports,
expand_star_imports=expand_star_imports,
remove_all_unused_imports=remove_all_unused_imports,
remove_duplicate_keys=remove_duplicate_keys,
remove_unused_variables=remove_unused_variables,
ignore_init_module_imports=ignore_init_module_imports,
))))
if filtered_source == source:
break
source = filtered_source
return filtered_source
|
def fix_code(source, additional_imports=None, expand_star_imports=False,
remove_all_unused_imports=False, remove_duplicate_keys=False,
remove_unused_variables=False, ignore_init_module_imports=False):
"""Return code with all filtering run on it."""
if not source:
return source
# pyflakes does not handle "nonlocal" correctly.
if 'nonlocal' in source:
remove_unused_variables = False
filtered_source = None
while True:
filtered_source = ''.join(
filter_useless_pass(''.join(
filter_code(
source,
additional_imports=additional_imports,
expand_star_imports=expand_star_imports,
remove_all_unused_imports=remove_all_unused_imports,
remove_duplicate_keys=remove_duplicate_keys,
remove_unused_variables=remove_unused_variables,
ignore_init_module_imports=ignore_init_module_imports,
))))
if filtered_source == source:
break
source = filtered_source
return filtered_source
|
[
"Return",
"code",
"with",
"all",
"filtering",
"run",
"on",
"it",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L595-L624
|
[
"def",
"fix_code",
"(",
"source",
",",
"additional_imports",
"=",
"None",
",",
"expand_star_imports",
"=",
"False",
",",
"remove_all_unused_imports",
"=",
"False",
",",
"remove_duplicate_keys",
"=",
"False",
",",
"remove_unused_variables",
"=",
"False",
",",
"ignore_init_module_imports",
"=",
"False",
")",
":",
"if",
"not",
"source",
":",
"return",
"source",
"# pyflakes does not handle \"nonlocal\" correctly.",
"if",
"'nonlocal'",
"in",
"source",
":",
"remove_unused_variables",
"=",
"False",
"filtered_source",
"=",
"None",
"while",
"True",
":",
"filtered_source",
"=",
"''",
".",
"join",
"(",
"filter_useless_pass",
"(",
"''",
".",
"join",
"(",
"filter_code",
"(",
"source",
",",
"additional_imports",
"=",
"additional_imports",
",",
"expand_star_imports",
"=",
"expand_star_imports",
",",
"remove_all_unused_imports",
"=",
"remove_all_unused_imports",
",",
"remove_duplicate_keys",
"=",
"remove_duplicate_keys",
",",
"remove_unused_variables",
"=",
"remove_unused_variables",
",",
"ignore_init_module_imports",
"=",
"ignore_init_module_imports",
",",
")",
")",
")",
")",
"if",
"filtered_source",
"==",
"source",
":",
"break",
"source",
"=",
"filtered_source",
"return",
"filtered_source"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
fix_file
|
Run fix_code() on a file.
|
autoflake.py
|
def fix_file(filename, args, standard_out):
"""Run fix_code() on a file."""
encoding = detect_encoding(filename)
with open_with_encoding(filename, encoding=encoding) as input_file:
source = input_file.read()
original_source = source
isInitFile = os.path.basename(filename) == '__init__.py'
if args.ignore_init_module_imports and isInitFile:
ignore_init_module_imports = True
else:
ignore_init_module_imports = False
filtered_source = fix_code(
source,
additional_imports=args.imports.split(',') if args.imports else None,
expand_star_imports=args.expand_star_imports,
remove_all_unused_imports=args.remove_all_unused_imports,
remove_duplicate_keys=args.remove_duplicate_keys,
remove_unused_variables=args.remove_unused_variables,
ignore_init_module_imports=ignore_init_module_imports,
)
if original_source != filtered_source:
if args.check:
standard_out.write('Unused imports/variables detected.')
sys.exit(1)
if args.in_place:
with open_with_encoding(filename, mode='w',
encoding=encoding) as output_file:
output_file.write(filtered_source)
else:
diff = get_diff_text(
io.StringIO(original_source).readlines(),
io.StringIO(filtered_source).readlines(),
filename)
standard_out.write(''.join(diff))
else:
if args.check:
standard_out.write('No issues detected!')
|
def fix_file(filename, args, standard_out):
"""Run fix_code() on a file."""
encoding = detect_encoding(filename)
with open_with_encoding(filename, encoding=encoding) as input_file:
source = input_file.read()
original_source = source
isInitFile = os.path.basename(filename) == '__init__.py'
if args.ignore_init_module_imports and isInitFile:
ignore_init_module_imports = True
else:
ignore_init_module_imports = False
filtered_source = fix_code(
source,
additional_imports=args.imports.split(',') if args.imports else None,
expand_star_imports=args.expand_star_imports,
remove_all_unused_imports=args.remove_all_unused_imports,
remove_duplicate_keys=args.remove_duplicate_keys,
remove_unused_variables=args.remove_unused_variables,
ignore_init_module_imports=ignore_init_module_imports,
)
if original_source != filtered_source:
if args.check:
standard_out.write('Unused imports/variables detected.')
sys.exit(1)
if args.in_place:
with open_with_encoding(filename, mode='w',
encoding=encoding) as output_file:
output_file.write(filtered_source)
else:
diff = get_diff_text(
io.StringIO(original_source).readlines(),
io.StringIO(filtered_source).readlines(),
filename)
standard_out.write(''.join(diff))
else:
if args.check:
standard_out.write('No issues detected!')
|
[
"Run",
"fix_code",
"()",
"on",
"a",
"file",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L627-L668
|
[
"def",
"fix_file",
"(",
"filename",
",",
"args",
",",
"standard_out",
")",
":",
"encoding",
"=",
"detect_encoding",
"(",
"filename",
")",
"with",
"open_with_encoding",
"(",
"filename",
",",
"encoding",
"=",
"encoding",
")",
"as",
"input_file",
":",
"source",
"=",
"input_file",
".",
"read",
"(",
")",
"original_source",
"=",
"source",
"isInitFile",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"filename",
")",
"==",
"'__init__.py'",
"if",
"args",
".",
"ignore_init_module_imports",
"and",
"isInitFile",
":",
"ignore_init_module_imports",
"=",
"True",
"else",
":",
"ignore_init_module_imports",
"=",
"False",
"filtered_source",
"=",
"fix_code",
"(",
"source",
",",
"additional_imports",
"=",
"args",
".",
"imports",
".",
"split",
"(",
"','",
")",
"if",
"args",
".",
"imports",
"else",
"None",
",",
"expand_star_imports",
"=",
"args",
".",
"expand_star_imports",
",",
"remove_all_unused_imports",
"=",
"args",
".",
"remove_all_unused_imports",
",",
"remove_duplicate_keys",
"=",
"args",
".",
"remove_duplicate_keys",
",",
"remove_unused_variables",
"=",
"args",
".",
"remove_unused_variables",
",",
"ignore_init_module_imports",
"=",
"ignore_init_module_imports",
",",
")",
"if",
"original_source",
"!=",
"filtered_source",
":",
"if",
"args",
".",
"check",
":",
"standard_out",
".",
"write",
"(",
"'Unused imports/variables detected.'",
")",
"sys",
".",
"exit",
"(",
"1",
")",
"if",
"args",
".",
"in_place",
":",
"with",
"open_with_encoding",
"(",
"filename",
",",
"mode",
"=",
"'w'",
",",
"encoding",
"=",
"encoding",
")",
"as",
"output_file",
":",
"output_file",
".",
"write",
"(",
"filtered_source",
")",
"else",
":",
"diff",
"=",
"get_diff_text",
"(",
"io",
".",
"StringIO",
"(",
"original_source",
")",
".",
"readlines",
"(",
")",
",",
"io",
".",
"StringIO",
"(",
"filtered_source",
")",
".",
"readlines",
"(",
")",
",",
"filename",
")",
"standard_out",
".",
"write",
"(",
"''",
".",
"join",
"(",
"diff",
")",
")",
"else",
":",
"if",
"args",
".",
"check",
":",
"standard_out",
".",
"write",
"(",
"'No issues detected!'",
")"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
detect_encoding
|
Return file encoding.
|
autoflake.py
|
def detect_encoding(filename, limit_byte_check=-1):
"""Return file encoding."""
try:
with open(filename, 'rb') as input_file:
encoding = _detect_encoding(input_file.readline)
# Check for correctness of encoding.
with open_with_encoding(filename, encoding) as input_file:
input_file.read(limit_byte_check)
return encoding
except (LookupError, SyntaxError, UnicodeDecodeError):
return 'latin-1'
|
def detect_encoding(filename, limit_byte_check=-1):
"""Return file encoding."""
try:
with open(filename, 'rb') as input_file:
encoding = _detect_encoding(input_file.readline)
# Check for correctness of encoding.
with open_with_encoding(filename, encoding) as input_file:
input_file.read(limit_byte_check)
return encoding
except (LookupError, SyntaxError, UnicodeDecodeError):
return 'latin-1'
|
[
"Return",
"file",
"encoding",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L681-L693
|
[
"def",
"detect_encoding",
"(",
"filename",
",",
"limit_byte_check",
"=",
"-",
"1",
")",
":",
"try",
":",
"with",
"open",
"(",
"filename",
",",
"'rb'",
")",
"as",
"input_file",
":",
"encoding",
"=",
"_detect_encoding",
"(",
"input_file",
".",
"readline",
")",
"# Check for correctness of encoding.",
"with",
"open_with_encoding",
"(",
"filename",
",",
"encoding",
")",
"as",
"input_file",
":",
"input_file",
".",
"read",
"(",
"limit_byte_check",
")",
"return",
"encoding",
"except",
"(",
"LookupError",
",",
"SyntaxError",
",",
"UnicodeDecodeError",
")",
":",
"return",
"'latin-1'"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
_detect_encoding
|
Return file encoding.
|
autoflake.py
|
def _detect_encoding(readline):
"""Return file encoding."""
try:
from lib2to3.pgen2 import tokenize as lib2to3_tokenize
encoding = lib2to3_tokenize.detect_encoding(readline)[0]
return encoding
except (LookupError, SyntaxError, UnicodeDecodeError):
return 'latin-1'
|
def _detect_encoding(readline):
"""Return file encoding."""
try:
from lib2to3.pgen2 import tokenize as lib2to3_tokenize
encoding = lib2to3_tokenize.detect_encoding(readline)[0]
return encoding
except (LookupError, SyntaxError, UnicodeDecodeError):
return 'latin-1'
|
[
"Return",
"file",
"encoding",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L696-L703
|
[
"def",
"_detect_encoding",
"(",
"readline",
")",
":",
"try",
":",
"from",
"lib2to3",
".",
"pgen2",
"import",
"tokenize",
"as",
"lib2to3_tokenize",
"encoding",
"=",
"lib2to3_tokenize",
".",
"detect_encoding",
"(",
"readline",
")",
"[",
"0",
"]",
"return",
"encoding",
"except",
"(",
"LookupError",
",",
"SyntaxError",
",",
"UnicodeDecodeError",
")",
":",
"return",
"'latin-1'"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
_split_comma_separated
|
Return a set of strings.
|
autoflake.py
|
def _split_comma_separated(string):
"""Return a set of strings."""
return set(text.strip() for text in string.split(',') if text.strip())
|
def _split_comma_separated(string):
"""Return a set of strings."""
return set(text.strip() for text in string.split(',') if text.strip())
|
[
"Return",
"a",
"set",
"of",
"strings",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L726-L728
|
[
"def",
"_split_comma_separated",
"(",
"string",
")",
":",
"return",
"set",
"(",
"text",
".",
"strip",
"(",
")",
"for",
"text",
"in",
"string",
".",
"split",
"(",
"','",
")",
"if",
"text",
".",
"strip",
"(",
")",
")"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
is_python_file
|
Return True if filename is Python file.
|
autoflake.py
|
def is_python_file(filename):
"""Return True if filename is Python file."""
if filename.endswith('.py'):
return True
try:
with open_with_encoding(
filename,
None,
limit_byte_check=MAX_PYTHON_FILE_DETECTION_BYTES) as f:
text = f.read(MAX_PYTHON_FILE_DETECTION_BYTES)
if not text:
return False
first_line = text.splitlines()[0]
except (IOError, IndexError):
return False
if not PYTHON_SHEBANG_REGEX.match(first_line):
return False
return True
|
def is_python_file(filename):
"""Return True if filename is Python file."""
if filename.endswith('.py'):
return True
try:
with open_with_encoding(
filename,
None,
limit_byte_check=MAX_PYTHON_FILE_DETECTION_BYTES) as f:
text = f.read(MAX_PYTHON_FILE_DETECTION_BYTES)
if not text:
return False
first_line = text.splitlines()[0]
except (IOError, IndexError):
return False
if not PYTHON_SHEBANG_REGEX.match(first_line):
return False
return True
|
[
"Return",
"True",
"if",
"filename",
"is",
"Python",
"file",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L731-L751
|
[
"def",
"is_python_file",
"(",
"filename",
")",
":",
"if",
"filename",
".",
"endswith",
"(",
"'.py'",
")",
":",
"return",
"True",
"try",
":",
"with",
"open_with_encoding",
"(",
"filename",
",",
"None",
",",
"limit_byte_check",
"=",
"MAX_PYTHON_FILE_DETECTION_BYTES",
")",
"as",
"f",
":",
"text",
"=",
"f",
".",
"read",
"(",
"MAX_PYTHON_FILE_DETECTION_BYTES",
")",
"if",
"not",
"text",
":",
"return",
"False",
"first_line",
"=",
"text",
".",
"splitlines",
"(",
")",
"[",
"0",
"]",
"except",
"(",
"IOError",
",",
"IndexError",
")",
":",
"return",
"False",
"if",
"not",
"PYTHON_SHEBANG_REGEX",
".",
"match",
"(",
"first_line",
")",
":",
"return",
"False",
"return",
"True"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
is_exclude_file
|
Return True if file matches exclude pattern.
|
autoflake.py
|
def is_exclude_file(filename, exclude):
"""Return True if file matches exclude pattern."""
base_name = os.path.basename(filename)
if base_name.startswith('.'):
return True
for pattern in exclude:
if fnmatch.fnmatch(base_name, pattern):
return True
if fnmatch.fnmatch(filename, pattern):
return True
return False
|
def is_exclude_file(filename, exclude):
"""Return True if file matches exclude pattern."""
base_name = os.path.basename(filename)
if base_name.startswith('.'):
return True
for pattern in exclude:
if fnmatch.fnmatch(base_name, pattern):
return True
if fnmatch.fnmatch(filename, pattern):
return True
return False
|
[
"Return",
"True",
"if",
"file",
"matches",
"exclude",
"pattern",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L754-L766
|
[
"def",
"is_exclude_file",
"(",
"filename",
",",
"exclude",
")",
":",
"base_name",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"filename",
")",
"if",
"base_name",
".",
"startswith",
"(",
"'.'",
")",
":",
"return",
"True",
"for",
"pattern",
"in",
"exclude",
":",
"if",
"fnmatch",
".",
"fnmatch",
"(",
"base_name",
",",
"pattern",
")",
":",
"return",
"True",
"if",
"fnmatch",
".",
"fnmatch",
"(",
"filename",
",",
"pattern",
")",
":",
"return",
"True",
"return",
"False"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
match_file
|
Return True if file is okay for modifying/recursing.
|
autoflake.py
|
def match_file(filename, exclude):
"""Return True if file is okay for modifying/recursing."""
if is_exclude_file(filename, exclude):
return False
if not os.path.isdir(filename) and not is_python_file(filename):
return False
return True
|
def match_file(filename, exclude):
"""Return True if file is okay for modifying/recursing."""
if is_exclude_file(filename, exclude):
return False
if not os.path.isdir(filename) and not is_python_file(filename):
return False
return True
|
[
"Return",
"True",
"if",
"file",
"is",
"okay",
"for",
"modifying",
"/",
"recursing",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L769-L777
|
[
"def",
"match_file",
"(",
"filename",
",",
"exclude",
")",
":",
"if",
"is_exclude_file",
"(",
"filename",
",",
"exclude",
")",
":",
"return",
"False",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"filename",
")",
"and",
"not",
"is_python_file",
"(",
"filename",
")",
":",
"return",
"False",
"return",
"True"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
find_files
|
Yield filenames.
|
autoflake.py
|
def find_files(filenames, recursive, exclude):
"""Yield filenames."""
while filenames:
name = filenames.pop(0)
if recursive and os.path.isdir(name):
for root, directories, children in os.walk(name):
filenames += [os.path.join(root, f) for f in children
if match_file(os.path.join(root, f),
exclude)]
directories[:] = [d for d in directories
if match_file(os.path.join(root, d),
exclude)]
else:
if not is_exclude_file(name, exclude):
yield name
|
def find_files(filenames, recursive, exclude):
"""Yield filenames."""
while filenames:
name = filenames.pop(0)
if recursive and os.path.isdir(name):
for root, directories, children in os.walk(name):
filenames += [os.path.join(root, f) for f in children
if match_file(os.path.join(root, f),
exclude)]
directories[:] = [d for d in directories
if match_file(os.path.join(root, d),
exclude)]
else:
if not is_exclude_file(name, exclude):
yield name
|
[
"Yield",
"filenames",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L780-L794
|
[
"def",
"find_files",
"(",
"filenames",
",",
"recursive",
",",
"exclude",
")",
":",
"while",
"filenames",
":",
"name",
"=",
"filenames",
".",
"pop",
"(",
"0",
")",
"if",
"recursive",
"and",
"os",
".",
"path",
".",
"isdir",
"(",
"name",
")",
":",
"for",
"root",
",",
"directories",
",",
"children",
"in",
"os",
".",
"walk",
"(",
"name",
")",
":",
"filenames",
"+=",
"[",
"os",
".",
"path",
".",
"join",
"(",
"root",
",",
"f",
")",
"for",
"f",
"in",
"children",
"if",
"match_file",
"(",
"os",
".",
"path",
".",
"join",
"(",
"root",
",",
"f",
")",
",",
"exclude",
")",
"]",
"directories",
"[",
":",
"]",
"=",
"[",
"d",
"for",
"d",
"in",
"directories",
"if",
"match_file",
"(",
"os",
".",
"path",
".",
"join",
"(",
"root",
",",
"d",
")",
",",
"exclude",
")",
"]",
"else",
":",
"if",
"not",
"is_exclude_file",
"(",
"name",
",",
"exclude",
")",
":",
"yield",
"name"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
_main
|
Return exit status.
0 means no error.
|
autoflake.py
|
def _main(argv, standard_out, standard_error):
"""Return exit status.
0 means no error.
"""
import argparse
parser = argparse.ArgumentParser(description=__doc__, prog='autoflake')
parser.add_argument('-c', '--check', action='store_true',
help='return error code if changes are needed')
parser.add_argument('-i', '--in-place', action='store_true',
help='make changes to files instead of printing diffs')
parser.add_argument('-r', '--recursive', action='store_true',
help='drill down directories recursively')
parser.add_argument('--exclude', metavar='globs',
help='exclude file/directory names that match these '
'comma-separated globs')
parser.add_argument('--imports',
help='by default, only unused standard library '
'imports are removed; specify a comma-separated '
'list of additional modules/packages')
parser.add_argument('--expand-star-imports', action='store_true',
help='expand wildcard star imports with undefined '
'names; this only triggers if there is only '
'one star import in the file; this is skipped if '
'there are any uses of `__all__` or `del` in the '
'file')
parser.add_argument('--remove-all-unused-imports', action='store_true',
help='remove all unused imports (not just those from '
'the standard library)')
parser.add_argument('--ignore-init-module-imports', action='store_true',
help='exclude __init__.py when removing unused '
'imports')
parser.add_argument('--remove-duplicate-keys', action='store_true',
help='remove all duplicate keys in objects')
parser.add_argument('--remove-unused-variables', action='store_true',
help='remove unused variables')
parser.add_argument('--version', action='version',
version='%(prog)s ' + __version__)
parser.add_argument('files', nargs='+', help='files to format')
args = parser.parse_args(argv[1:])
if args.remove_all_unused_imports and args.imports:
print('Using both --remove-all and --imports is redundant',
file=standard_error)
return 1
if args.exclude:
args.exclude = _split_comma_separated(args.exclude)
else:
args.exclude = set([])
filenames = list(set(args.files))
failure = False
for name in find_files(filenames, args.recursive, args.exclude):
try:
fix_file(name, args=args, standard_out=standard_out)
except IOError as exception:
print(unicode(exception), file=standard_error)
failure = True
return 1 if failure else 0
|
def _main(argv, standard_out, standard_error):
"""Return exit status.
0 means no error.
"""
import argparse
parser = argparse.ArgumentParser(description=__doc__, prog='autoflake')
parser.add_argument('-c', '--check', action='store_true',
help='return error code if changes are needed')
parser.add_argument('-i', '--in-place', action='store_true',
help='make changes to files instead of printing diffs')
parser.add_argument('-r', '--recursive', action='store_true',
help='drill down directories recursively')
parser.add_argument('--exclude', metavar='globs',
help='exclude file/directory names that match these '
'comma-separated globs')
parser.add_argument('--imports',
help='by default, only unused standard library '
'imports are removed; specify a comma-separated '
'list of additional modules/packages')
parser.add_argument('--expand-star-imports', action='store_true',
help='expand wildcard star imports with undefined '
'names; this only triggers if there is only '
'one star import in the file; this is skipped if '
'there are any uses of `__all__` or `del` in the '
'file')
parser.add_argument('--remove-all-unused-imports', action='store_true',
help='remove all unused imports (not just those from '
'the standard library)')
parser.add_argument('--ignore-init-module-imports', action='store_true',
help='exclude __init__.py when removing unused '
'imports')
parser.add_argument('--remove-duplicate-keys', action='store_true',
help='remove all duplicate keys in objects')
parser.add_argument('--remove-unused-variables', action='store_true',
help='remove unused variables')
parser.add_argument('--version', action='version',
version='%(prog)s ' + __version__)
parser.add_argument('files', nargs='+', help='files to format')
args = parser.parse_args(argv[1:])
if args.remove_all_unused_imports and args.imports:
print('Using both --remove-all and --imports is redundant',
file=standard_error)
return 1
if args.exclude:
args.exclude = _split_comma_separated(args.exclude)
else:
args.exclude = set([])
filenames = list(set(args.files))
failure = False
for name in find_files(filenames, args.recursive, args.exclude):
try:
fix_file(name, args=args, standard_out=standard_out)
except IOError as exception:
print(unicode(exception), file=standard_error)
failure = True
return 1 if failure else 0
|
[
"Return",
"exit",
"status",
"."
] |
myint/autoflake
|
python
|
https://github.com/myint/autoflake/blob/68fea68646922b920d55975f9f2adaeafd84df4f/autoflake.py#L797-L858
|
[
"def",
"_main",
"(",
"argv",
",",
"standard_out",
",",
"standard_error",
")",
":",
"import",
"argparse",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"__doc__",
",",
"prog",
"=",
"'autoflake'",
")",
"parser",
".",
"add_argument",
"(",
"'-c'",
",",
"'--check'",
",",
"action",
"=",
"'store_true'",
",",
"help",
"=",
"'return error code if changes are needed'",
")",
"parser",
".",
"add_argument",
"(",
"'-i'",
",",
"'--in-place'",
",",
"action",
"=",
"'store_true'",
",",
"help",
"=",
"'make changes to files instead of printing diffs'",
")",
"parser",
".",
"add_argument",
"(",
"'-r'",
",",
"'--recursive'",
",",
"action",
"=",
"'store_true'",
",",
"help",
"=",
"'drill down directories recursively'",
")",
"parser",
".",
"add_argument",
"(",
"'--exclude'",
",",
"metavar",
"=",
"'globs'",
",",
"help",
"=",
"'exclude file/directory names that match these '",
"'comma-separated globs'",
")",
"parser",
".",
"add_argument",
"(",
"'--imports'",
",",
"help",
"=",
"'by default, only unused standard library '",
"'imports are removed; specify a comma-separated '",
"'list of additional modules/packages'",
")",
"parser",
".",
"add_argument",
"(",
"'--expand-star-imports'",
",",
"action",
"=",
"'store_true'",
",",
"help",
"=",
"'expand wildcard star imports with undefined '",
"'names; this only triggers if there is only '",
"'one star import in the file; this is skipped if '",
"'there are any uses of `__all__` or `del` in the '",
"'file'",
")",
"parser",
".",
"add_argument",
"(",
"'--remove-all-unused-imports'",
",",
"action",
"=",
"'store_true'",
",",
"help",
"=",
"'remove all unused imports (not just those from '",
"'the standard library)'",
")",
"parser",
".",
"add_argument",
"(",
"'--ignore-init-module-imports'",
",",
"action",
"=",
"'store_true'",
",",
"help",
"=",
"'exclude __init__.py when removing unused '",
"'imports'",
")",
"parser",
".",
"add_argument",
"(",
"'--remove-duplicate-keys'",
",",
"action",
"=",
"'store_true'",
",",
"help",
"=",
"'remove all duplicate keys in objects'",
")",
"parser",
".",
"add_argument",
"(",
"'--remove-unused-variables'",
",",
"action",
"=",
"'store_true'",
",",
"help",
"=",
"'remove unused variables'",
")",
"parser",
".",
"add_argument",
"(",
"'--version'",
",",
"action",
"=",
"'version'",
",",
"version",
"=",
"'%(prog)s '",
"+",
"__version__",
")",
"parser",
".",
"add_argument",
"(",
"'files'",
",",
"nargs",
"=",
"'+'",
",",
"help",
"=",
"'files to format'",
")",
"args",
"=",
"parser",
".",
"parse_args",
"(",
"argv",
"[",
"1",
":",
"]",
")",
"if",
"args",
".",
"remove_all_unused_imports",
"and",
"args",
".",
"imports",
":",
"print",
"(",
"'Using both --remove-all and --imports is redundant'",
",",
"file",
"=",
"standard_error",
")",
"return",
"1",
"if",
"args",
".",
"exclude",
":",
"args",
".",
"exclude",
"=",
"_split_comma_separated",
"(",
"args",
".",
"exclude",
")",
"else",
":",
"args",
".",
"exclude",
"=",
"set",
"(",
"[",
"]",
")",
"filenames",
"=",
"list",
"(",
"set",
"(",
"args",
".",
"files",
")",
")",
"failure",
"=",
"False",
"for",
"name",
"in",
"find_files",
"(",
"filenames",
",",
"args",
".",
"recursive",
",",
"args",
".",
"exclude",
")",
":",
"try",
":",
"fix_file",
"(",
"name",
",",
"args",
"=",
"args",
",",
"standard_out",
"=",
"standard_out",
")",
"except",
"IOError",
"as",
"exception",
":",
"print",
"(",
"unicode",
"(",
"exception",
")",
",",
"file",
"=",
"standard_error",
")",
"failure",
"=",
"True",
"return",
"1",
"if",
"failure",
"else",
"0"
] |
68fea68646922b920d55975f9f2adaeafd84df4f
|
test
|
ObtainLeaseResponsePayload.read
|
Read the data encoding the ObtainLease response payload and decode it
into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
|
kmip/core/messages/payloads/obtain_lease.py
|
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the ObtainLease response payload and decode it
into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
"""
super(ObtainLeaseResponsePayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.LEASE_TIME, local_stream):
self._lease_time = primitives.Interval(
tag=enums.Tags.LEASE_TIME
)
self._lease_time.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.LAST_CHANGE_DATE, local_stream):
self._last_change_date = primitives.DateTime(
tag=enums.Tags.LAST_CHANGE_DATE
)
self._last_change_date.read(
local_stream,
kmip_version=kmip_version
)
self.is_oversized(local_stream)
|
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the ObtainLease response payload and decode it
into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
"""
super(ObtainLeaseResponsePayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.LEASE_TIME, local_stream):
self._lease_time = primitives.Interval(
tag=enums.Tags.LEASE_TIME
)
self._lease_time.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.LAST_CHANGE_DATE, local_stream):
self._last_change_date = primitives.DateTime(
tag=enums.Tags.LAST_CHANGE_DATE
)
self._last_change_date.read(
local_stream,
kmip_version=kmip_version
)
self.is_oversized(local_stream)
|
[
"Read",
"the",
"data",
"encoding",
"the",
"ObtainLease",
"response",
"payload",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/obtain_lease.py#L254-L299
|
[
"def",
"read",
"(",
"self",
",",
"input_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"ObtainLeaseResponsePayload",
",",
"self",
")",
".",
"read",
"(",
"input_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"local_stream",
"=",
"utils",
".",
"BytearrayStream",
"(",
"input_stream",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"UNIQUE_IDENTIFIER",
",",
"local_stream",
")",
":",
"self",
".",
"_unique_identifier",
"=",
"primitives",
".",
"TextString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"UNIQUE_IDENTIFIER",
")",
"self",
".",
"_unique_identifier",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"LEASE_TIME",
",",
"local_stream",
")",
":",
"self",
".",
"_lease_time",
"=",
"primitives",
".",
"Interval",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"LEASE_TIME",
")",
"self",
".",
"_lease_time",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"LAST_CHANGE_DATE",
",",
"local_stream",
")",
":",
"self",
".",
"_last_change_date",
"=",
"primitives",
".",
"DateTime",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"LAST_CHANGE_DATE",
")",
"self",
".",
"_last_change_date",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"is_oversized",
"(",
"local_stream",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
ObtainLeaseResponsePayload.write
|
Write the data encoding the ObtainLease response payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is not defined.
|
kmip/core/messages/payloads/obtain_lease.py
|
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the ObtainLease response payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is not defined.
"""
local_stream = utils.BytearrayStream()
if self._unique_identifier:
self._unique_identifier.write(
local_stream,
kmip_version=kmip_version
)
if self._lease_time:
self._lease_time.write(
local_stream,
kmip_version=kmip_version
)
if self._last_change_date:
self._last_change_date.write(
local_stream,
kmip_version=kmip_version
)
self.length = local_stream.length()
super(ObtainLeaseResponsePayload, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
|
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the ObtainLease response payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is not defined.
"""
local_stream = utils.BytearrayStream()
if self._unique_identifier:
self._unique_identifier.write(
local_stream,
kmip_version=kmip_version
)
if self._lease_time:
self._lease_time.write(
local_stream,
kmip_version=kmip_version
)
if self._last_change_date:
self._last_change_date.write(
local_stream,
kmip_version=kmip_version
)
self.length = local_stream.length()
super(ObtainLeaseResponsePayload, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
|
[
"Write",
"the",
"data",
"encoding",
"the",
"ObtainLease",
"response",
"payload",
"to",
"a",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/obtain_lease.py#L301-L339
|
[
"def",
"write",
"(",
"self",
",",
"output_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"local_stream",
"=",
"utils",
".",
"BytearrayStream",
"(",
")",
"if",
"self",
".",
"_unique_identifier",
":",
"self",
".",
"_unique_identifier",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_lease_time",
":",
"self",
".",
"_lease_time",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_last_change_date",
":",
"self",
".",
"_last_change_date",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"length",
"=",
"local_stream",
".",
"length",
"(",
")",
"super",
"(",
"ObtainLeaseResponsePayload",
",",
"self",
")",
".",
"write",
"(",
"output_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"output_stream",
".",
"write",
"(",
"local_stream",
".",
"buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
CancelRequestPayload.write
|
Write the data encoding the Cancel request payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is not defined.
|
kmip/core/messages/payloads/cancel.py
|
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Cancel request payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is not defined.
"""
local_stream = utils.BytearrayStream()
if self._asynchronous_correlation_value:
self._asynchronous_correlation_value.write(
local_stream,
kmip_version=kmip_version
)
self.length = local_stream.length()
super(CancelRequestPayload, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
|
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Cancel request payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is not defined.
"""
local_stream = utils.BytearrayStream()
if self._asynchronous_correlation_value:
self._asynchronous_correlation_value.write(
local_stream,
kmip_version=kmip_version
)
self.length = local_stream.length()
super(CancelRequestPayload, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
|
[
"Write",
"the",
"data",
"encoding",
"the",
"Cancel",
"request",
"payload",
"to",
"a",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/cancel.py#L103-L131
|
[
"def",
"write",
"(",
"self",
",",
"output_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"local_stream",
"=",
"utils",
".",
"BytearrayStream",
"(",
")",
"if",
"self",
".",
"_asynchronous_correlation_value",
":",
"self",
".",
"_asynchronous_correlation_value",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"length",
"=",
"local_stream",
".",
"length",
"(",
")",
"super",
"(",
"CancelRequestPayload",
",",
"self",
")",
".",
"write",
"(",
"output_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"output_stream",
".",
"write",
"(",
"local_stream",
".",
"buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
CancelResponsePayload.read
|
Read the data encoding the Cancel response payload and decode it into
its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
|
kmip/core/messages/payloads/cancel.py
|
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Cancel response payload and decode it into
its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
"""
super(CancelResponsePayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(
enums.Tags.ASYNCHRONOUS_CORRELATION_VALUE,
local_stream
):
self._asynchronous_correlation_value = primitives.ByteString(
tag=enums.Tags.ASYNCHRONOUS_CORRELATION_VALUE
)
self._asynchronous_correlation_value.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.CANCELLATION_RESULT, local_stream):
self._cancellation_result = primitives.Enumeration(
enums.CancellationResult,
tag=enums.Tags.CANCELLATION_RESULT
)
self._cancellation_result.read(
local_stream,
kmip_version=kmip_version
)
self.is_oversized(local_stream)
|
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Cancel response payload and decode it into
its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
"""
super(CancelResponsePayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(
enums.Tags.ASYNCHRONOUS_CORRELATION_VALUE,
local_stream
):
self._asynchronous_correlation_value = primitives.ByteString(
tag=enums.Tags.ASYNCHRONOUS_CORRELATION_VALUE
)
self._asynchronous_correlation_value.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.CANCELLATION_RESULT, local_stream):
self._cancellation_result = primitives.Enumeration(
enums.CancellationResult,
tag=enums.Tags.CANCELLATION_RESULT
)
self._cancellation_result.read(
local_stream,
kmip_version=kmip_version
)
self.is_oversized(local_stream)
|
[
"Read",
"the",
"data",
"encoding",
"the",
"Cancel",
"response",
"payload",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/cancel.py#L237-L281
|
[
"def",
"read",
"(",
"self",
",",
"input_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"CancelResponsePayload",
",",
"self",
")",
".",
"read",
"(",
"input_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"local_stream",
"=",
"utils",
".",
"BytearrayStream",
"(",
"input_stream",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"ASYNCHRONOUS_CORRELATION_VALUE",
",",
"local_stream",
")",
":",
"self",
".",
"_asynchronous_correlation_value",
"=",
"primitives",
".",
"ByteString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"ASYNCHRONOUS_CORRELATION_VALUE",
")",
"self",
".",
"_asynchronous_correlation_value",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"CANCELLATION_RESULT",
",",
"local_stream",
")",
":",
"self",
".",
"_cancellation_result",
"=",
"primitives",
".",
"Enumeration",
"(",
"enums",
".",
"CancellationResult",
",",
"tag",
"=",
"enums",
".",
"Tags",
".",
"CANCELLATION_RESULT",
")",
"self",
".",
"_cancellation_result",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"is_oversized",
"(",
"local_stream",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
Name.create
|
Returns a Name object, populated with the given value and type
|
kmip/core/attributes.py
|
def create(cls, name_value, name_type):
'''
Returns a Name object, populated with the given value and type
'''
if isinstance(name_value, Name.NameValue):
value = name_value
elif isinstance(name_value, str):
value = cls.NameValue(name_value)
else:
name = 'Name'
msg = exceptions.ErrorStrings.BAD_EXP_RECV
member = 'name_value'
raise TypeError(msg.format('{0}.{1}'.format(name, member),
'name_value', type(Name.NameValue),
type(name_value)))
if isinstance(name_type, Name.NameType):
n_type = name_type
elif isinstance(name_type, Enum):
n_type = cls.NameType(name_type)
else:
name = 'Name'
msg = exceptions.ErrorStrings.BAD_EXP_RECV
member = 'name_type'
raise TypeError(msg.format('{0}.{1}'.format(name, member),
'name_type', type(Name.NameType),
type(name_type)))
return Name(name_value=value,
name_type=n_type)
|
def create(cls, name_value, name_type):
'''
Returns a Name object, populated with the given value and type
'''
if isinstance(name_value, Name.NameValue):
value = name_value
elif isinstance(name_value, str):
value = cls.NameValue(name_value)
else:
name = 'Name'
msg = exceptions.ErrorStrings.BAD_EXP_RECV
member = 'name_value'
raise TypeError(msg.format('{0}.{1}'.format(name, member),
'name_value', type(Name.NameValue),
type(name_value)))
if isinstance(name_type, Name.NameType):
n_type = name_type
elif isinstance(name_type, Enum):
n_type = cls.NameType(name_type)
else:
name = 'Name'
msg = exceptions.ErrorStrings.BAD_EXP_RECV
member = 'name_type'
raise TypeError(msg.format('{0}.{1}'.format(name, member),
'name_type', type(Name.NameType),
type(name_type)))
return Name(name_value=value,
name_type=n_type)
|
[
"Returns",
"a",
"Name",
"object",
"populated",
"with",
"the",
"given",
"value",
"and",
"type"
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/attributes.py#L157-L186
|
[
"def",
"create",
"(",
"cls",
",",
"name_value",
",",
"name_type",
")",
":",
"if",
"isinstance",
"(",
"name_value",
",",
"Name",
".",
"NameValue",
")",
":",
"value",
"=",
"name_value",
"elif",
"isinstance",
"(",
"name_value",
",",
"str",
")",
":",
"value",
"=",
"cls",
".",
"NameValue",
"(",
"name_value",
")",
"else",
":",
"name",
"=",
"'Name'",
"msg",
"=",
"exceptions",
".",
"ErrorStrings",
".",
"BAD_EXP_RECV",
"member",
"=",
"'name_value'",
"raise",
"TypeError",
"(",
"msg",
".",
"format",
"(",
"'{0}.{1}'",
".",
"format",
"(",
"name",
",",
"member",
")",
",",
"'name_value'",
",",
"type",
"(",
"Name",
".",
"NameValue",
")",
",",
"type",
"(",
"name_value",
")",
")",
")",
"if",
"isinstance",
"(",
"name_type",
",",
"Name",
".",
"NameType",
")",
":",
"n_type",
"=",
"name_type",
"elif",
"isinstance",
"(",
"name_type",
",",
"Enum",
")",
":",
"n_type",
"=",
"cls",
".",
"NameType",
"(",
"name_type",
")",
"else",
":",
"name",
"=",
"'Name'",
"msg",
"=",
"exceptions",
".",
"ErrorStrings",
".",
"BAD_EXP_RECV",
"member",
"=",
"'name_type'",
"raise",
"TypeError",
"(",
"msg",
".",
"format",
"(",
"'{0}.{1}'",
".",
"format",
"(",
"name",
",",
"member",
")",
",",
"'name_type'",
",",
"type",
"(",
"Name",
".",
"NameType",
")",
",",
"type",
"(",
"name_type",
")",
")",
")",
"return",
"Name",
"(",
"name_value",
"=",
"value",
",",
"name_type",
"=",
"n_type",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
Digest.read
|
Read the data encoding the Digest object and decode it into its
constituent parts.
Args:
istream (Stream): A data stream containing encoded object data,
supporting a read method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/attributes.py
|
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Digest object and decode it into its
constituent parts.
Args:
istream (Stream): A data stream containing encoded object data,
supporting a read method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(Digest, self).read(istream, kmip_version=kmip_version)
tstream = BytearrayStream(istream.read(self.length))
self.hashing_algorithm.read(tstream, kmip_version=kmip_version)
self.digest_value.read(tstream, kmip_version=kmip_version)
self.key_format_type.read(tstream, kmip_version=kmip_version)
self.is_oversized(tstream)
self.validate()
|
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Digest object and decode it into its
constituent parts.
Args:
istream (Stream): A data stream containing encoded object data,
supporting a read method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(Digest, self).read(istream, kmip_version=kmip_version)
tstream = BytearrayStream(istream.read(self.length))
self.hashing_algorithm.read(tstream, kmip_version=kmip_version)
self.digest_value.read(tstream, kmip_version=kmip_version)
self.key_format_type.read(tstream, kmip_version=kmip_version)
self.is_oversized(tstream)
self.validate()
|
[
"Read",
"the",
"data",
"encoding",
"the",
"Digest",
"object",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/attributes.py#L899-L919
|
[
"def",
"read",
"(",
"self",
",",
"istream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"Digest",
",",
"self",
")",
".",
"read",
"(",
"istream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"tstream",
"=",
"BytearrayStream",
"(",
"istream",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"self",
".",
"hashing_algorithm",
".",
"read",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"digest_value",
".",
"read",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"key_format_type",
".",
"read",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"is_oversized",
"(",
"tstream",
")",
"self",
".",
"validate",
"(",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
Digest.write
|
Write the data encoding the Digest object to a stream.
Args:
ostream (Stream): A data stream in which to encode object data,
supporting a write method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/attributes.py
|
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Digest object to a stream.
Args:
ostream (Stream): A data stream in which to encode object data,
supporting a write method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
tstream = BytearrayStream()
self.hashing_algorithm.write(tstream, kmip_version=kmip_version)
self.digest_value.write(tstream, kmip_version=kmip_version)
self.key_format_type.write(tstream, kmip_version=kmip_version)
self.length = tstream.length()
super(Digest, self).write(ostream, kmip_version=kmip_version)
ostream.write(tstream.buffer)
|
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Digest object to a stream.
Args:
ostream (Stream): A data stream in which to encode object data,
supporting a write method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
tstream = BytearrayStream()
self.hashing_algorithm.write(tstream, kmip_version=kmip_version)
self.digest_value.write(tstream, kmip_version=kmip_version)
self.key_format_type.write(tstream, kmip_version=kmip_version)
self.length = tstream.length()
super(Digest, self).write(ostream, kmip_version=kmip_version)
ostream.write(tstream.buffer)
|
[
"Write",
"the",
"data",
"encoding",
"the",
"Digest",
"object",
"to",
"a",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/attributes.py#L921-L940
|
[
"def",
"write",
"(",
"self",
",",
"ostream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"tstream",
"=",
"BytearrayStream",
"(",
")",
"self",
".",
"hashing_algorithm",
".",
"write",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"digest_value",
".",
"write",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"key_format_type",
".",
"write",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"length",
"=",
"tstream",
".",
"length",
"(",
")",
"super",
"(",
"Digest",
",",
"self",
")",
".",
"write",
"(",
"ostream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"ostream",
".",
"write",
"(",
"tstream",
".",
"buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
Digest.create
|
Construct a Digest object from provided digest values.
Args:
hashing_algorithm (HashingAlgorithm): An enumeration representing
the hash algorithm used to compute the digest. Optional,
defaults to HashingAlgorithm.SHA_256.
digest_value (byte string): The bytes of the digest hash. Optional,
defaults to the empty byte string.
key_format_type (KeyFormatType): An enumeration representing the
format of the key corresponding to the digest. Optional,
defaults to KeyFormatType.RAW.
Returns:
Digest: The newly created Digest.
Example:
>>> x = Digest.create(HashingAlgorithm.MD5, b'\x00',
... KeyFormatType.RAW)
>>> x.hashing_algorithm
HashingAlgorithm(value=HashingAlgorithm.MD5)
>>> x.digest_value
DigestValue(value=bytearray(b'\x00'))
>>> x.key_format_type
KeyFormatType(value=KeyFormatType.RAW)
|
kmip/core/attributes.py
|
def create(cls,
hashing_algorithm=HashingAlgorithmEnum.SHA_256,
digest_value=b'',
key_format_type=KeyFormatTypeEnum.RAW):
"""
Construct a Digest object from provided digest values.
Args:
hashing_algorithm (HashingAlgorithm): An enumeration representing
the hash algorithm used to compute the digest. Optional,
defaults to HashingAlgorithm.SHA_256.
digest_value (byte string): The bytes of the digest hash. Optional,
defaults to the empty byte string.
key_format_type (KeyFormatType): An enumeration representing the
format of the key corresponding to the digest. Optional,
defaults to KeyFormatType.RAW.
Returns:
Digest: The newly created Digest.
Example:
>>> x = Digest.create(HashingAlgorithm.MD5, b'\x00',
... KeyFormatType.RAW)
>>> x.hashing_algorithm
HashingAlgorithm(value=HashingAlgorithm.MD5)
>>> x.digest_value
DigestValue(value=bytearray(b'\x00'))
>>> x.key_format_type
KeyFormatType(value=KeyFormatType.RAW)
"""
algorithm = HashingAlgorithm(hashing_algorithm)
value = DigestValue(bytearray(digest_value))
format_type = KeyFormatType(key_format_type)
return Digest(hashing_algorithm=algorithm,
digest_value=value,
key_format_type=format_type)
|
def create(cls,
hashing_algorithm=HashingAlgorithmEnum.SHA_256,
digest_value=b'',
key_format_type=KeyFormatTypeEnum.RAW):
"""
Construct a Digest object from provided digest values.
Args:
hashing_algorithm (HashingAlgorithm): An enumeration representing
the hash algorithm used to compute the digest. Optional,
defaults to HashingAlgorithm.SHA_256.
digest_value (byte string): The bytes of the digest hash. Optional,
defaults to the empty byte string.
key_format_type (KeyFormatType): An enumeration representing the
format of the key corresponding to the digest. Optional,
defaults to KeyFormatType.RAW.
Returns:
Digest: The newly created Digest.
Example:
>>> x = Digest.create(HashingAlgorithm.MD5, b'\x00',
... KeyFormatType.RAW)
>>> x.hashing_algorithm
HashingAlgorithm(value=HashingAlgorithm.MD5)
>>> x.digest_value
DigestValue(value=bytearray(b'\x00'))
>>> x.key_format_type
KeyFormatType(value=KeyFormatType.RAW)
"""
algorithm = HashingAlgorithm(hashing_algorithm)
value = DigestValue(bytearray(digest_value))
format_type = KeyFormatType(key_format_type)
return Digest(hashing_algorithm=algorithm,
digest_value=value,
key_format_type=format_type)
|
[
"Construct",
"a",
"Digest",
"object",
"from",
"provided",
"digest",
"values",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/attributes.py#L1003-L1039
|
[
"def",
"create",
"(",
"cls",
",",
"hashing_algorithm",
"=",
"HashingAlgorithmEnum",
".",
"SHA_256",
",",
"digest_value",
"=",
"b''",
",",
"key_format_type",
"=",
"KeyFormatTypeEnum",
".",
"RAW",
")",
":",
"algorithm",
"=",
"HashingAlgorithm",
"(",
"hashing_algorithm",
")",
"value",
"=",
"DigestValue",
"(",
"bytearray",
"(",
"digest_value",
")",
")",
"format_type",
"=",
"KeyFormatType",
"(",
"key_format_type",
")",
"return",
"Digest",
"(",
"hashing_algorithm",
"=",
"algorithm",
",",
"digest_value",
"=",
"value",
",",
"key_format_type",
"=",
"format_type",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
ApplicationSpecificInformation.read
|
Read the data encoding the ApplicationSpecificInformation object and
decode it into its constituent parts.
Args:
istream (Stream): A data stream containing encoded object data,
supporting a read method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/attributes.py
|
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the ApplicationSpecificInformation object and
decode it into its constituent parts.
Args:
istream (Stream): A data stream containing encoded object data,
supporting a read method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(ApplicationSpecificInformation, self).read(
istream,
kmip_version=kmip_version
)
tstream = BytearrayStream(istream.read(self.length))
self.application_namespace.read(tstream, kmip_version=kmip_version)
self.application_data.read(tstream, kmip_version=kmip_version)
self.is_oversized(tstream)
self.validate()
|
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the ApplicationSpecificInformation object and
decode it into its constituent parts.
Args:
istream (Stream): A data stream containing encoded object data,
supporting a read method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(ApplicationSpecificInformation, self).read(
istream,
kmip_version=kmip_version
)
tstream = BytearrayStream(istream.read(self.length))
self.application_namespace.read(tstream, kmip_version=kmip_version)
self.application_data.read(tstream, kmip_version=kmip_version)
self.is_oversized(tstream)
self.validate()
|
[
"Read",
"the",
"data",
"encoding",
"the",
"ApplicationSpecificInformation",
"object",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/attributes.py#L1154-L1176
|
[
"def",
"read",
"(",
"self",
",",
"istream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"ApplicationSpecificInformation",
",",
"self",
")",
".",
"read",
"(",
"istream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"tstream",
"=",
"BytearrayStream",
"(",
"istream",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"self",
".",
"application_namespace",
".",
"read",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"application_data",
".",
"read",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"is_oversized",
"(",
"tstream",
")",
"self",
".",
"validate",
"(",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
ApplicationSpecificInformation.write
|
Write the data encoding the ApplicationSpecificInformation object to a
stream.
Args:
ostream (Stream): A data stream in which to encode object data,
supporting a write method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/attributes.py
|
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the ApplicationSpecificInformation object to a
stream.
Args:
ostream (Stream): A data stream in which to encode object data,
supporting a write method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
tstream = BytearrayStream()
self.application_namespace.write(tstream, kmip_version=kmip_version)
self.application_data.write(tstream, kmip_version=kmip_version)
self.length = tstream.length()
super(ApplicationSpecificInformation, self).write(
ostream,
kmip_version=kmip_version
)
ostream.write(tstream.buffer)
|
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the ApplicationSpecificInformation object to a
stream.
Args:
ostream (Stream): A data stream in which to encode object data,
supporting a write method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
tstream = BytearrayStream()
self.application_namespace.write(tstream, kmip_version=kmip_version)
self.application_data.write(tstream, kmip_version=kmip_version)
self.length = tstream.length()
super(ApplicationSpecificInformation, self).write(
ostream,
kmip_version=kmip_version
)
ostream.write(tstream.buffer)
|
[
"Write",
"the",
"data",
"encoding",
"the",
"ApplicationSpecificInformation",
"object",
"to",
"a",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/attributes.py#L1178-L1200
|
[
"def",
"write",
"(",
"self",
",",
"ostream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"tstream",
"=",
"BytearrayStream",
"(",
")",
"self",
".",
"application_namespace",
".",
"write",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"application_data",
".",
"write",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"length",
"=",
"tstream",
".",
"length",
"(",
")",
"super",
"(",
"ApplicationSpecificInformation",
",",
"self",
")",
".",
"write",
"(",
"ostream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"ostream",
".",
"write",
"(",
"tstream",
".",
"buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
ApplicationSpecificInformation.create
|
Construct an ApplicationSpecificInformation object from provided data
and namespace values.
Args:
application_namespace (str): The name of the application namespace.
application_data (str): Application data related to the namespace.
Returns:
ApplicationSpecificInformation: The newly created set of
application information.
Example:
>>> x = ApplicationSpecificInformation.create('namespace', 'data')
>>> x.application_namespace.value
'namespace'
>>> x.application_data.value
'data'
|
kmip/core/attributes.py
|
def create(cls, application_namespace, application_data):
"""
Construct an ApplicationSpecificInformation object from provided data
and namespace values.
Args:
application_namespace (str): The name of the application namespace.
application_data (str): Application data related to the namespace.
Returns:
ApplicationSpecificInformation: The newly created set of
application information.
Example:
>>> x = ApplicationSpecificInformation.create('namespace', 'data')
>>> x.application_namespace.value
'namespace'
>>> x.application_data.value
'data'
"""
namespace = ApplicationNamespace(application_namespace)
data = ApplicationData(application_data)
return ApplicationSpecificInformation(
application_namespace=namespace, application_data=data)
|
def create(cls, application_namespace, application_data):
"""
Construct an ApplicationSpecificInformation object from provided data
and namespace values.
Args:
application_namespace (str): The name of the application namespace.
application_data (str): Application data related to the namespace.
Returns:
ApplicationSpecificInformation: The newly created set of
application information.
Example:
>>> x = ApplicationSpecificInformation.create('namespace', 'data')
>>> x.application_namespace.value
'namespace'
>>> x.application_data.value
'data'
"""
namespace = ApplicationNamespace(application_namespace)
data = ApplicationData(application_data)
return ApplicationSpecificInformation(
application_namespace=namespace, application_data=data)
|
[
"Construct",
"an",
"ApplicationSpecificInformation",
"object",
"from",
"provided",
"data",
"and",
"namespace",
"values",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/attributes.py#L1257-L1280
|
[
"def",
"create",
"(",
"cls",
",",
"application_namespace",
",",
"application_data",
")",
":",
"namespace",
"=",
"ApplicationNamespace",
"(",
"application_namespace",
")",
"data",
"=",
"ApplicationData",
"(",
"application_data",
")",
"return",
"ApplicationSpecificInformation",
"(",
"application_namespace",
"=",
"namespace",
",",
"application_data",
"=",
"data",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
DerivationParameters.read
|
Read the data encoding the DerivationParameters struct and decode it
into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/attributes.py
|
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the DerivationParameters struct and decode it
into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(DerivationParameters, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(
enums.Tags.CRYPTOGRAPHIC_PARAMETERS,
local_stream
):
self._cryptographic_parameters = CryptographicParameters()
self._cryptographic_parameters.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.INITIALIZATION_VECTOR, local_stream):
self._initialization_vector = ByteString(
tag=enums.Tags.INITIALIZATION_VECTOR
)
self._initialization_vector.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.DERIVATION_DATA, local_stream):
self._derivation_data = ByteString(tag=enums.Tags.DERIVATION_DATA)
self._derivation_data.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.SALT, local_stream):
self._salt = ByteString(tag=enums.Tags.SALT)
self._salt.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(Tags.ITERATION_COUNT, local_stream):
self._iteration_count = Integer(tag=Tags.ITERATION_COUNT)
self._iteration_count.read(local_stream, kmip_version=kmip_version)
self.is_oversized(local_stream)
|
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the DerivationParameters struct and decode it
into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(DerivationParameters, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(
enums.Tags.CRYPTOGRAPHIC_PARAMETERS,
local_stream
):
self._cryptographic_parameters = CryptographicParameters()
self._cryptographic_parameters.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.INITIALIZATION_VECTOR, local_stream):
self._initialization_vector = ByteString(
tag=enums.Tags.INITIALIZATION_VECTOR
)
self._initialization_vector.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.DERIVATION_DATA, local_stream):
self._derivation_data = ByteString(tag=enums.Tags.DERIVATION_DATA)
self._derivation_data.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.SALT, local_stream):
self._salt = ByteString(tag=enums.Tags.SALT)
self._salt.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(Tags.ITERATION_COUNT, local_stream):
self._iteration_count = Integer(tag=Tags.ITERATION_COUNT)
self._iteration_count.read(local_stream, kmip_version=kmip_version)
self.is_oversized(local_stream)
|
[
"Read",
"the",
"data",
"encoding",
"the",
"DerivationParameters",
"struct",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/attributes.py#L1443-L1493
|
[
"def",
"read",
"(",
"self",
",",
"input_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"DerivationParameters",
",",
"self",
")",
".",
"read",
"(",
"input_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"local_stream",
"=",
"BytearrayStream",
"(",
"input_stream",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"CRYPTOGRAPHIC_PARAMETERS",
",",
"local_stream",
")",
":",
"self",
".",
"_cryptographic_parameters",
"=",
"CryptographicParameters",
"(",
")",
"self",
".",
"_cryptographic_parameters",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"INITIALIZATION_VECTOR",
",",
"local_stream",
")",
":",
"self",
".",
"_initialization_vector",
"=",
"ByteString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"INITIALIZATION_VECTOR",
")",
"self",
".",
"_initialization_vector",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"DERIVATION_DATA",
",",
"local_stream",
")",
":",
"self",
".",
"_derivation_data",
"=",
"ByteString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"DERIVATION_DATA",
")",
"self",
".",
"_derivation_data",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"SALT",
",",
"local_stream",
")",
":",
"self",
".",
"_salt",
"=",
"ByteString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"SALT",
")",
"self",
".",
"_salt",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"Tags",
".",
"ITERATION_COUNT",
",",
"local_stream",
")",
":",
"self",
".",
"_iteration_count",
"=",
"Integer",
"(",
"tag",
"=",
"Tags",
".",
"ITERATION_COUNT",
")",
"self",
".",
"_iteration_count",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"is_oversized",
"(",
"local_stream",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
DerivationParameters.write
|
Write the data encoding the DerivationParameters struct to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/attributes.py
|
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the DerivationParameters struct to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_stream = BytearrayStream()
if self._cryptographic_parameters:
self._cryptographic_parameters.write(
local_stream,
kmip_version=kmip_version
)
if self._initialization_vector:
self._initialization_vector.write(
local_stream,
kmip_version=kmip_version
)
if self._derivation_data:
self._derivation_data.write(
local_stream,
kmip_version=kmip_version
)
if self._salt:
self._salt.write(
local_stream,
kmip_version=kmip_version
)
if self._iteration_count:
self._iteration_count.write(
local_stream,
kmip_version=kmip_version
)
self.length = local_stream.length()
super(DerivationParameters, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
|
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the DerivationParameters struct to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_stream = BytearrayStream()
if self._cryptographic_parameters:
self._cryptographic_parameters.write(
local_stream,
kmip_version=kmip_version
)
if self._initialization_vector:
self._initialization_vector.write(
local_stream,
kmip_version=kmip_version
)
if self._derivation_data:
self._derivation_data.write(
local_stream,
kmip_version=kmip_version
)
if self._salt:
self._salt.write(
local_stream,
kmip_version=kmip_version
)
if self._iteration_count:
self._iteration_count.write(
local_stream,
kmip_version=kmip_version
)
self.length = local_stream.length()
super(DerivationParameters, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
|
[
"Write",
"the",
"data",
"encoding",
"the",
"DerivationParameters",
"struct",
"to",
"a",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/attributes.py#L1495-L1540
|
[
"def",
"write",
"(",
"self",
",",
"output_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"local_stream",
"=",
"BytearrayStream",
"(",
")",
"if",
"self",
".",
"_cryptographic_parameters",
":",
"self",
".",
"_cryptographic_parameters",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_initialization_vector",
":",
"self",
".",
"_initialization_vector",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_derivation_data",
":",
"self",
".",
"_derivation_data",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_salt",
":",
"self",
".",
"_salt",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_iteration_count",
":",
"self",
".",
"_iteration_count",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"length",
"=",
"local_stream",
".",
"length",
"(",
")",
"super",
"(",
"DerivationParameters",
",",
"self",
")",
".",
"write",
"(",
"output_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"output_stream",
".",
"write",
"(",
"local_stream",
".",
"buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
GetRequestPayload.read
|
Read the data encoding the Get request payload and decode it into its
constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/messages/payloads/get.py
|
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Get request payload and decode it into its
constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(GetRequestPayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.KEY_FORMAT_TYPE, local_stream):
self._key_format_type = primitives.Enumeration(
enum=enums.KeyFormatType,
tag=enums.Tags.KEY_FORMAT_TYPE
)
self._key_format_type.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.KEY_COMPRESSION_TYPE, local_stream):
self._key_compression_type = primitives.Enumeration(
enum=enums.KeyCompressionType,
tag=enums.Tags.KEY_COMPRESSION_TYPE
)
self._key_compression_type.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(
enums.Tags.KEY_WRAPPING_SPECIFICATION,
local_stream
):
self._key_wrapping_specification = \
objects.KeyWrappingSpecification()
self._key_wrapping_specification.read(
local_stream,
kmip_version=kmip_version
)
self.is_oversized(local_stream)
|
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Get request payload and decode it into its
constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(GetRequestPayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.KEY_FORMAT_TYPE, local_stream):
self._key_format_type = primitives.Enumeration(
enum=enums.KeyFormatType,
tag=enums.Tags.KEY_FORMAT_TYPE
)
self._key_format_type.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.KEY_COMPRESSION_TYPE, local_stream):
self._key_compression_type = primitives.Enumeration(
enum=enums.KeyCompressionType,
tag=enums.Tags.KEY_COMPRESSION_TYPE
)
self._key_compression_type.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(
enums.Tags.KEY_WRAPPING_SPECIFICATION,
local_stream
):
self._key_wrapping_specification = \
objects.KeyWrappingSpecification()
self._key_wrapping_specification.read(
local_stream,
kmip_version=kmip_version
)
self.is_oversized(local_stream)
|
[
"Read",
"the",
"data",
"encoding",
"the",
"Get",
"request",
"payload",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/get.py#L159-L218
|
[
"def",
"read",
"(",
"self",
",",
"input_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"GetRequestPayload",
",",
"self",
")",
".",
"read",
"(",
"input_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"local_stream",
"=",
"utils",
".",
"BytearrayStream",
"(",
"input_stream",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"UNIQUE_IDENTIFIER",
",",
"local_stream",
")",
":",
"self",
".",
"_unique_identifier",
"=",
"primitives",
".",
"TextString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"UNIQUE_IDENTIFIER",
")",
"self",
".",
"_unique_identifier",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"KEY_FORMAT_TYPE",
",",
"local_stream",
")",
":",
"self",
".",
"_key_format_type",
"=",
"primitives",
".",
"Enumeration",
"(",
"enum",
"=",
"enums",
".",
"KeyFormatType",
",",
"tag",
"=",
"enums",
".",
"Tags",
".",
"KEY_FORMAT_TYPE",
")",
"self",
".",
"_key_format_type",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"KEY_COMPRESSION_TYPE",
",",
"local_stream",
")",
":",
"self",
".",
"_key_compression_type",
"=",
"primitives",
".",
"Enumeration",
"(",
"enum",
"=",
"enums",
".",
"KeyCompressionType",
",",
"tag",
"=",
"enums",
".",
"Tags",
".",
"KEY_COMPRESSION_TYPE",
")",
"self",
".",
"_key_compression_type",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"KEY_WRAPPING_SPECIFICATION",
",",
"local_stream",
")",
":",
"self",
".",
"_key_wrapping_specification",
"=",
"objects",
".",
"KeyWrappingSpecification",
"(",
")",
"self",
".",
"_key_wrapping_specification",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"is_oversized",
"(",
"local_stream",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
GetRequestPayload.write
|
Write the data encoding the Get request payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/messages/payloads/get.py
|
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Get request payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_stream = utils.BytearrayStream()
if self._unique_identifier is not None:
self._unique_identifier.write(
local_stream,
kmip_version=kmip_version
)
if self._key_format_type is not None:
self._key_format_type.write(
local_stream,
kmip_version=kmip_version
)
if self._key_compression_type is not None:
self._key_compression_type.write(
local_stream,
kmip_version=kmip_version
)
if self._key_wrapping_specification is not None:
self._key_wrapping_specification.write(
local_stream,
kmip_version=kmip_version
)
self.length = local_stream.length()
super(GetRequestPayload, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
|
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Get request payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_stream = utils.BytearrayStream()
if self._unique_identifier is not None:
self._unique_identifier.write(
local_stream,
kmip_version=kmip_version
)
if self._key_format_type is not None:
self._key_format_type.write(
local_stream,
kmip_version=kmip_version
)
if self._key_compression_type is not None:
self._key_compression_type.write(
local_stream,
kmip_version=kmip_version
)
if self._key_wrapping_specification is not None:
self._key_wrapping_specification.write(
local_stream,
kmip_version=kmip_version
)
self.length = local_stream.length()
super(GetRequestPayload, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
|
[
"Write",
"the",
"data",
"encoding",
"the",
"Get",
"request",
"payload",
"to",
"a",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/get.py#L220-L260
|
[
"def",
"write",
"(",
"self",
",",
"output_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"local_stream",
"=",
"utils",
".",
"BytearrayStream",
"(",
")",
"if",
"self",
".",
"_unique_identifier",
"is",
"not",
"None",
":",
"self",
".",
"_unique_identifier",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_key_format_type",
"is",
"not",
"None",
":",
"self",
".",
"_key_format_type",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_key_compression_type",
"is",
"not",
"None",
":",
"self",
".",
"_key_compression_type",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_key_wrapping_specification",
"is",
"not",
"None",
":",
"self",
".",
"_key_wrapping_specification",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"length",
"=",
"local_stream",
".",
"length",
"(",
")",
"super",
"(",
"GetRequestPayload",
",",
"self",
")",
".",
"write",
"(",
"output_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"output_stream",
".",
"write",
"(",
"local_stream",
".",
"buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
GetResponsePayload.read
|
Read the data encoding the Get response payload and decode it
into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the object type, unique identifier, or
secret attributes are missing from the encoded payload.
|
kmip/core/messages/payloads/get.py
|
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Get response payload and decode it
into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the object type, unique identifier, or
secret attributes are missing from the encoded payload.
"""
super(GetResponsePayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_stream):
self._object_type = primitives.Enumeration(
enum=enums.ObjectType,
tag=enums.Tags.OBJECT_TYPE
)
self._object_type.read(local_stream, kmip_version=kmip_version)
else:
raise ValueError(
"Parsed payload encoding is missing the object type field."
)
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
"Parsed payload encoding is missing the unique identifier "
"field."
)
self.secret = self.secret_factory.create(self.object_type)
if self.is_tag_next(self._secret.tag, local_stream):
self._secret.read(local_stream, kmip_version=kmip_version)
else:
raise ValueError(
"Parsed payload encoding is missing the secret field."
)
self.is_oversized(local_stream)
|
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the Get response payload and decode it
into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the object type, unique identifier, or
secret attributes are missing from the encoded payload.
"""
super(GetResponsePayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.OBJECT_TYPE, local_stream):
self._object_type = primitives.Enumeration(
enum=enums.ObjectType,
tag=enums.Tags.OBJECT_TYPE
)
self._object_type.read(local_stream, kmip_version=kmip_version)
else:
raise ValueError(
"Parsed payload encoding is missing the object type field."
)
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
"Parsed payload encoding is missing the unique identifier "
"field."
)
self.secret = self.secret_factory.create(self.object_type)
if self.is_tag_next(self._secret.tag, local_stream):
self._secret.read(local_stream, kmip_version=kmip_version)
else:
raise ValueError(
"Parsed payload encoding is missing the secret field."
)
self.is_oversized(local_stream)
|
[
"Read",
"the",
"data",
"encoding",
"the",
"Get",
"response",
"payload",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/get.py#L414-L470
|
[
"def",
"read",
"(",
"self",
",",
"input_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"GetResponsePayload",
",",
"self",
")",
".",
"read",
"(",
"input_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"local_stream",
"=",
"utils",
".",
"BytearrayStream",
"(",
"input_stream",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"OBJECT_TYPE",
",",
"local_stream",
")",
":",
"self",
".",
"_object_type",
"=",
"primitives",
".",
"Enumeration",
"(",
"enum",
"=",
"enums",
".",
"ObjectType",
",",
"tag",
"=",
"enums",
".",
"Tags",
".",
"OBJECT_TYPE",
")",
"self",
".",
"_object_type",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"ValueError",
"(",
"\"Parsed payload encoding is missing the object type field.\"",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"UNIQUE_IDENTIFIER",
",",
"local_stream",
")",
":",
"self",
".",
"_unique_identifier",
"=",
"primitives",
".",
"TextString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"UNIQUE_IDENTIFIER",
")",
"self",
".",
"_unique_identifier",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"ValueError",
"(",
"\"Parsed payload encoding is missing the unique identifier \"",
"\"field.\"",
")",
"self",
".",
"secret",
"=",
"self",
".",
"secret_factory",
".",
"create",
"(",
"self",
".",
"object_type",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"self",
".",
"_secret",
".",
"tag",
",",
"local_stream",
")",
":",
"self",
".",
"_secret",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"ValueError",
"(",
"\"Parsed payload encoding is missing the secret field.\"",
")",
"self",
".",
"is_oversized",
"(",
"local_stream",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
GetResponsePayload.write
|
Write the data encoding the Get response payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the object type, unique identifier, or
secret attributes are missing from the payload struct.
|
kmip/core/messages/payloads/get.py
|
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Get response payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the object type, unique identifier, or
secret attributes are missing from the payload struct.
"""
local_stream = utils.BytearrayStream()
if self.object_type:
self._object_type.write(local_stream, kmip_version=kmip_version)
else:
raise ValueError("Payload is missing the object type field.")
if self.unique_identifier:
self._unique_identifier.write(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
"Payload is missing the unique identifier field."
)
if self.secret:
self._secret.write(local_stream, kmip_version=kmip_version)
else:
raise ValueError("Payload is missing the secret field.")
self.length = local_stream.length()
super(GetResponsePayload, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
|
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Get response payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the object type, unique identifier, or
secret attributes are missing from the payload struct.
"""
local_stream = utils.BytearrayStream()
if self.object_type:
self._object_type.write(local_stream, kmip_version=kmip_version)
else:
raise ValueError("Payload is missing the object type field.")
if self.unique_identifier:
self._unique_identifier.write(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
"Payload is missing the unique identifier field."
)
if self.secret:
self._secret.write(local_stream, kmip_version=kmip_version)
else:
raise ValueError("Payload is missing the secret field.")
self.length = local_stream.length()
super(GetResponsePayload, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
|
[
"Write",
"the",
"data",
"encoding",
"the",
"Get",
"response",
"payload",
"to",
"a",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/get.py#L472-L515
|
[
"def",
"write",
"(",
"self",
",",
"output_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"local_stream",
"=",
"utils",
".",
"BytearrayStream",
"(",
")",
"if",
"self",
".",
"object_type",
":",
"self",
".",
"_object_type",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"ValueError",
"(",
"\"Payload is missing the object type field.\"",
")",
"if",
"self",
".",
"unique_identifier",
":",
"self",
".",
"_unique_identifier",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"ValueError",
"(",
"\"Payload is missing the unique identifier field.\"",
")",
"if",
"self",
".",
"secret",
":",
"self",
".",
"_secret",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"ValueError",
"(",
"\"Payload is missing the secret field.\"",
")",
"self",
".",
"length",
"=",
"local_stream",
".",
"length",
"(",
")",
"super",
"(",
"GetResponsePayload",
",",
"self",
")",
".",
"write",
"(",
"output_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"output_stream",
".",
"write",
"(",
"local_stream",
".",
"buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
SignatureVerifyRequestPayload.read
|
Read the data encoding the SignatureVerify request payload and decode
it into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
|
kmip/core/messages/payloads/signature_verify.py
|
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the SignatureVerify request payload and decode
it into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
"""
super(SignatureVerifyRequestPayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_PARAMETERS, local_stream):
self._cryptographic_parameters = \
attributes.CryptographicParameters()
self._cryptographic_parameters.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.DATA, local_stream):
self._data = primitives.ByteString(tag=enums.Tags.DATA)
self._data.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.DIGESTED_DATA, local_stream):
self._digested_data = primitives.ByteString(
tag=enums.Tags.DIGESTED_DATA
)
self._digested_data.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.SIGNATURE_DATA, local_stream):
self._signature_data = primitives.ByteString(
tag=enums.Tags.SIGNATURE_DATA
)
self._signature_data.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.CORRELATION_VALUE, local_stream):
self._correlation_value = primitives.ByteString(
tag=enums.Tags.CORRELATION_VALUE
)
self._correlation_value.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.INIT_INDICATOR, local_stream):
self._init_indicator = primitives.Boolean(
tag=enums.Tags.INIT_INDICATOR
)
self._init_indicator.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.FINAL_INDICATOR, local_stream):
self._final_indicator = primitives.Boolean(
tag=enums.Tags.FINAL_INDICATOR
)
self._final_indicator.read(local_stream, kmip_version=kmip_version)
self.is_oversized(local_stream)
|
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the SignatureVerify request payload and decode
it into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
"""
super(SignatureVerifyRequestPayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.CRYPTOGRAPHIC_PARAMETERS, local_stream):
self._cryptographic_parameters = \
attributes.CryptographicParameters()
self._cryptographic_parameters.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.DATA, local_stream):
self._data = primitives.ByteString(tag=enums.Tags.DATA)
self._data.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.DIGESTED_DATA, local_stream):
self._digested_data = primitives.ByteString(
tag=enums.Tags.DIGESTED_DATA
)
self._digested_data.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.SIGNATURE_DATA, local_stream):
self._signature_data = primitives.ByteString(
tag=enums.Tags.SIGNATURE_DATA
)
self._signature_data.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.CORRELATION_VALUE, local_stream):
self._correlation_value = primitives.ByteString(
tag=enums.Tags.CORRELATION_VALUE
)
self._correlation_value.read(
local_stream,
kmip_version=kmip_version
)
if self.is_tag_next(enums.Tags.INIT_INDICATOR, local_stream):
self._init_indicator = primitives.Boolean(
tag=enums.Tags.INIT_INDICATOR
)
self._init_indicator.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.FINAL_INDICATOR, local_stream):
self._final_indicator = primitives.Boolean(
tag=enums.Tags.FINAL_INDICATOR
)
self._final_indicator.read(local_stream, kmip_version=kmip_version)
self.is_oversized(local_stream)
|
[
"Read",
"the",
"data",
"encoding",
"the",
"SignatureVerify",
"request",
"payload",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/signature_verify.py#L251-L321
|
[
"def",
"read",
"(",
"self",
",",
"input_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"SignatureVerifyRequestPayload",
",",
"self",
")",
".",
"read",
"(",
"input_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"local_stream",
"=",
"utils",
".",
"BytearrayStream",
"(",
"input_stream",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"UNIQUE_IDENTIFIER",
",",
"local_stream",
")",
":",
"self",
".",
"_unique_identifier",
"=",
"primitives",
".",
"TextString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"UNIQUE_IDENTIFIER",
")",
"self",
".",
"_unique_identifier",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"CRYPTOGRAPHIC_PARAMETERS",
",",
"local_stream",
")",
":",
"self",
".",
"_cryptographic_parameters",
"=",
"attributes",
".",
"CryptographicParameters",
"(",
")",
"self",
".",
"_cryptographic_parameters",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"DATA",
",",
"local_stream",
")",
":",
"self",
".",
"_data",
"=",
"primitives",
".",
"ByteString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"DATA",
")",
"self",
".",
"_data",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"DIGESTED_DATA",
",",
"local_stream",
")",
":",
"self",
".",
"_digested_data",
"=",
"primitives",
".",
"ByteString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"DIGESTED_DATA",
")",
"self",
".",
"_digested_data",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"SIGNATURE_DATA",
",",
"local_stream",
")",
":",
"self",
".",
"_signature_data",
"=",
"primitives",
".",
"ByteString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"SIGNATURE_DATA",
")",
"self",
".",
"_signature_data",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"CORRELATION_VALUE",
",",
"local_stream",
")",
":",
"self",
".",
"_correlation_value",
"=",
"primitives",
".",
"ByteString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"CORRELATION_VALUE",
")",
"self",
".",
"_correlation_value",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"INIT_INDICATOR",
",",
"local_stream",
")",
":",
"self",
".",
"_init_indicator",
"=",
"primitives",
".",
"Boolean",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"INIT_INDICATOR",
")",
"self",
".",
"_init_indicator",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"FINAL_INDICATOR",
",",
"local_stream",
")",
":",
"self",
".",
"_final_indicator",
"=",
"primitives",
".",
"Boolean",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"FINAL_INDICATOR",
")",
"self",
".",
"_final_indicator",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"is_oversized",
"(",
"local_stream",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
SignatureVerifyRequestPayload.write
|
Write the data encoding the SignatureVerify request payload to a
stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is not defined.
|
kmip/core/messages/payloads/signature_verify.py
|
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the SignatureVerify request payload to a
stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is not defined.
"""
local_stream = utils.BytearrayStream()
if self._unique_identifier:
self._unique_identifier.write(
local_stream,
kmip_version=kmip_version
)
if self._cryptographic_parameters:
self._cryptographic_parameters.write(
local_stream,
kmip_version=kmip_version
)
if self._data:
self._data.write(local_stream, kmip_version=kmip_version)
if self._digested_data:
self._digested_data.write(local_stream, kmip_version=kmip_version)
if self._signature_data:
self._signature_data.write(
local_stream,
kmip_version=kmip_version
)
if self._correlation_value:
self._correlation_value.write(
local_stream,
kmip_version=kmip_version
)
if self._init_indicator:
self._init_indicator.write(
local_stream,
kmip_version=kmip_version
)
if self._final_indicator:
self._final_indicator.write(
local_stream,
kmip_version=kmip_version
)
self.length = local_stream.length()
super(SignatureVerifyRequestPayload, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
|
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the SignatureVerify request payload to a
stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is not defined.
"""
local_stream = utils.BytearrayStream()
if self._unique_identifier:
self._unique_identifier.write(
local_stream,
kmip_version=kmip_version
)
if self._cryptographic_parameters:
self._cryptographic_parameters.write(
local_stream,
kmip_version=kmip_version
)
if self._data:
self._data.write(local_stream, kmip_version=kmip_version)
if self._digested_data:
self._digested_data.write(local_stream, kmip_version=kmip_version)
if self._signature_data:
self._signature_data.write(
local_stream,
kmip_version=kmip_version
)
if self._correlation_value:
self._correlation_value.write(
local_stream,
kmip_version=kmip_version
)
if self._init_indicator:
self._init_indicator.write(
local_stream,
kmip_version=kmip_version
)
if self._final_indicator:
self._final_indicator.write(
local_stream,
kmip_version=kmip_version
)
self.length = local_stream.length()
super(SignatureVerifyRequestPayload, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
|
[
"Write",
"the",
"data",
"encoding",
"the",
"SignatureVerify",
"request",
"payload",
"to",
"a",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/signature_verify.py#L323-L381
|
[
"def",
"write",
"(",
"self",
",",
"output_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"local_stream",
"=",
"utils",
".",
"BytearrayStream",
"(",
")",
"if",
"self",
".",
"_unique_identifier",
":",
"self",
".",
"_unique_identifier",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_cryptographic_parameters",
":",
"self",
".",
"_cryptographic_parameters",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_data",
":",
"self",
".",
"_data",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_digested_data",
":",
"self",
".",
"_digested_data",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_signature_data",
":",
"self",
".",
"_signature_data",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_correlation_value",
":",
"self",
".",
"_correlation_value",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_init_indicator",
":",
"self",
".",
"_init_indicator",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_final_indicator",
":",
"self",
".",
"_final_indicator",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"length",
"=",
"local_stream",
".",
"length",
"(",
")",
"super",
"(",
"SignatureVerifyRequestPayload",
",",
"self",
")",
".",
"write",
"(",
"output_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"output_stream",
".",
"write",
"(",
"local_stream",
".",
"buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
SignatureVerifyResponsePayload.read
|
Read the data encoding the SignatureVerify response payload and decode
it into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
|
kmip/core/messages/payloads/signature_verify.py
|
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the SignatureVerify response payload and decode
it into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
"""
super(SignatureVerifyResponsePayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
"Parsed payload encoding is missing the unique identifier "
"field."
)
if self.is_tag_next(enums.Tags.VALIDITY_INDICATOR, local_stream):
self._validity_indicator = primitives.Enumeration(
enums.ValidityIndicator,
tag=enums.Tags.VALIDITY_INDICATOR
)
self._validity_indicator.read(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
"Parsed payload encoding is missing the validity indicator "
"field."
)
if self.is_tag_next(enums.Tags.DATA, local_stream):
self._data = primitives.ByteString(tag=enums.Tags.DATA)
self._data.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.CORRELATION_VALUE, local_stream):
self._correlation_value = primitives.ByteString(
tag=enums.Tags.CORRELATION_VALUE
)
self._correlation_value.read(
local_stream,
kmip_version=kmip_version
)
self.is_oversized(local_stream)
|
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the SignatureVerify response payload and decode
it into its constituent parts.
Args:
input_stream (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is missing from the
encoded payload.
"""
super(SignatureVerifyResponsePayload, self).read(
input_stream,
kmip_version=kmip_version
)
local_stream = utils.BytearrayStream(input_stream.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
"Parsed payload encoding is missing the unique identifier "
"field."
)
if self.is_tag_next(enums.Tags.VALIDITY_INDICATOR, local_stream):
self._validity_indicator = primitives.Enumeration(
enums.ValidityIndicator,
tag=enums.Tags.VALIDITY_INDICATOR
)
self._validity_indicator.read(
local_stream,
kmip_version=kmip_version
)
else:
raise ValueError(
"Parsed payload encoding is missing the validity indicator "
"field."
)
if self.is_tag_next(enums.Tags.DATA, local_stream):
self._data = primitives.ByteString(tag=enums.Tags.DATA)
self._data.read(local_stream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.CORRELATION_VALUE, local_stream):
self._correlation_value = primitives.ByteString(
tag=enums.Tags.CORRELATION_VALUE
)
self._correlation_value.read(
local_stream,
kmip_version=kmip_version
)
self.is_oversized(local_stream)
|
[
"Read",
"the",
"data",
"encoding",
"the",
"SignatureVerify",
"response",
"payload",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/signature_verify.py#L568-L630
|
[
"def",
"read",
"(",
"self",
",",
"input_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"SignatureVerifyResponsePayload",
",",
"self",
")",
".",
"read",
"(",
"input_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"local_stream",
"=",
"utils",
".",
"BytearrayStream",
"(",
"input_stream",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"UNIQUE_IDENTIFIER",
",",
"local_stream",
")",
":",
"self",
".",
"_unique_identifier",
"=",
"primitives",
".",
"TextString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"UNIQUE_IDENTIFIER",
")",
"self",
".",
"_unique_identifier",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"ValueError",
"(",
"\"Parsed payload encoding is missing the unique identifier \"",
"\"field.\"",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"VALIDITY_INDICATOR",
",",
"local_stream",
")",
":",
"self",
".",
"_validity_indicator",
"=",
"primitives",
".",
"Enumeration",
"(",
"enums",
".",
"ValidityIndicator",
",",
"tag",
"=",
"enums",
".",
"Tags",
".",
"VALIDITY_INDICATOR",
")",
"self",
".",
"_validity_indicator",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"ValueError",
"(",
"\"Parsed payload encoding is missing the validity indicator \"",
"\"field.\"",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"DATA",
",",
"local_stream",
")",
":",
"self",
".",
"_data",
"=",
"primitives",
".",
"ByteString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"DATA",
")",
"self",
".",
"_data",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"CORRELATION_VALUE",
",",
"local_stream",
")",
":",
"self",
".",
"_correlation_value",
"=",
"primitives",
".",
"ByteString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"CORRELATION_VALUE",
")",
"self",
".",
"_correlation_value",
".",
"read",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"is_oversized",
"(",
"local_stream",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
KmipEngine.process_request
|
Process a KMIP request message.
This routine is the main driver of the KmipEngine. It breaks apart and
processes the request header, handles any message errors that may
result, and then passes the set of request batch items on for
processing. This routine is thread-safe, allowing multiple client
connections to use the same KmipEngine.
Args:
request (RequestMessage): The request message containing the batch
items to be processed.
credential (string): Identifying information about the client
obtained from the client certificate. Optional, defaults to
None.
Returns:
ResponseMessage: The response containing all of the results from
the request batch items.
|
kmip/services/server/engine.py
|
def process_request(self, request, credential=None):
"""
Process a KMIP request message.
This routine is the main driver of the KmipEngine. It breaks apart and
processes the request header, handles any message errors that may
result, and then passes the set of request batch items on for
processing. This routine is thread-safe, allowing multiple client
connections to use the same KmipEngine.
Args:
request (RequestMessage): The request message containing the batch
items to be processed.
credential (string): Identifying information about the client
obtained from the client certificate. Optional, defaults to
None.
Returns:
ResponseMessage: The response containing all of the results from
the request batch items.
"""
self._client_identity = [None, None]
header = request.request_header
# Process the protocol version
self._set_protocol_version(header.protocol_version)
# Process the maximum response size
max_response_size = None
if header.maximum_response_size:
max_response_size = header.maximum_response_size.value
# Process the time stamp
now = int(time.time())
if header.time_stamp:
then = header.time_stamp.value
if (now >= then) and ((now - then) < 60):
self._logger.info("Received request at time: {0}".format(
time.strftime(
"%Y-%m-%d %H:%M:%S",
time.gmtime(then)
)
))
else:
if now < then:
self._logger.warning(
"Received request with future timestamp. Received "
"timestamp: {0}, Current timestamp: {1}".format(
then,
now
)
)
raise exceptions.InvalidMessage(
"Future request rejected by server."
)
else:
self._logger.warning(
"Received request with old timestamp. Possible "
"replay attack. Received timestamp: {0}, Current "
"timestamp: {1}".format(then, now)
)
raise exceptions.InvalidMessage(
"Stale request rejected by server."
)
else:
self._logger.info("Received request at time: {0}".format(
time.strftime(
"%Y-%m-%d %H:%M:%S",
time.gmtime(now)
)
))
# Process the asynchronous indicator
self.is_asynchronous = False
if header.asynchronous_indicator is not None:
self.is_asynchronous = header.asynchronous_indicator.value
if self.is_asynchronous:
raise exceptions.InvalidMessage(
"Asynchronous operations are not supported."
)
# Process the authentication credentials
if header.authentication:
if header.authentication.credentials:
auth_credentials = header.authentication.credentials[0]
else:
auth_credentials = None
else:
auth_credentials = None
self._verify_credential(auth_credentials, credential)
# Process the batch error continuation option
batch_error_option = enums.BatchErrorContinuationOption.STOP
if header.batch_error_cont_option is not None:
batch_error_option = header.batch_error_cont_option.value
if batch_error_option == enums.BatchErrorContinuationOption.UNDO:
raise exceptions.InvalidMessage(
"Undo option for batch handling is not supported."
)
# Process the batch order option
batch_order_option = False
if header.batch_order_option:
batch_order_option = header.batch_order_option.value
response_batch = self._process_batch(
request.batch_items,
batch_error_option,
batch_order_option
)
response = self._build_response(
header.protocol_version,
response_batch
)
return response, max_response_size, header.protocol_version
|
def process_request(self, request, credential=None):
"""
Process a KMIP request message.
This routine is the main driver of the KmipEngine. It breaks apart and
processes the request header, handles any message errors that may
result, and then passes the set of request batch items on for
processing. This routine is thread-safe, allowing multiple client
connections to use the same KmipEngine.
Args:
request (RequestMessage): The request message containing the batch
items to be processed.
credential (string): Identifying information about the client
obtained from the client certificate. Optional, defaults to
None.
Returns:
ResponseMessage: The response containing all of the results from
the request batch items.
"""
self._client_identity = [None, None]
header = request.request_header
# Process the protocol version
self._set_protocol_version(header.protocol_version)
# Process the maximum response size
max_response_size = None
if header.maximum_response_size:
max_response_size = header.maximum_response_size.value
# Process the time stamp
now = int(time.time())
if header.time_stamp:
then = header.time_stamp.value
if (now >= then) and ((now - then) < 60):
self._logger.info("Received request at time: {0}".format(
time.strftime(
"%Y-%m-%d %H:%M:%S",
time.gmtime(then)
)
))
else:
if now < then:
self._logger.warning(
"Received request with future timestamp. Received "
"timestamp: {0}, Current timestamp: {1}".format(
then,
now
)
)
raise exceptions.InvalidMessage(
"Future request rejected by server."
)
else:
self._logger.warning(
"Received request with old timestamp. Possible "
"replay attack. Received timestamp: {0}, Current "
"timestamp: {1}".format(then, now)
)
raise exceptions.InvalidMessage(
"Stale request rejected by server."
)
else:
self._logger.info("Received request at time: {0}".format(
time.strftime(
"%Y-%m-%d %H:%M:%S",
time.gmtime(now)
)
))
# Process the asynchronous indicator
self.is_asynchronous = False
if header.asynchronous_indicator is not None:
self.is_asynchronous = header.asynchronous_indicator.value
if self.is_asynchronous:
raise exceptions.InvalidMessage(
"Asynchronous operations are not supported."
)
# Process the authentication credentials
if header.authentication:
if header.authentication.credentials:
auth_credentials = header.authentication.credentials[0]
else:
auth_credentials = None
else:
auth_credentials = None
self._verify_credential(auth_credentials, credential)
# Process the batch error continuation option
batch_error_option = enums.BatchErrorContinuationOption.STOP
if header.batch_error_cont_option is not None:
batch_error_option = header.batch_error_cont_option.value
if batch_error_option == enums.BatchErrorContinuationOption.UNDO:
raise exceptions.InvalidMessage(
"Undo option for batch handling is not supported."
)
# Process the batch order option
batch_order_option = False
if header.batch_order_option:
batch_order_option = header.batch_order_option.value
response_batch = self._process_batch(
request.batch_items,
batch_error_option,
batch_order_option
)
response = self._build_response(
header.protocol_version,
response_batch
)
return response, max_response_size, header.protocol_version
|
[
"Process",
"a",
"KMIP",
"request",
"message",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/engine.py#L189-L310
|
[
"def",
"process_request",
"(",
"self",
",",
"request",
",",
"credential",
"=",
"None",
")",
":",
"self",
".",
"_client_identity",
"=",
"[",
"None",
",",
"None",
"]",
"header",
"=",
"request",
".",
"request_header",
"# Process the protocol version",
"self",
".",
"_set_protocol_version",
"(",
"header",
".",
"protocol_version",
")",
"# Process the maximum response size",
"max_response_size",
"=",
"None",
"if",
"header",
".",
"maximum_response_size",
":",
"max_response_size",
"=",
"header",
".",
"maximum_response_size",
".",
"value",
"# Process the time stamp",
"now",
"=",
"int",
"(",
"time",
".",
"time",
"(",
")",
")",
"if",
"header",
".",
"time_stamp",
":",
"then",
"=",
"header",
".",
"time_stamp",
".",
"value",
"if",
"(",
"now",
">=",
"then",
")",
"and",
"(",
"(",
"now",
"-",
"then",
")",
"<",
"60",
")",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"\"Received request at time: {0}\"",
".",
"format",
"(",
"time",
".",
"strftime",
"(",
"\"%Y-%m-%d %H:%M:%S\"",
",",
"time",
".",
"gmtime",
"(",
"then",
")",
")",
")",
")",
"else",
":",
"if",
"now",
"<",
"then",
":",
"self",
".",
"_logger",
".",
"warning",
"(",
"\"Received request with future timestamp. Received \"",
"\"timestamp: {0}, Current timestamp: {1}\"",
".",
"format",
"(",
"then",
",",
"now",
")",
")",
"raise",
"exceptions",
".",
"InvalidMessage",
"(",
"\"Future request rejected by server.\"",
")",
"else",
":",
"self",
".",
"_logger",
".",
"warning",
"(",
"\"Received request with old timestamp. Possible \"",
"\"replay attack. Received timestamp: {0}, Current \"",
"\"timestamp: {1}\"",
".",
"format",
"(",
"then",
",",
"now",
")",
")",
"raise",
"exceptions",
".",
"InvalidMessage",
"(",
"\"Stale request rejected by server.\"",
")",
"else",
":",
"self",
".",
"_logger",
".",
"info",
"(",
"\"Received request at time: {0}\"",
".",
"format",
"(",
"time",
".",
"strftime",
"(",
"\"%Y-%m-%d %H:%M:%S\"",
",",
"time",
".",
"gmtime",
"(",
"now",
")",
")",
")",
")",
"# Process the asynchronous indicator",
"self",
".",
"is_asynchronous",
"=",
"False",
"if",
"header",
".",
"asynchronous_indicator",
"is",
"not",
"None",
":",
"self",
".",
"is_asynchronous",
"=",
"header",
".",
"asynchronous_indicator",
".",
"value",
"if",
"self",
".",
"is_asynchronous",
":",
"raise",
"exceptions",
".",
"InvalidMessage",
"(",
"\"Asynchronous operations are not supported.\"",
")",
"# Process the authentication credentials",
"if",
"header",
".",
"authentication",
":",
"if",
"header",
".",
"authentication",
".",
"credentials",
":",
"auth_credentials",
"=",
"header",
".",
"authentication",
".",
"credentials",
"[",
"0",
"]",
"else",
":",
"auth_credentials",
"=",
"None",
"else",
":",
"auth_credentials",
"=",
"None",
"self",
".",
"_verify_credential",
"(",
"auth_credentials",
",",
"credential",
")",
"# Process the batch error continuation option",
"batch_error_option",
"=",
"enums",
".",
"BatchErrorContinuationOption",
".",
"STOP",
"if",
"header",
".",
"batch_error_cont_option",
"is",
"not",
"None",
":",
"batch_error_option",
"=",
"header",
".",
"batch_error_cont_option",
".",
"value",
"if",
"batch_error_option",
"==",
"enums",
".",
"BatchErrorContinuationOption",
".",
"UNDO",
":",
"raise",
"exceptions",
".",
"InvalidMessage",
"(",
"\"Undo option for batch handling is not supported.\"",
")",
"# Process the batch order option",
"batch_order_option",
"=",
"False",
"if",
"header",
".",
"batch_order_option",
":",
"batch_order_option",
"=",
"header",
".",
"batch_order_option",
".",
"value",
"response_batch",
"=",
"self",
".",
"_process_batch",
"(",
"request",
".",
"batch_items",
",",
"batch_error_option",
",",
"batch_order_option",
")",
"response",
"=",
"self",
".",
"_build_response",
"(",
"header",
".",
"protocol_version",
",",
"response_batch",
")",
"return",
"response",
",",
"max_response_size",
",",
"header",
".",
"protocol_version"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
KmipEngine.build_error_response
|
Build a simple ResponseMessage with a single error result.
Args:
version (ProtocolVersion): The protocol version the response
should be addressed with.
reason (ResultReason): An enumeration classifying the type of
error occurred.
message (str): A string providing additional information about
the error.
Returns:
ResponseMessage: The simple ResponseMessage containing a
single error result.
|
kmip/services/server/engine.py
|
def build_error_response(self, version, reason, message):
"""
Build a simple ResponseMessage with a single error result.
Args:
version (ProtocolVersion): The protocol version the response
should be addressed with.
reason (ResultReason): An enumeration classifying the type of
error occurred.
message (str): A string providing additional information about
the error.
Returns:
ResponseMessage: The simple ResponseMessage containing a
single error result.
"""
batch_item = messages.ResponseBatchItem(
result_status=contents.ResultStatus(
enums.ResultStatus.OPERATION_FAILED
),
result_reason=contents.ResultReason(reason),
result_message=contents.ResultMessage(message)
)
return self._build_response(version, [batch_item])
|
def build_error_response(self, version, reason, message):
"""
Build a simple ResponseMessage with a single error result.
Args:
version (ProtocolVersion): The protocol version the response
should be addressed with.
reason (ResultReason): An enumeration classifying the type of
error occurred.
message (str): A string providing additional information about
the error.
Returns:
ResponseMessage: The simple ResponseMessage containing a
single error result.
"""
batch_item = messages.ResponseBatchItem(
result_status=contents.ResultStatus(
enums.ResultStatus.OPERATION_FAILED
),
result_reason=contents.ResultReason(reason),
result_message=contents.ResultMessage(message)
)
return self._build_response(version, [batch_item])
|
[
"Build",
"a",
"simple",
"ResponseMessage",
"with",
"a",
"single",
"error",
"result",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/engine.py#L324-L347
|
[
"def",
"build_error_response",
"(",
"self",
",",
"version",
",",
"reason",
",",
"message",
")",
":",
"batch_item",
"=",
"messages",
".",
"ResponseBatchItem",
"(",
"result_status",
"=",
"contents",
".",
"ResultStatus",
"(",
"enums",
".",
"ResultStatus",
".",
"OPERATION_FAILED",
")",
",",
"result_reason",
"=",
"contents",
".",
"ResultReason",
"(",
"reason",
")",
",",
"result_message",
"=",
"contents",
".",
"ResultMessage",
"(",
"message",
")",
")",
"return",
"self",
".",
"_build_response",
"(",
"version",
",",
"[",
"batch_item",
"]",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
KmipEngine._process_template_attribute
|
Given a kmip.core TemplateAttribute object, extract the attribute
value data into a usable dictionary format.
|
kmip/services/server/engine.py
|
def _process_template_attribute(self, template_attribute):
"""
Given a kmip.core TemplateAttribute object, extract the attribute
value data into a usable dictionary format.
"""
attributes = {}
if len(template_attribute.names) > 0:
raise exceptions.ItemNotFound(
"Attribute templates are not supported."
)
for attribute in template_attribute.attributes:
name = attribute.attribute_name.value
if not self._attribute_policy.is_attribute_supported(name):
raise exceptions.InvalidField(
"The {0} attribute is unsupported.".format(name)
)
if self._attribute_policy.is_attribute_multivalued(name):
values = attributes.get(name, list())
if (not attribute.attribute_index) and len(values) > 0:
raise exceptions.InvalidField(
"Attribute index missing from multivalued attribute."
)
values.append(attribute.attribute_value)
attributes.update([(name, values)])
else:
if attribute.attribute_index:
if attribute.attribute_index.value != 0:
raise exceptions.InvalidField(
"Non-zero attribute index found for "
"single-valued attribute."
)
value = attributes.get(name, None)
if value:
raise exceptions.IndexOutOfBounds(
"Cannot set multiple instances of the "
"{0} attribute.".format(name)
)
else:
attributes.update([(name, attribute.attribute_value)])
return attributes
|
def _process_template_attribute(self, template_attribute):
"""
Given a kmip.core TemplateAttribute object, extract the attribute
value data into a usable dictionary format.
"""
attributes = {}
if len(template_attribute.names) > 0:
raise exceptions.ItemNotFound(
"Attribute templates are not supported."
)
for attribute in template_attribute.attributes:
name = attribute.attribute_name.value
if not self._attribute_policy.is_attribute_supported(name):
raise exceptions.InvalidField(
"The {0} attribute is unsupported.".format(name)
)
if self._attribute_policy.is_attribute_multivalued(name):
values = attributes.get(name, list())
if (not attribute.attribute_index) and len(values) > 0:
raise exceptions.InvalidField(
"Attribute index missing from multivalued attribute."
)
values.append(attribute.attribute_value)
attributes.update([(name, values)])
else:
if attribute.attribute_index:
if attribute.attribute_index.value != 0:
raise exceptions.InvalidField(
"Non-zero attribute index found for "
"single-valued attribute."
)
value = attributes.get(name, None)
if value:
raise exceptions.IndexOutOfBounds(
"Cannot set multiple instances of the "
"{0} attribute.".format(name)
)
else:
attributes.update([(name, attribute.attribute_value)])
return attributes
|
[
"Given",
"a",
"kmip",
".",
"core",
"TemplateAttribute",
"object",
"extract",
"the",
"attribute",
"value",
"data",
"into",
"a",
"usable",
"dictionary",
"format",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/engine.py#L529-L574
|
[
"def",
"_process_template_attribute",
"(",
"self",
",",
"template_attribute",
")",
":",
"attributes",
"=",
"{",
"}",
"if",
"len",
"(",
"template_attribute",
".",
"names",
")",
">",
"0",
":",
"raise",
"exceptions",
".",
"ItemNotFound",
"(",
"\"Attribute templates are not supported.\"",
")",
"for",
"attribute",
"in",
"template_attribute",
".",
"attributes",
":",
"name",
"=",
"attribute",
".",
"attribute_name",
".",
"value",
"if",
"not",
"self",
".",
"_attribute_policy",
".",
"is_attribute_supported",
"(",
"name",
")",
":",
"raise",
"exceptions",
".",
"InvalidField",
"(",
"\"The {0} attribute is unsupported.\"",
".",
"format",
"(",
"name",
")",
")",
"if",
"self",
".",
"_attribute_policy",
".",
"is_attribute_multivalued",
"(",
"name",
")",
":",
"values",
"=",
"attributes",
".",
"get",
"(",
"name",
",",
"list",
"(",
")",
")",
"if",
"(",
"not",
"attribute",
".",
"attribute_index",
")",
"and",
"len",
"(",
"values",
")",
">",
"0",
":",
"raise",
"exceptions",
".",
"InvalidField",
"(",
"\"Attribute index missing from multivalued attribute.\"",
")",
"values",
".",
"append",
"(",
"attribute",
".",
"attribute_value",
")",
"attributes",
".",
"update",
"(",
"[",
"(",
"name",
",",
"values",
")",
"]",
")",
"else",
":",
"if",
"attribute",
".",
"attribute_index",
":",
"if",
"attribute",
".",
"attribute_index",
".",
"value",
"!=",
"0",
":",
"raise",
"exceptions",
".",
"InvalidField",
"(",
"\"Non-zero attribute index found for \"",
"\"single-valued attribute.\"",
")",
"value",
"=",
"attributes",
".",
"get",
"(",
"name",
",",
"None",
")",
"if",
"value",
":",
"raise",
"exceptions",
".",
"IndexOutOfBounds",
"(",
"\"Cannot set multiple instances of the \"",
"\"{0} attribute.\"",
".",
"format",
"(",
"name",
")",
")",
"else",
":",
"attributes",
".",
"update",
"(",
"[",
"(",
"name",
",",
"attribute",
".",
"attribute_value",
")",
"]",
")",
"return",
"attributes"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
KmipEngine._get_attributes_from_managed_object
|
Given a kmip.pie object and a list of attribute names, attempt to get
all of the existing attribute values from the object.
|
kmip/services/server/engine.py
|
def _get_attributes_from_managed_object(self, managed_object, attr_names):
"""
Given a kmip.pie object and a list of attribute names, attempt to get
all of the existing attribute values from the object.
"""
attr_factory = attribute_factory.AttributeFactory()
retrieved_attributes = list()
if not attr_names:
attr_names = self._attribute_policy.get_all_attribute_names()
for attribute_name in attr_names:
object_type = managed_object._object_type
if not self._attribute_policy.is_attribute_supported(
attribute_name
):
continue
if self._attribute_policy.is_attribute_applicable_to_object_type(
attribute_name,
object_type
):
try:
attribute_value = self._get_attribute_from_managed_object(
managed_object,
attribute_name
)
except Exception:
attribute_value = None
if attribute_value is not None:
if self._attribute_policy.is_attribute_multivalued(
attribute_name
):
for count, value in enumerate(attribute_value):
attribute = attr_factory.create_attribute(
enums.AttributeType(attribute_name),
value,
count
)
retrieved_attributes.append(attribute)
else:
attribute = attr_factory.create_attribute(
enums.AttributeType(attribute_name),
attribute_value
)
retrieved_attributes.append(attribute)
return retrieved_attributes
|
def _get_attributes_from_managed_object(self, managed_object, attr_names):
"""
Given a kmip.pie object and a list of attribute names, attempt to get
all of the existing attribute values from the object.
"""
attr_factory = attribute_factory.AttributeFactory()
retrieved_attributes = list()
if not attr_names:
attr_names = self._attribute_policy.get_all_attribute_names()
for attribute_name in attr_names:
object_type = managed_object._object_type
if not self._attribute_policy.is_attribute_supported(
attribute_name
):
continue
if self._attribute_policy.is_attribute_applicable_to_object_type(
attribute_name,
object_type
):
try:
attribute_value = self._get_attribute_from_managed_object(
managed_object,
attribute_name
)
except Exception:
attribute_value = None
if attribute_value is not None:
if self._attribute_policy.is_attribute_multivalued(
attribute_name
):
for count, value in enumerate(attribute_value):
attribute = attr_factory.create_attribute(
enums.AttributeType(attribute_name),
value,
count
)
retrieved_attributes.append(attribute)
else:
attribute = attr_factory.create_attribute(
enums.AttributeType(attribute_name),
attribute_value
)
retrieved_attributes.append(attribute)
return retrieved_attributes
|
[
"Given",
"a",
"kmip",
".",
"pie",
"object",
"and",
"a",
"list",
"of",
"attribute",
"names",
"attempt",
"to",
"get",
"all",
"of",
"the",
"existing",
"attribute",
"values",
"from",
"the",
"object",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/engine.py#L576-L625
|
[
"def",
"_get_attributes_from_managed_object",
"(",
"self",
",",
"managed_object",
",",
"attr_names",
")",
":",
"attr_factory",
"=",
"attribute_factory",
".",
"AttributeFactory",
"(",
")",
"retrieved_attributes",
"=",
"list",
"(",
")",
"if",
"not",
"attr_names",
":",
"attr_names",
"=",
"self",
".",
"_attribute_policy",
".",
"get_all_attribute_names",
"(",
")",
"for",
"attribute_name",
"in",
"attr_names",
":",
"object_type",
"=",
"managed_object",
".",
"_object_type",
"if",
"not",
"self",
".",
"_attribute_policy",
".",
"is_attribute_supported",
"(",
"attribute_name",
")",
":",
"continue",
"if",
"self",
".",
"_attribute_policy",
".",
"is_attribute_applicable_to_object_type",
"(",
"attribute_name",
",",
"object_type",
")",
":",
"try",
":",
"attribute_value",
"=",
"self",
".",
"_get_attribute_from_managed_object",
"(",
"managed_object",
",",
"attribute_name",
")",
"except",
"Exception",
":",
"attribute_value",
"=",
"None",
"if",
"attribute_value",
"is",
"not",
"None",
":",
"if",
"self",
".",
"_attribute_policy",
".",
"is_attribute_multivalued",
"(",
"attribute_name",
")",
":",
"for",
"count",
",",
"value",
"in",
"enumerate",
"(",
"attribute_value",
")",
":",
"attribute",
"=",
"attr_factory",
".",
"create_attribute",
"(",
"enums",
".",
"AttributeType",
"(",
"attribute_name",
")",
",",
"value",
",",
"count",
")",
"retrieved_attributes",
".",
"append",
"(",
"attribute",
")",
"else",
":",
"attribute",
"=",
"attr_factory",
".",
"create_attribute",
"(",
"enums",
".",
"AttributeType",
"(",
"attribute_name",
")",
",",
"attribute_value",
")",
"retrieved_attributes",
".",
"append",
"(",
"attribute",
")",
"return",
"retrieved_attributes"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
KmipEngine._get_attribute_from_managed_object
|
Get the attribute value from the kmip.pie managed object.
|
kmip/services/server/engine.py
|
def _get_attribute_from_managed_object(self, managed_object, attr_name):
"""
Get the attribute value from the kmip.pie managed object.
"""
if attr_name == 'Unique Identifier':
return str(managed_object.unique_identifier)
elif attr_name == 'Name':
names = list()
for name in managed_object.names:
name = attributes.Name(
attributes.Name.NameValue(name),
attributes.Name.NameType(
enums.NameType.UNINTERPRETED_TEXT_STRING
)
)
names.append(name)
return names
elif attr_name == 'Object Type':
return managed_object._object_type
elif attr_name == 'Cryptographic Algorithm':
return managed_object.cryptographic_algorithm
elif attr_name == 'Cryptographic Length':
return managed_object.cryptographic_length
elif attr_name == 'Cryptographic Parameters':
return None
elif attr_name == 'Cryptographic Domain Parameters':
return None
elif attr_name == 'Certificate Type':
return managed_object.certificate_type
elif attr_name == 'Certificate Length':
return None
elif attr_name == 'X.509 Certificate Identifier':
return None
elif attr_name == 'X.509 Certificate Subject':
return None
elif attr_name == 'X.509 Certificate Issuer':
return None
elif attr_name == 'Certificate Identifier':
return None
elif attr_name == 'Certificate Subject':
return None
elif attr_name == 'Certificate Issuer':
return None
elif attr_name == 'Digital Signature Algorithm':
return None
elif attr_name == 'Digest':
return None
elif attr_name == 'Operation Policy Name':
return managed_object.operation_policy_name
elif attr_name == 'Cryptographic Usage Mask':
return managed_object.cryptographic_usage_masks
elif attr_name == 'Lease Time':
return None
elif attr_name == 'Usage Limits':
return None
elif attr_name == 'State':
return managed_object.state
elif attr_name == 'Initial Date':
return managed_object.initial_date
elif attr_name == 'Activation Date':
return None
elif attr_name == 'Process Start Date':
return None
elif attr_name == 'Protect Stop Date':
return None
elif attr_name == 'Deactivation Date':
return None
elif attr_name == 'Destroy Date':
return None
elif attr_name == 'Compromise Occurrence Date':
return None
elif attr_name == 'Compromise Date':
return None
elif attr_name == 'Revocation Reason':
return None
elif attr_name == 'Archive Date':
return None
elif attr_name == 'Object Group':
return None
elif attr_name == 'Fresh':
return None
elif attr_name == 'Link':
return None
elif attr_name == 'Application Specific Information':
return None
elif attr_name == 'Contact Information':
return None
elif attr_name == 'Last Change Date':
return None
else:
# Since custom attribute names are possible, just return None
# for unrecognized attributes. This satisfies the spec.
return None
|
def _get_attribute_from_managed_object(self, managed_object, attr_name):
"""
Get the attribute value from the kmip.pie managed object.
"""
if attr_name == 'Unique Identifier':
return str(managed_object.unique_identifier)
elif attr_name == 'Name':
names = list()
for name in managed_object.names:
name = attributes.Name(
attributes.Name.NameValue(name),
attributes.Name.NameType(
enums.NameType.UNINTERPRETED_TEXT_STRING
)
)
names.append(name)
return names
elif attr_name == 'Object Type':
return managed_object._object_type
elif attr_name == 'Cryptographic Algorithm':
return managed_object.cryptographic_algorithm
elif attr_name == 'Cryptographic Length':
return managed_object.cryptographic_length
elif attr_name == 'Cryptographic Parameters':
return None
elif attr_name == 'Cryptographic Domain Parameters':
return None
elif attr_name == 'Certificate Type':
return managed_object.certificate_type
elif attr_name == 'Certificate Length':
return None
elif attr_name == 'X.509 Certificate Identifier':
return None
elif attr_name == 'X.509 Certificate Subject':
return None
elif attr_name == 'X.509 Certificate Issuer':
return None
elif attr_name == 'Certificate Identifier':
return None
elif attr_name == 'Certificate Subject':
return None
elif attr_name == 'Certificate Issuer':
return None
elif attr_name == 'Digital Signature Algorithm':
return None
elif attr_name == 'Digest':
return None
elif attr_name == 'Operation Policy Name':
return managed_object.operation_policy_name
elif attr_name == 'Cryptographic Usage Mask':
return managed_object.cryptographic_usage_masks
elif attr_name == 'Lease Time':
return None
elif attr_name == 'Usage Limits':
return None
elif attr_name == 'State':
return managed_object.state
elif attr_name == 'Initial Date':
return managed_object.initial_date
elif attr_name == 'Activation Date':
return None
elif attr_name == 'Process Start Date':
return None
elif attr_name == 'Protect Stop Date':
return None
elif attr_name == 'Deactivation Date':
return None
elif attr_name == 'Destroy Date':
return None
elif attr_name == 'Compromise Occurrence Date':
return None
elif attr_name == 'Compromise Date':
return None
elif attr_name == 'Revocation Reason':
return None
elif attr_name == 'Archive Date':
return None
elif attr_name == 'Object Group':
return None
elif attr_name == 'Fresh':
return None
elif attr_name == 'Link':
return None
elif attr_name == 'Application Specific Information':
return None
elif attr_name == 'Contact Information':
return None
elif attr_name == 'Last Change Date':
return None
else:
# Since custom attribute names are possible, just return None
# for unrecognized attributes. This satisfies the spec.
return None
|
[
"Get",
"the",
"attribute",
"value",
"from",
"the",
"kmip",
".",
"pie",
"managed",
"object",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/engine.py#L627-L719
|
[
"def",
"_get_attribute_from_managed_object",
"(",
"self",
",",
"managed_object",
",",
"attr_name",
")",
":",
"if",
"attr_name",
"==",
"'Unique Identifier'",
":",
"return",
"str",
"(",
"managed_object",
".",
"unique_identifier",
")",
"elif",
"attr_name",
"==",
"'Name'",
":",
"names",
"=",
"list",
"(",
")",
"for",
"name",
"in",
"managed_object",
".",
"names",
":",
"name",
"=",
"attributes",
".",
"Name",
"(",
"attributes",
".",
"Name",
".",
"NameValue",
"(",
"name",
")",
",",
"attributes",
".",
"Name",
".",
"NameType",
"(",
"enums",
".",
"NameType",
".",
"UNINTERPRETED_TEXT_STRING",
")",
")",
"names",
".",
"append",
"(",
"name",
")",
"return",
"names",
"elif",
"attr_name",
"==",
"'Object Type'",
":",
"return",
"managed_object",
".",
"_object_type",
"elif",
"attr_name",
"==",
"'Cryptographic Algorithm'",
":",
"return",
"managed_object",
".",
"cryptographic_algorithm",
"elif",
"attr_name",
"==",
"'Cryptographic Length'",
":",
"return",
"managed_object",
".",
"cryptographic_length",
"elif",
"attr_name",
"==",
"'Cryptographic Parameters'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Cryptographic Domain Parameters'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Certificate Type'",
":",
"return",
"managed_object",
".",
"certificate_type",
"elif",
"attr_name",
"==",
"'Certificate Length'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'X.509 Certificate Identifier'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'X.509 Certificate Subject'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'X.509 Certificate Issuer'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Certificate Identifier'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Certificate Subject'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Certificate Issuer'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Digital Signature Algorithm'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Digest'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Operation Policy Name'",
":",
"return",
"managed_object",
".",
"operation_policy_name",
"elif",
"attr_name",
"==",
"'Cryptographic Usage Mask'",
":",
"return",
"managed_object",
".",
"cryptographic_usage_masks",
"elif",
"attr_name",
"==",
"'Lease Time'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Usage Limits'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'State'",
":",
"return",
"managed_object",
".",
"state",
"elif",
"attr_name",
"==",
"'Initial Date'",
":",
"return",
"managed_object",
".",
"initial_date",
"elif",
"attr_name",
"==",
"'Activation Date'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Process Start Date'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Protect Stop Date'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Deactivation Date'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Destroy Date'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Compromise Occurrence Date'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Compromise Date'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Revocation Reason'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Archive Date'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Object Group'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Fresh'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Link'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Application Specific Information'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Contact Information'",
":",
"return",
"None",
"elif",
"attr_name",
"==",
"'Last Change Date'",
":",
"return",
"None",
"else",
":",
"# Since custom attribute names are possible, just return None",
"# for unrecognized attributes. This satisfies the spec.",
"return",
"None"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
KmipEngine._set_attributes_on_managed_object
|
Given a kmip.pie object and a dictionary of attributes, attempt to set
the attribute values on the object.
|
kmip/services/server/engine.py
|
def _set_attributes_on_managed_object(self, managed_object, attributes):
"""
Given a kmip.pie object and a dictionary of attributes, attempt to set
the attribute values on the object.
"""
for attribute_name, attribute_value in six.iteritems(attributes):
object_type = managed_object._object_type
if self._attribute_policy.is_attribute_applicable_to_object_type(
attribute_name,
object_type):
self._set_attribute_on_managed_object(
managed_object,
(attribute_name, attribute_value)
)
else:
name = object_type.name
raise exceptions.InvalidField(
"Cannot set {0} attribute on {1} object.".format(
attribute_name,
''.join([x.capitalize() for x in name.split('_')])
)
)
|
def _set_attributes_on_managed_object(self, managed_object, attributes):
"""
Given a kmip.pie object and a dictionary of attributes, attempt to set
the attribute values on the object.
"""
for attribute_name, attribute_value in six.iteritems(attributes):
object_type = managed_object._object_type
if self._attribute_policy.is_attribute_applicable_to_object_type(
attribute_name,
object_type):
self._set_attribute_on_managed_object(
managed_object,
(attribute_name, attribute_value)
)
else:
name = object_type.name
raise exceptions.InvalidField(
"Cannot set {0} attribute on {1} object.".format(
attribute_name,
''.join([x.capitalize() for x in name.split('_')])
)
)
|
[
"Given",
"a",
"kmip",
".",
"pie",
"object",
"and",
"a",
"dictionary",
"of",
"attributes",
"attempt",
"to",
"set",
"the",
"attribute",
"values",
"on",
"the",
"object",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/engine.py#L721-L742
|
[
"def",
"_set_attributes_on_managed_object",
"(",
"self",
",",
"managed_object",
",",
"attributes",
")",
":",
"for",
"attribute_name",
",",
"attribute_value",
"in",
"six",
".",
"iteritems",
"(",
"attributes",
")",
":",
"object_type",
"=",
"managed_object",
".",
"_object_type",
"if",
"self",
".",
"_attribute_policy",
".",
"is_attribute_applicable_to_object_type",
"(",
"attribute_name",
",",
"object_type",
")",
":",
"self",
".",
"_set_attribute_on_managed_object",
"(",
"managed_object",
",",
"(",
"attribute_name",
",",
"attribute_value",
")",
")",
"else",
":",
"name",
"=",
"object_type",
".",
"name",
"raise",
"exceptions",
".",
"InvalidField",
"(",
"\"Cannot set {0} attribute on {1} object.\"",
".",
"format",
"(",
"attribute_name",
",",
"''",
".",
"join",
"(",
"[",
"x",
".",
"capitalize",
"(",
")",
"for",
"x",
"in",
"name",
".",
"split",
"(",
"'_'",
")",
"]",
")",
")",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
KmipEngine._set_attribute_on_managed_object
|
Set the attribute value on the kmip.pie managed object.
|
kmip/services/server/engine.py
|
def _set_attribute_on_managed_object(self, managed_object, attribute):
"""
Set the attribute value on the kmip.pie managed object.
"""
attribute_name = attribute[0]
attribute_value = attribute[1]
if self._attribute_policy.is_attribute_multivalued(attribute_name):
if attribute_name == 'Name':
managed_object.names.extend(
[x.name_value.value for x in attribute_value]
)
for name in managed_object.names:
if managed_object.names.count(name) > 1:
raise exceptions.InvalidField(
"Cannot set duplicate name values."
)
else:
# TODO (peterhamilton) Remove when all attributes are supported
raise exceptions.InvalidField(
"The {0} attribute is unsupported.".format(attribute_name)
)
else:
field = None
value = attribute_value.value
if attribute_name == 'Cryptographic Algorithm':
field = 'cryptographic_algorithm'
elif attribute_name == 'Cryptographic Length':
field = 'cryptographic_length'
elif attribute_name == 'Cryptographic Usage Mask':
field = 'cryptographic_usage_masks'
value = list()
for e in enums.CryptographicUsageMask:
if e.value & attribute_value.value:
value.append(e)
elif attribute_name == 'Operation Policy Name':
field = 'operation_policy_name'
if field:
existing_value = getattr(managed_object, field)
if existing_value:
if existing_value != value:
raise exceptions.InvalidField(
"Cannot overwrite the {0} attribute.".format(
attribute_name
)
)
else:
setattr(managed_object, field, value)
else:
# TODO (peterhamilton) Remove when all attributes are supported
raise exceptions.InvalidField(
"The {0} attribute is unsupported.".format(attribute_name)
)
|
def _set_attribute_on_managed_object(self, managed_object, attribute):
"""
Set the attribute value on the kmip.pie managed object.
"""
attribute_name = attribute[0]
attribute_value = attribute[1]
if self._attribute_policy.is_attribute_multivalued(attribute_name):
if attribute_name == 'Name':
managed_object.names.extend(
[x.name_value.value for x in attribute_value]
)
for name in managed_object.names:
if managed_object.names.count(name) > 1:
raise exceptions.InvalidField(
"Cannot set duplicate name values."
)
else:
# TODO (peterhamilton) Remove when all attributes are supported
raise exceptions.InvalidField(
"The {0} attribute is unsupported.".format(attribute_name)
)
else:
field = None
value = attribute_value.value
if attribute_name == 'Cryptographic Algorithm':
field = 'cryptographic_algorithm'
elif attribute_name == 'Cryptographic Length':
field = 'cryptographic_length'
elif attribute_name == 'Cryptographic Usage Mask':
field = 'cryptographic_usage_masks'
value = list()
for e in enums.CryptographicUsageMask:
if e.value & attribute_value.value:
value.append(e)
elif attribute_name == 'Operation Policy Name':
field = 'operation_policy_name'
if field:
existing_value = getattr(managed_object, field)
if existing_value:
if existing_value != value:
raise exceptions.InvalidField(
"Cannot overwrite the {0} attribute.".format(
attribute_name
)
)
else:
setattr(managed_object, field, value)
else:
# TODO (peterhamilton) Remove when all attributes are supported
raise exceptions.InvalidField(
"The {0} attribute is unsupported.".format(attribute_name)
)
|
[
"Set",
"the",
"attribute",
"value",
"on",
"the",
"kmip",
".",
"pie",
"managed",
"object",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/engine.py#L744-L798
|
[
"def",
"_set_attribute_on_managed_object",
"(",
"self",
",",
"managed_object",
",",
"attribute",
")",
":",
"attribute_name",
"=",
"attribute",
"[",
"0",
"]",
"attribute_value",
"=",
"attribute",
"[",
"1",
"]",
"if",
"self",
".",
"_attribute_policy",
".",
"is_attribute_multivalued",
"(",
"attribute_name",
")",
":",
"if",
"attribute_name",
"==",
"'Name'",
":",
"managed_object",
".",
"names",
".",
"extend",
"(",
"[",
"x",
".",
"name_value",
".",
"value",
"for",
"x",
"in",
"attribute_value",
"]",
")",
"for",
"name",
"in",
"managed_object",
".",
"names",
":",
"if",
"managed_object",
".",
"names",
".",
"count",
"(",
"name",
")",
">",
"1",
":",
"raise",
"exceptions",
".",
"InvalidField",
"(",
"\"Cannot set duplicate name values.\"",
")",
"else",
":",
"# TODO (peterhamilton) Remove when all attributes are supported",
"raise",
"exceptions",
".",
"InvalidField",
"(",
"\"The {0} attribute is unsupported.\"",
".",
"format",
"(",
"attribute_name",
")",
")",
"else",
":",
"field",
"=",
"None",
"value",
"=",
"attribute_value",
".",
"value",
"if",
"attribute_name",
"==",
"'Cryptographic Algorithm'",
":",
"field",
"=",
"'cryptographic_algorithm'",
"elif",
"attribute_name",
"==",
"'Cryptographic Length'",
":",
"field",
"=",
"'cryptographic_length'",
"elif",
"attribute_name",
"==",
"'Cryptographic Usage Mask'",
":",
"field",
"=",
"'cryptographic_usage_masks'",
"value",
"=",
"list",
"(",
")",
"for",
"e",
"in",
"enums",
".",
"CryptographicUsageMask",
":",
"if",
"e",
".",
"value",
"&",
"attribute_value",
".",
"value",
":",
"value",
".",
"append",
"(",
"e",
")",
"elif",
"attribute_name",
"==",
"'Operation Policy Name'",
":",
"field",
"=",
"'operation_policy_name'",
"if",
"field",
":",
"existing_value",
"=",
"getattr",
"(",
"managed_object",
",",
"field",
")",
"if",
"existing_value",
":",
"if",
"existing_value",
"!=",
"value",
":",
"raise",
"exceptions",
".",
"InvalidField",
"(",
"\"Cannot overwrite the {0} attribute.\"",
".",
"format",
"(",
"attribute_name",
")",
")",
"else",
":",
"setattr",
"(",
"managed_object",
",",
"field",
",",
"value",
")",
"else",
":",
"# TODO (peterhamilton) Remove when all attributes are supported",
"raise",
"exceptions",
".",
"InvalidField",
"(",
"\"The {0} attribute is unsupported.\"",
".",
"format",
"(",
"attribute_name",
")",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
KmipEngine.get_relevant_policy_section
|
Look up the policy corresponding to the provided policy name and
group (optional). Log any issues found during the look up.
|
kmip/services/server/engine.py
|
def get_relevant_policy_section(self, policy_name, group=None):
"""
Look up the policy corresponding to the provided policy name and
group (optional). Log any issues found during the look up.
"""
policy_bundle = self._operation_policies.get(policy_name)
if not policy_bundle:
self._logger.warning(
"The '{}' policy does not exist.".format(policy_name)
)
return None
if group:
groups_policy_bundle = policy_bundle.get('groups')
if not groups_policy_bundle:
self._logger.debug(
"The '{}' policy does not support groups.".format(
policy_name
)
)
return None
else:
group_policy = groups_policy_bundle.get(group)
if not group_policy:
self._logger.debug(
"The '{}' policy does not support group '{}'.".format(
policy_name,
group
)
)
return None
else:
return group_policy
else:
return policy_bundle.get('preset')
|
def get_relevant_policy_section(self, policy_name, group=None):
"""
Look up the policy corresponding to the provided policy name and
group (optional). Log any issues found during the look up.
"""
policy_bundle = self._operation_policies.get(policy_name)
if not policy_bundle:
self._logger.warning(
"The '{}' policy does not exist.".format(policy_name)
)
return None
if group:
groups_policy_bundle = policy_bundle.get('groups')
if not groups_policy_bundle:
self._logger.debug(
"The '{}' policy does not support groups.".format(
policy_name
)
)
return None
else:
group_policy = groups_policy_bundle.get(group)
if not group_policy:
self._logger.debug(
"The '{}' policy does not support group '{}'.".format(
policy_name,
group
)
)
return None
else:
return group_policy
else:
return policy_bundle.get('preset')
|
[
"Look",
"up",
"the",
"policy",
"corresponding",
"to",
"the",
"provided",
"policy",
"name",
"and",
"group",
"(",
"optional",
")",
".",
"Log",
"any",
"issues",
"found",
"during",
"the",
"look",
"up",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/engine.py#L828-L863
|
[
"def",
"get_relevant_policy_section",
"(",
"self",
",",
"policy_name",
",",
"group",
"=",
"None",
")",
":",
"policy_bundle",
"=",
"self",
".",
"_operation_policies",
".",
"get",
"(",
"policy_name",
")",
"if",
"not",
"policy_bundle",
":",
"self",
".",
"_logger",
".",
"warning",
"(",
"\"The '{}' policy does not exist.\"",
".",
"format",
"(",
"policy_name",
")",
")",
"return",
"None",
"if",
"group",
":",
"groups_policy_bundle",
"=",
"policy_bundle",
".",
"get",
"(",
"'groups'",
")",
"if",
"not",
"groups_policy_bundle",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"The '{}' policy does not support groups.\"",
".",
"format",
"(",
"policy_name",
")",
")",
"return",
"None",
"else",
":",
"group_policy",
"=",
"groups_policy_bundle",
".",
"get",
"(",
"group",
")",
"if",
"not",
"group_policy",
":",
"self",
".",
"_logger",
".",
"debug",
"(",
"\"The '{}' policy does not support group '{}'.\"",
".",
"format",
"(",
"policy_name",
",",
"group",
")",
")",
"return",
"None",
"else",
":",
"return",
"group_policy",
"else",
":",
"return",
"policy_bundle",
".",
"get",
"(",
"'preset'",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
KmipEngine.is_allowed
|
Determine if object access is allowed for the provided policy and
session settings.
|
kmip/services/server/engine.py
|
def is_allowed(
self,
policy_name,
session_user,
session_group,
object_owner,
object_type,
operation
):
"""
Determine if object access is allowed for the provided policy and
session settings.
"""
policy_section = self.get_relevant_policy_section(
policy_name,
session_group
)
if policy_section is None:
return False
object_policy = policy_section.get(object_type)
if not object_policy:
self._logger.warning(
"The '{0}' policy does not apply to {1} objects.".format(
policy_name,
self._get_enum_string(object_type)
)
)
return False
operation_object_policy = object_policy.get(operation)
if not operation_object_policy:
self._logger.warning(
"The '{0}' policy does not apply to {1} operations on {2} "
"objects.".format(
policy_name,
self._get_enum_string(operation),
self._get_enum_string(object_type)
)
)
return False
if operation_object_policy == enums.Policy.ALLOW_ALL:
return True
elif operation_object_policy == enums.Policy.ALLOW_OWNER:
if session_user == object_owner:
return True
else:
return False
elif operation_object_policy == enums.Policy.DISALLOW_ALL:
return False
else:
return False
|
def is_allowed(
self,
policy_name,
session_user,
session_group,
object_owner,
object_type,
operation
):
"""
Determine if object access is allowed for the provided policy and
session settings.
"""
policy_section = self.get_relevant_policy_section(
policy_name,
session_group
)
if policy_section is None:
return False
object_policy = policy_section.get(object_type)
if not object_policy:
self._logger.warning(
"The '{0}' policy does not apply to {1} objects.".format(
policy_name,
self._get_enum_string(object_type)
)
)
return False
operation_object_policy = object_policy.get(operation)
if not operation_object_policy:
self._logger.warning(
"The '{0}' policy does not apply to {1} operations on {2} "
"objects.".format(
policy_name,
self._get_enum_string(operation),
self._get_enum_string(object_type)
)
)
return False
if operation_object_policy == enums.Policy.ALLOW_ALL:
return True
elif operation_object_policy == enums.Policy.ALLOW_OWNER:
if session_user == object_owner:
return True
else:
return False
elif operation_object_policy == enums.Policy.DISALLOW_ALL:
return False
else:
return False
|
[
"Determine",
"if",
"object",
"access",
"is",
"allowed",
"for",
"the",
"provided",
"policy",
"and",
"session",
"settings",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/engine.py#L865-L917
|
[
"def",
"is_allowed",
"(",
"self",
",",
"policy_name",
",",
"session_user",
",",
"session_group",
",",
"object_owner",
",",
"object_type",
",",
"operation",
")",
":",
"policy_section",
"=",
"self",
".",
"get_relevant_policy_section",
"(",
"policy_name",
",",
"session_group",
")",
"if",
"policy_section",
"is",
"None",
":",
"return",
"False",
"object_policy",
"=",
"policy_section",
".",
"get",
"(",
"object_type",
")",
"if",
"not",
"object_policy",
":",
"self",
".",
"_logger",
".",
"warning",
"(",
"\"The '{0}' policy does not apply to {1} objects.\"",
".",
"format",
"(",
"policy_name",
",",
"self",
".",
"_get_enum_string",
"(",
"object_type",
")",
")",
")",
"return",
"False",
"operation_object_policy",
"=",
"object_policy",
".",
"get",
"(",
"operation",
")",
"if",
"not",
"operation_object_policy",
":",
"self",
".",
"_logger",
".",
"warning",
"(",
"\"The '{0}' policy does not apply to {1} operations on {2} \"",
"\"objects.\"",
".",
"format",
"(",
"policy_name",
",",
"self",
".",
"_get_enum_string",
"(",
"operation",
")",
",",
"self",
".",
"_get_enum_string",
"(",
"object_type",
")",
")",
")",
"return",
"False",
"if",
"operation_object_policy",
"==",
"enums",
".",
"Policy",
".",
"ALLOW_ALL",
":",
"return",
"True",
"elif",
"operation_object_policy",
"==",
"enums",
".",
"Policy",
".",
"ALLOW_OWNER",
":",
"if",
"session_user",
"==",
"object_owner",
":",
"return",
"True",
"else",
":",
"return",
"False",
"elif",
"operation_object_policy",
"==",
"enums",
".",
"Policy",
".",
"DISALLOW_ALL",
":",
"return",
"False",
"else",
":",
"return",
"False"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
DecryptRequestPayload.write
|
Write the data encoding the Decrypt request payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is not defined.
|
kmip/core/messages/payloads/decrypt.py
|
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Decrypt request payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is not defined.
"""
local_stream = utils.BytearrayStream()
if self._unique_identifier:
self._unique_identifier.write(
local_stream,
kmip_version=kmip_version
)
if self._cryptographic_parameters:
self._cryptographic_parameters.write(
local_stream,
kmip_version=kmip_version
)
if self._data:
self._data.write(local_stream, kmip_version=kmip_version)
else:
raise ValueError("invalid payload missing the data attribute")
if self._iv_counter_nonce:
self._iv_counter_nonce.write(
local_stream,
kmip_version=kmip_version
)
self.length = local_stream.length()
super(DecryptRequestPayload, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
|
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the Decrypt request payload to a stream.
Args:
output_stream (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: Raised if the data attribute is not defined.
"""
local_stream = utils.BytearrayStream()
if self._unique_identifier:
self._unique_identifier.write(
local_stream,
kmip_version=kmip_version
)
if self._cryptographic_parameters:
self._cryptographic_parameters.write(
local_stream,
kmip_version=kmip_version
)
if self._data:
self._data.write(local_stream, kmip_version=kmip_version)
else:
raise ValueError("invalid payload missing the data attribute")
if self._iv_counter_nonce:
self._iv_counter_nonce.write(
local_stream,
kmip_version=kmip_version
)
self.length = local_stream.length()
super(DecryptRequestPayload, self).write(
output_stream,
kmip_version=kmip_version
)
output_stream.write(local_stream.buffer)
|
[
"Write",
"the",
"data",
"encoding",
"the",
"Decrypt",
"request",
"payload",
"to",
"a",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/decrypt.py#L207-L251
|
[
"def",
"write",
"(",
"self",
",",
"output_stream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"local_stream",
"=",
"utils",
".",
"BytearrayStream",
"(",
")",
"if",
"self",
".",
"_unique_identifier",
":",
"self",
".",
"_unique_identifier",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_cryptographic_parameters",
":",
"self",
".",
"_cryptographic_parameters",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_data",
":",
"self",
".",
"_data",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"ValueError",
"(",
"\"invalid payload missing the data attribute\"",
")",
"if",
"self",
".",
"_iv_counter_nonce",
":",
"self",
".",
"_iv_counter_nonce",
".",
"write",
"(",
"local_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"length",
"=",
"local_stream",
".",
"length",
"(",
")",
"super",
"(",
"DecryptRequestPayload",
",",
"self",
")",
".",
"write",
"(",
"output_stream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"output_stream",
".",
"write",
"(",
"local_stream",
".",
"buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
RevokeRequestPayload.read
|
Read the data encoding the RevokeRequestPayload object and decode it
into its constituent parts.
Args:
istream (Stream): A data stream containing encoded object data,
supporting a read method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/messages/payloads/revoke.py
|
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the RevokeRequestPayload object and decode it
into its constituent parts.
Args:
istream (Stream): A data stream containing encoded object data,
supporting a read method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(RevokeRequestPayload, self).read(
istream,
kmip_version=kmip_version
)
tstream = BytearrayStream(istream.read(self.length))
self.unique_identifier = attributes.UniqueIdentifier()
self.unique_identifier.read(tstream, kmip_version=kmip_version)
self.revocation_reason = objects.RevocationReason()
self.revocation_reason.read(tstream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.COMPROMISE_OCCURRENCE_DATE, tstream):
self.compromise_occurrence_date = primitives.DateTime(
tag=enums.Tags.COMPROMISE_OCCURRENCE_DATE)
self.compromise_occurrence_date.read(
tstream,
kmip_version=kmip_version
)
self.is_oversized(tstream)
self.validate()
|
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the RevokeRequestPayload object and decode it
into its constituent parts.
Args:
istream (Stream): A data stream containing encoded object data,
supporting a read method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(RevokeRequestPayload, self).read(
istream,
kmip_version=kmip_version
)
tstream = BytearrayStream(istream.read(self.length))
self.unique_identifier = attributes.UniqueIdentifier()
self.unique_identifier.read(tstream, kmip_version=kmip_version)
self.revocation_reason = objects.RevocationReason()
self.revocation_reason.read(tstream, kmip_version=kmip_version)
if self.is_tag_next(enums.Tags.COMPROMISE_OCCURRENCE_DATE, tstream):
self.compromise_occurrence_date = primitives.DateTime(
tag=enums.Tags.COMPROMISE_OCCURRENCE_DATE)
self.compromise_occurrence_date.read(
tstream,
kmip_version=kmip_version
)
self.is_oversized(tstream)
self.validate()
|
[
"Read",
"the",
"data",
"encoding",
"the",
"RevokeRequestPayload",
"object",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
".",
"Args",
":",
"istream",
"(",
"Stream",
")",
":",
"A",
"data",
"stream",
"containing",
"encoded",
"object",
"data",
"supporting",
"a",
"read",
"method",
";",
"usually",
"a",
"BytearrayStream",
"object",
".",
"kmip_version",
"(",
"KMIPVersion",
")",
":",
"An",
"enumeration",
"defining",
"the",
"KMIP",
"version",
"with",
"which",
"the",
"object",
"will",
"be",
"decoded",
".",
"Optional",
"defaults",
"to",
"KMIP",
"1",
".",
"0",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/revoke.py#L63-L95
|
[
"def",
"read",
"(",
"self",
",",
"istream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"RevokeRequestPayload",
",",
"self",
")",
".",
"read",
"(",
"istream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"tstream",
"=",
"BytearrayStream",
"(",
"istream",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"self",
".",
"unique_identifier",
"=",
"attributes",
".",
"UniqueIdentifier",
"(",
")",
"self",
".",
"unique_identifier",
".",
"read",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"revocation_reason",
"=",
"objects",
".",
"RevocationReason",
"(",
")",
"self",
".",
"revocation_reason",
".",
"read",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"COMPROMISE_OCCURRENCE_DATE",
",",
"tstream",
")",
":",
"self",
".",
"compromise_occurrence_date",
"=",
"primitives",
".",
"DateTime",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"COMPROMISE_OCCURRENCE_DATE",
")",
"self",
".",
"compromise_occurrence_date",
".",
"read",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"is_oversized",
"(",
"tstream",
")",
"self",
".",
"validate",
"(",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
RevokeRequestPayload.write
|
Write the data encoding the RevokeRequestPayload object to a stream.
Args:
ostream (Stream): A data stream in which to encode object data,
supporting a write method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/messages/payloads/revoke.py
|
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the RevokeRequestPayload object to a stream.
Args:
ostream (Stream): A data stream in which to encode object data,
supporting a write method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
tstream = BytearrayStream()
# Write the contents of the request payload
if self.unique_identifier is not None:
self.unique_identifier.write(tstream, kmip_version=kmip_version)
self.revocation_reason.write(tstream, kmip_version=kmip_version)
if self.compromise_occurrence_date is not None:
self.compromise_occurrence_date.write(
tstream,
kmip_version=kmip_version
)
# Write the length and value of the request payload
self.length = tstream.length()
super(RevokeRequestPayload, self).write(
ostream,
kmip_version=kmip_version
)
ostream.write(tstream.buffer)
|
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the RevokeRequestPayload object to a stream.
Args:
ostream (Stream): A data stream in which to encode object data,
supporting a write method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
tstream = BytearrayStream()
# Write the contents of the request payload
if self.unique_identifier is not None:
self.unique_identifier.write(tstream, kmip_version=kmip_version)
self.revocation_reason.write(tstream, kmip_version=kmip_version)
if self.compromise_occurrence_date is not None:
self.compromise_occurrence_date.write(
tstream,
kmip_version=kmip_version
)
# Write the length and value of the request payload
self.length = tstream.length()
super(RevokeRequestPayload, self).write(
ostream,
kmip_version=kmip_version
)
ostream.write(tstream.buffer)
|
[
"Write",
"the",
"data",
"encoding",
"the",
"RevokeRequestPayload",
"object",
"to",
"a",
"stream",
".",
"Args",
":",
"ostream",
"(",
"Stream",
")",
":",
"A",
"data",
"stream",
"in",
"which",
"to",
"encode",
"object",
"data",
"supporting",
"a",
"write",
"method",
";",
"usually",
"a",
"BytearrayStream",
"object",
".",
"kmip_version",
"(",
"KMIPVersion",
")",
":",
"An",
"enumeration",
"defining",
"the",
"KMIP",
"version",
"with",
"which",
"the",
"object",
"will",
"be",
"encoded",
".",
"Optional",
"defaults",
"to",
"KMIP",
"1",
".",
"0",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/revoke.py#L97-L127
|
[
"def",
"write",
"(",
"self",
",",
"ostream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"tstream",
"=",
"BytearrayStream",
"(",
")",
"# Write the contents of the request payload",
"if",
"self",
".",
"unique_identifier",
"is",
"not",
"None",
":",
"self",
".",
"unique_identifier",
".",
"write",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"revocation_reason",
".",
"write",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"compromise_occurrence_date",
"is",
"not",
"None",
":",
"self",
".",
"compromise_occurrence_date",
".",
"write",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"# Write the length and value of the request payload",
"self",
".",
"length",
"=",
"tstream",
".",
"length",
"(",
")",
"super",
"(",
"RevokeRequestPayload",
",",
"self",
")",
".",
"write",
"(",
"ostream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"ostream",
".",
"write",
"(",
"tstream",
".",
"buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
RevokeRequestPayload.validate
|
Error check the attributes of the ActivateRequestPayload object.
|
kmip/core/messages/payloads/revoke.py
|
def validate(self):
"""
Error check the attributes of the ActivateRequestPayload object.
"""
if self.unique_identifier is not None:
if not isinstance(self.unique_identifier,
attributes.UniqueIdentifier):
msg = "invalid unique identifier"
raise TypeError(msg)
if self.compromise_occurrence_date is not None:
if not isinstance(self.compromise_occurrence_date,
primitives.DateTime):
msg = "invalid compromise time"
raise TypeError(msg)
if not isinstance(self.revocation_reason, objects.RevocationReason):
msg = "invalid revocation reason"
raise TypeError(msg)
|
def validate(self):
"""
Error check the attributes of the ActivateRequestPayload object.
"""
if self.unique_identifier is not None:
if not isinstance(self.unique_identifier,
attributes.UniqueIdentifier):
msg = "invalid unique identifier"
raise TypeError(msg)
if self.compromise_occurrence_date is not None:
if not isinstance(self.compromise_occurrence_date,
primitives.DateTime):
msg = "invalid compromise time"
raise TypeError(msg)
if not isinstance(self.revocation_reason, objects.RevocationReason):
msg = "invalid revocation reason"
raise TypeError(msg)
|
[
"Error",
"check",
"the",
"attributes",
"of",
"the",
"ActivateRequestPayload",
"object",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/revoke.py#L129-L145
|
[
"def",
"validate",
"(",
"self",
")",
":",
"if",
"self",
".",
"unique_identifier",
"is",
"not",
"None",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"unique_identifier",
",",
"attributes",
".",
"UniqueIdentifier",
")",
":",
"msg",
"=",
"\"invalid unique identifier\"",
"raise",
"TypeError",
"(",
"msg",
")",
"if",
"self",
".",
"compromise_occurrence_date",
"is",
"not",
"None",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"compromise_occurrence_date",
",",
"primitives",
".",
"DateTime",
")",
":",
"msg",
"=",
"\"invalid compromise time\"",
"raise",
"TypeError",
"(",
"msg",
")",
"if",
"not",
"isinstance",
"(",
"self",
".",
"revocation_reason",
",",
"objects",
".",
"RevocationReason",
")",
":",
"msg",
"=",
"\"invalid revocation reason\"",
"raise",
"TypeError",
"(",
"msg",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
RevokeResponsePayload.read
|
Read the data encoding the RevokeResponsePayload object and decode it
into its constituent parts.
Args:
istream (Stream): A data stream containing encoded object data,
supporting a read method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/messages/payloads/revoke.py
|
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the RevokeResponsePayload object and decode it
into its constituent parts.
Args:
istream (Stream): A data stream containing encoded object data,
supporting a read method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(RevokeResponsePayload, self).read(
istream,
kmip_version=kmip_version
)
tstream = BytearrayStream(istream.read(self.length))
self.unique_identifier = attributes.UniqueIdentifier()
self.unique_identifier.read(tstream, kmip_version=kmip_version)
self.is_oversized(tstream)
self.validate()
|
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the RevokeResponsePayload object and decode it
into its constituent parts.
Args:
istream (Stream): A data stream containing encoded object data,
supporting a read method; usually a BytearrayStream object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(RevokeResponsePayload, self).read(
istream,
kmip_version=kmip_version
)
tstream = BytearrayStream(istream.read(self.length))
self.unique_identifier = attributes.UniqueIdentifier()
self.unique_identifier.read(tstream, kmip_version=kmip_version)
self.is_oversized(tstream)
self.validate()
|
[
"Read",
"the",
"data",
"encoding",
"the",
"RevokeResponsePayload",
"object",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
".",
"Args",
":",
"istream",
"(",
"Stream",
")",
":",
"A",
"data",
"stream",
"containing",
"encoded",
"object",
"data",
"supporting",
"a",
"read",
"method",
";",
"usually",
"a",
"BytearrayStream",
"object",
".",
"kmip_version",
"(",
"KMIPVersion",
")",
":",
"An",
"enumeration",
"defining",
"the",
"KMIP",
"version",
"with",
"which",
"the",
"object",
"will",
"be",
"decoded",
".",
"Optional",
"defaults",
"to",
"KMIP",
"1",
".",
"0",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/revoke.py#L172-L193
|
[
"def",
"read",
"(",
"self",
",",
"istream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"RevokeResponsePayload",
",",
"self",
")",
".",
"read",
"(",
"istream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"tstream",
"=",
"BytearrayStream",
"(",
"istream",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"self",
".",
"unique_identifier",
"=",
"attributes",
".",
"UniqueIdentifier",
"(",
")",
"self",
".",
"unique_identifier",
".",
"read",
"(",
"tstream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"is_oversized",
"(",
"tstream",
")",
"self",
".",
"validate",
"(",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
SecretFactory.create
|
Create a secret object of the specified type with the given value.
Args:
secret_type (ObjectType): An ObjectType enumeration specifying the
type of secret to create.
value (dict): A dictionary containing secret data. Optional,
defaults to None.
Returns:
secret: The newly constructed secret object.
Raises:
TypeError: If the provided secret type is unrecognized.
Example:
>>> factory.create(ObjectType.SYMMETRIC_KEY)
SymmetricKey(...)
|
kmip/core/factories/secrets.py
|
def create(self, secret_type, value=None):
"""
Create a secret object of the specified type with the given value.
Args:
secret_type (ObjectType): An ObjectType enumeration specifying the
type of secret to create.
value (dict): A dictionary containing secret data. Optional,
defaults to None.
Returns:
secret: The newly constructed secret object.
Raises:
TypeError: If the provided secret type is unrecognized.
Example:
>>> factory.create(ObjectType.SYMMETRIC_KEY)
SymmetricKey(...)
"""
if secret_type is ObjectType.CERTIFICATE:
return self._create_certificate(value)
elif secret_type is ObjectType.SYMMETRIC_KEY:
return self._create_symmetric_key(value)
elif secret_type is ObjectType.PUBLIC_KEY:
return self._create_public_key(value)
elif secret_type is ObjectType.PRIVATE_KEY:
return self._create_private_key(value)
elif secret_type is ObjectType.SPLIT_KEY:
return self._create_split_key(value)
elif secret_type is ObjectType.TEMPLATE:
return self._create_template(value)
elif secret_type is ObjectType.SECRET_DATA:
return self._create_secret_data(value)
elif secret_type is ObjectType.OPAQUE_DATA:
return self._create_opaque_data(value)
else:
raise TypeError("Unrecognized secret type: {0}".format(
secret_type))
|
def create(self, secret_type, value=None):
"""
Create a secret object of the specified type with the given value.
Args:
secret_type (ObjectType): An ObjectType enumeration specifying the
type of secret to create.
value (dict): A dictionary containing secret data. Optional,
defaults to None.
Returns:
secret: The newly constructed secret object.
Raises:
TypeError: If the provided secret type is unrecognized.
Example:
>>> factory.create(ObjectType.SYMMETRIC_KEY)
SymmetricKey(...)
"""
if secret_type is ObjectType.CERTIFICATE:
return self._create_certificate(value)
elif secret_type is ObjectType.SYMMETRIC_KEY:
return self._create_symmetric_key(value)
elif secret_type is ObjectType.PUBLIC_KEY:
return self._create_public_key(value)
elif secret_type is ObjectType.PRIVATE_KEY:
return self._create_private_key(value)
elif secret_type is ObjectType.SPLIT_KEY:
return self._create_split_key(value)
elif secret_type is ObjectType.TEMPLATE:
return self._create_template(value)
elif secret_type is ObjectType.SECRET_DATA:
return self._create_secret_data(value)
elif secret_type is ObjectType.OPAQUE_DATA:
return self._create_opaque_data(value)
else:
raise TypeError("Unrecognized secret type: {0}".format(
secret_type))
|
[
"Create",
"a",
"secret",
"object",
"of",
"the",
"specified",
"type",
"with",
"the",
"given",
"value",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/factories/secrets.py#L48-L86
|
[
"def",
"create",
"(",
"self",
",",
"secret_type",
",",
"value",
"=",
"None",
")",
":",
"if",
"secret_type",
"is",
"ObjectType",
".",
"CERTIFICATE",
":",
"return",
"self",
".",
"_create_certificate",
"(",
"value",
")",
"elif",
"secret_type",
"is",
"ObjectType",
".",
"SYMMETRIC_KEY",
":",
"return",
"self",
".",
"_create_symmetric_key",
"(",
"value",
")",
"elif",
"secret_type",
"is",
"ObjectType",
".",
"PUBLIC_KEY",
":",
"return",
"self",
".",
"_create_public_key",
"(",
"value",
")",
"elif",
"secret_type",
"is",
"ObjectType",
".",
"PRIVATE_KEY",
":",
"return",
"self",
".",
"_create_private_key",
"(",
"value",
")",
"elif",
"secret_type",
"is",
"ObjectType",
".",
"SPLIT_KEY",
":",
"return",
"self",
".",
"_create_split_key",
"(",
"value",
")",
"elif",
"secret_type",
"is",
"ObjectType",
".",
"TEMPLATE",
":",
"return",
"self",
".",
"_create_template",
"(",
"value",
")",
"elif",
"secret_type",
"is",
"ObjectType",
".",
"SECRET_DATA",
":",
"return",
"self",
".",
"_create_secret_data",
"(",
"value",
")",
"elif",
"secret_type",
"is",
"ObjectType",
".",
"OPAQUE_DATA",
":",
"return",
"self",
".",
"_create_opaque_data",
"(",
"value",
")",
"else",
":",
"raise",
"TypeError",
"(",
"\"Unrecognized secret type: {0}\"",
".",
"format",
"(",
"secret_type",
")",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
KmipServerConfig.set_setting
|
Set a specific setting value.
This will overwrite the current setting value for the specified
setting.
Args:
setting (string): The name of the setting to set (e.g.,
'certificate_path', 'hostname'). Required.
value (misc): The value of the setting to set. Type varies based
on setting. Required.
Raises:
ConfigurationError: Raised if the setting is not supported or if
the setting value is invalid.
|
kmip/services/server/config.py
|
def set_setting(self, setting, value):
"""
Set a specific setting value.
This will overwrite the current setting value for the specified
setting.
Args:
setting (string): The name of the setting to set (e.g.,
'certificate_path', 'hostname'). Required.
value (misc): The value of the setting to set. Type varies based
on setting. Required.
Raises:
ConfigurationError: Raised if the setting is not supported or if
the setting value is invalid.
"""
if setting not in self._expected_settings + self._optional_settings:
raise exceptions.ConfigurationError(
"Setting '{0}' is not supported.".format(setting)
)
if setting == 'hostname':
self._set_hostname(value)
elif setting == 'port':
self._set_port(value)
elif setting == 'certificate_path':
self._set_certificate_path(value)
elif setting == 'key_path':
self._set_key_path(value)
elif setting == 'ca_path':
self._set_ca_path(value)
elif setting == 'auth_suite':
self._set_auth_suite(value)
elif setting == 'policy_path':
self._set_policy_path(value)
elif setting == 'enable_tls_client_auth':
self._set_enable_tls_client_auth(value)
elif setting == 'tls_cipher_suites':
self._set_tls_cipher_suites(value)
elif setting == 'logging_level':
self._set_logging_level(value)
else:
self._set_database_path(value)
|
def set_setting(self, setting, value):
"""
Set a specific setting value.
This will overwrite the current setting value for the specified
setting.
Args:
setting (string): The name of the setting to set (e.g.,
'certificate_path', 'hostname'). Required.
value (misc): The value of the setting to set. Type varies based
on setting. Required.
Raises:
ConfigurationError: Raised if the setting is not supported or if
the setting value is invalid.
"""
if setting not in self._expected_settings + self._optional_settings:
raise exceptions.ConfigurationError(
"Setting '{0}' is not supported.".format(setting)
)
if setting == 'hostname':
self._set_hostname(value)
elif setting == 'port':
self._set_port(value)
elif setting == 'certificate_path':
self._set_certificate_path(value)
elif setting == 'key_path':
self._set_key_path(value)
elif setting == 'ca_path':
self._set_ca_path(value)
elif setting == 'auth_suite':
self._set_auth_suite(value)
elif setting == 'policy_path':
self._set_policy_path(value)
elif setting == 'enable_tls_client_auth':
self._set_enable_tls_client_auth(value)
elif setting == 'tls_cipher_suites':
self._set_tls_cipher_suites(value)
elif setting == 'logging_level':
self._set_logging_level(value)
else:
self._set_database_path(value)
|
[
"Set",
"a",
"specific",
"setting",
"value",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/config.py#L58-L100
|
[
"def",
"set_setting",
"(",
"self",
",",
"setting",
",",
"value",
")",
":",
"if",
"setting",
"not",
"in",
"self",
".",
"_expected_settings",
"+",
"self",
".",
"_optional_settings",
":",
"raise",
"exceptions",
".",
"ConfigurationError",
"(",
"\"Setting '{0}' is not supported.\"",
".",
"format",
"(",
"setting",
")",
")",
"if",
"setting",
"==",
"'hostname'",
":",
"self",
".",
"_set_hostname",
"(",
"value",
")",
"elif",
"setting",
"==",
"'port'",
":",
"self",
".",
"_set_port",
"(",
"value",
")",
"elif",
"setting",
"==",
"'certificate_path'",
":",
"self",
".",
"_set_certificate_path",
"(",
"value",
")",
"elif",
"setting",
"==",
"'key_path'",
":",
"self",
".",
"_set_key_path",
"(",
"value",
")",
"elif",
"setting",
"==",
"'ca_path'",
":",
"self",
".",
"_set_ca_path",
"(",
"value",
")",
"elif",
"setting",
"==",
"'auth_suite'",
":",
"self",
".",
"_set_auth_suite",
"(",
"value",
")",
"elif",
"setting",
"==",
"'policy_path'",
":",
"self",
".",
"_set_policy_path",
"(",
"value",
")",
"elif",
"setting",
"==",
"'enable_tls_client_auth'",
":",
"self",
".",
"_set_enable_tls_client_auth",
"(",
"value",
")",
"elif",
"setting",
"==",
"'tls_cipher_suites'",
":",
"self",
".",
"_set_tls_cipher_suites",
"(",
"value",
")",
"elif",
"setting",
"==",
"'logging_level'",
":",
"self",
".",
"_set_logging_level",
"(",
"value",
")",
"else",
":",
"self",
".",
"_set_database_path",
"(",
"value",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
KmipServerConfig.load_settings
|
Load configuration settings from the file pointed to by path.
This will overwrite all current setting values.
Args:
path (string): The path to the configuration file containing
the settings to load. Required.
Raises:
ConfigurationError: Raised if the path does not point to an
existing file or if a setting value is invalid.
|
kmip/services/server/config.py
|
def load_settings(self, path):
"""
Load configuration settings from the file pointed to by path.
This will overwrite all current setting values.
Args:
path (string): The path to the configuration file containing
the settings to load. Required.
Raises:
ConfigurationError: Raised if the path does not point to an
existing file or if a setting value is invalid.
"""
if not os.path.exists(path):
raise exceptions.ConfigurationError(
"The server configuration file ('{0}') could not be "
"located.".format(path)
)
self._logger.info(
"Loading server configuration settings from: {0}".format(path)
)
parser = configparser.ConfigParser()
parser.read(path)
self._parse_settings(parser)
self.parse_auth_settings(parser)
|
def load_settings(self, path):
"""
Load configuration settings from the file pointed to by path.
This will overwrite all current setting values.
Args:
path (string): The path to the configuration file containing
the settings to load. Required.
Raises:
ConfigurationError: Raised if the path does not point to an
existing file or if a setting value is invalid.
"""
if not os.path.exists(path):
raise exceptions.ConfigurationError(
"The server configuration file ('{0}') could not be "
"located.".format(path)
)
self._logger.info(
"Loading server configuration settings from: {0}".format(path)
)
parser = configparser.ConfigParser()
parser.read(path)
self._parse_settings(parser)
self.parse_auth_settings(parser)
|
[
"Load",
"configuration",
"settings",
"from",
"the",
"file",
"pointed",
"to",
"by",
"path",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/config.py#L102-L128
|
[
"def",
"load_settings",
"(",
"self",
",",
"path",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"raise",
"exceptions",
".",
"ConfigurationError",
"(",
"\"The server configuration file ('{0}') could not be \"",
"\"located.\"",
".",
"format",
"(",
"path",
")",
")",
"self",
".",
"_logger",
".",
"info",
"(",
"\"Loading server configuration settings from: {0}\"",
".",
"format",
"(",
"path",
")",
")",
"parser",
"=",
"configparser",
".",
"ConfigParser",
"(",
")",
"parser",
".",
"read",
"(",
"path",
")",
"self",
".",
"_parse_settings",
"(",
"parser",
")",
"self",
".",
"parse_auth_settings",
"(",
"parser",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
UsageMaskType.process_bind_param
|
Returns the integer value of the usage mask bitmask. This value is
stored in the database.
Args:
value(list<enums.CryptographicUsageMask>): list of enums in the
usage mask
dialect(string): SQL dialect
|
kmip/pie/sqltypes.py
|
def process_bind_param(self, value, dialect):
"""
Returns the integer value of the usage mask bitmask. This value is
stored in the database.
Args:
value(list<enums.CryptographicUsageMask>): list of enums in the
usage mask
dialect(string): SQL dialect
"""
bitmask = 0x00
for e in value:
bitmask = bitmask | e.value
return bitmask
|
def process_bind_param(self, value, dialect):
"""
Returns the integer value of the usage mask bitmask. This value is
stored in the database.
Args:
value(list<enums.CryptographicUsageMask>): list of enums in the
usage mask
dialect(string): SQL dialect
"""
bitmask = 0x00
for e in value:
bitmask = bitmask | e.value
return bitmask
|
[
"Returns",
"the",
"integer",
"value",
"of",
"the",
"usage",
"mask",
"bitmask",
".",
"This",
"value",
"is",
"stored",
"in",
"the",
"database",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/pie/sqltypes.py#L46-L59
|
[
"def",
"process_bind_param",
"(",
"self",
",",
"value",
",",
"dialect",
")",
":",
"bitmask",
"=",
"0x00",
"for",
"e",
"in",
"value",
":",
"bitmask",
"=",
"bitmask",
"|",
"e",
".",
"value",
"return",
"bitmask"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
UsageMaskType.process_result_value
|
Returns a new list of enums.CryptographicUsageMask Enums. This converts
the integer value into the list of enums.
Args:
value(int): The integer value stored in the database that is used
to create the list of enums.CryptographicUsageMask Enums.
dialect(string): SQL dialect
|
kmip/pie/sqltypes.py
|
def process_result_value(self, value, dialect):
"""
Returns a new list of enums.CryptographicUsageMask Enums. This converts
the integer value into the list of enums.
Args:
value(int): The integer value stored in the database that is used
to create the list of enums.CryptographicUsageMask Enums.
dialect(string): SQL dialect
"""
masks = list()
if value:
for e in enums.CryptographicUsageMask:
if e.value & value:
masks.append(e)
return masks
|
def process_result_value(self, value, dialect):
"""
Returns a new list of enums.CryptographicUsageMask Enums. This converts
the integer value into the list of enums.
Args:
value(int): The integer value stored in the database that is used
to create the list of enums.CryptographicUsageMask Enums.
dialect(string): SQL dialect
"""
masks = list()
if value:
for e in enums.CryptographicUsageMask:
if e.value & value:
masks.append(e)
return masks
|
[
"Returns",
"a",
"new",
"list",
"of",
"enums",
".",
"CryptographicUsageMask",
"Enums",
".",
"This",
"converts",
"the",
"integer",
"value",
"into",
"the",
"list",
"of",
"enums",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/pie/sqltypes.py#L61-L76
|
[
"def",
"process_result_value",
"(",
"self",
",",
"value",
",",
"dialect",
")",
":",
"masks",
"=",
"list",
"(",
")",
"if",
"value",
":",
"for",
"e",
"in",
"enums",
".",
"CryptographicUsageMask",
":",
"if",
"e",
".",
"value",
"&",
"value",
":",
"masks",
".",
"append",
"(",
"e",
")",
"return",
"masks"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
LongInteger.read
|
Read the encoding of the LongInteger from the input stream.
Args:
istream (stream): A buffer containing the encoded bytes of a
LongInteger. Usually a BytearrayStream object. Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidPrimitiveLength: if the long integer encoding read in has
an invalid encoded length.
|
kmip/core/primitives.py
|
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the encoding of the LongInteger from the input stream.
Args:
istream (stream): A buffer containing the encoded bytes of a
LongInteger. Usually a BytearrayStream object. Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidPrimitiveLength: if the long integer encoding read in has
an invalid encoded length.
"""
super(LongInteger, self).read(istream, kmip_version=kmip_version)
if self.length is not LongInteger.LENGTH:
raise exceptions.InvalidPrimitiveLength(
"invalid long integer length read; "
"expected: {0}, observed: {1}".format(
LongInteger.LENGTH, self.length))
self.value = unpack('!q', istream.read(self.length))[0]
self.validate()
|
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the encoding of the LongInteger from the input stream.
Args:
istream (stream): A buffer containing the encoded bytes of a
LongInteger. Usually a BytearrayStream object. Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidPrimitiveLength: if the long integer encoding read in has
an invalid encoded length.
"""
super(LongInteger, self).read(istream, kmip_version=kmip_version)
if self.length is not LongInteger.LENGTH:
raise exceptions.InvalidPrimitiveLength(
"invalid long integer length read; "
"expected: {0}, observed: {1}".format(
LongInteger.LENGTH, self.length))
self.value = unpack('!q', istream.read(self.length))[0]
self.validate()
|
[
"Read",
"the",
"encoding",
"of",
"the",
"LongInteger",
"from",
"the",
"input",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/primitives.py#L331-L355
|
[
"def",
"read",
"(",
"self",
",",
"istream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"LongInteger",
",",
"self",
")",
".",
"read",
"(",
"istream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"length",
"is",
"not",
"LongInteger",
".",
"LENGTH",
":",
"raise",
"exceptions",
".",
"InvalidPrimitiveLength",
"(",
"\"invalid long integer length read; \"",
"\"expected: {0}, observed: {1}\"",
".",
"format",
"(",
"LongInteger",
".",
"LENGTH",
",",
"self",
".",
"length",
")",
")",
"self",
".",
"value",
"=",
"unpack",
"(",
"'!q'",
",",
"istream",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"[",
"0",
"]",
"self",
".",
"validate",
"(",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
LongInteger.write
|
Write the encoding of the LongInteger to the output stream.
Args:
ostream (stream): A buffer to contain the encoded bytes of a
LongInteger. Usually a BytearrayStream object. Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/primitives.py
|
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the encoding of the LongInteger to the output stream.
Args:
ostream (stream): A buffer to contain the encoded bytes of a
LongInteger. Usually a BytearrayStream object. Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
super(LongInteger, self).write(ostream, kmip_version=kmip_version)
ostream.write(pack('!q', self.value))
|
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the encoding of the LongInteger to the output stream.
Args:
ostream (stream): A buffer to contain the encoded bytes of a
LongInteger. Usually a BytearrayStream object. Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
super(LongInteger, self).write(ostream, kmip_version=kmip_version)
ostream.write(pack('!q', self.value))
|
[
"Write",
"the",
"encoding",
"of",
"the",
"LongInteger",
"to",
"the",
"output",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/primitives.py#L357-L369
|
[
"def",
"write",
"(",
"self",
",",
"ostream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"LongInteger",
",",
"self",
")",
".",
"write",
"(",
"ostream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"ostream",
".",
"write",
"(",
"pack",
"(",
"'!q'",
",",
"self",
".",
"value",
")",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
LongInteger.validate
|
Verify that the value of the LongInteger is valid.
Raises:
TypeError: if the value is not of type int or long
ValueError: if the value cannot be represented by a signed 64-bit
integer
|
kmip/core/primitives.py
|
def validate(self):
"""
Verify that the value of the LongInteger is valid.
Raises:
TypeError: if the value is not of type int or long
ValueError: if the value cannot be represented by a signed 64-bit
integer
"""
if self.value is not None:
if not isinstance(self.value, six.integer_types):
raise TypeError('expected (one of): {0}, observed: {1}'.format(
six.integer_types, type(self.value)))
else:
if self.value > LongInteger.MAX:
raise ValueError(
'long integer value greater than accepted max')
elif self.value < LongInteger.MIN:
raise ValueError(
'long integer value less than accepted min')
|
def validate(self):
"""
Verify that the value of the LongInteger is valid.
Raises:
TypeError: if the value is not of type int or long
ValueError: if the value cannot be represented by a signed 64-bit
integer
"""
if self.value is not None:
if not isinstance(self.value, six.integer_types):
raise TypeError('expected (one of): {0}, observed: {1}'.format(
six.integer_types, type(self.value)))
else:
if self.value > LongInteger.MAX:
raise ValueError(
'long integer value greater than accepted max')
elif self.value < LongInteger.MIN:
raise ValueError(
'long integer value less than accepted min')
|
[
"Verify",
"that",
"the",
"value",
"of",
"the",
"LongInteger",
"is",
"valid",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/primitives.py#L371-L390
|
[
"def",
"validate",
"(",
"self",
")",
":",
"if",
"self",
".",
"value",
"is",
"not",
"None",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"value",
",",
"six",
".",
"integer_types",
")",
":",
"raise",
"TypeError",
"(",
"'expected (one of): {0}, observed: {1}'",
".",
"format",
"(",
"six",
".",
"integer_types",
",",
"type",
"(",
"self",
".",
"value",
")",
")",
")",
"else",
":",
"if",
"self",
".",
"value",
">",
"LongInteger",
".",
"MAX",
":",
"raise",
"ValueError",
"(",
"'long integer value greater than accepted max'",
")",
"elif",
"self",
".",
"value",
"<",
"LongInteger",
".",
"MIN",
":",
"raise",
"ValueError",
"(",
"'long integer value less than accepted min'",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
BigInteger.read
|
Read the encoding of the BigInteger from the input stream.
Args:
istream (stream): A buffer containing the encoded bytes of the
value of a BigInteger. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidPrimitiveLength: if the big integer encoding read in has
an invalid encoded length.
|
kmip/core/primitives.py
|
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the encoding of the BigInteger from the input stream.
Args:
istream (stream): A buffer containing the encoded bytes of the
value of a BigInteger. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidPrimitiveLength: if the big integer encoding read in has
an invalid encoded length.
"""
super(BigInteger, self).read(istream, kmip_version=kmip_version)
# Check for a valid length before even trying to parse the value.
if self.length % 8:
raise exceptions.InvalidPrimitiveLength(
"invalid big integer length read; "
"expected: multiple of 8, observed: {0}".format(self.length))
sign = 1
binary = ''
# Read the value byte by byte and convert it into binary, padding each
# byte as needed.
for _ in range(self.length):
byte = struct.unpack('!B', istream.read(1))[0]
bits = "{0:b}".format(byte)
pad = len(bits) % 8
if pad:
bits = ('0' * (8 - pad)) + bits
binary += bits
# If the value is negative, convert via two's complement.
if binary[0] == '1':
sign = -1
binary = binary.replace('1', 'i')
binary = binary.replace('0', '1')
binary = binary.replace('i', '0')
pivot = binary.rfind('0')
binary = binary[0:pivot] + '1' + ('0' * len(binary[pivot + 1:]))
# Convert the value back to an integer and reapply the sign.
self.value = int(binary, 2) * sign
|
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the encoding of the BigInteger from the input stream.
Args:
istream (stream): A buffer containing the encoded bytes of the
value of a BigInteger. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidPrimitiveLength: if the big integer encoding read in has
an invalid encoded length.
"""
super(BigInteger, self).read(istream, kmip_version=kmip_version)
# Check for a valid length before even trying to parse the value.
if self.length % 8:
raise exceptions.InvalidPrimitiveLength(
"invalid big integer length read; "
"expected: multiple of 8, observed: {0}".format(self.length))
sign = 1
binary = ''
# Read the value byte by byte and convert it into binary, padding each
# byte as needed.
for _ in range(self.length):
byte = struct.unpack('!B', istream.read(1))[0]
bits = "{0:b}".format(byte)
pad = len(bits) % 8
if pad:
bits = ('0' * (8 - pad)) + bits
binary += bits
# If the value is negative, convert via two's complement.
if binary[0] == '1':
sign = -1
binary = binary.replace('1', 'i')
binary = binary.replace('0', '1')
binary = binary.replace('i', '0')
pivot = binary.rfind('0')
binary = binary[0:pivot] + '1' + ('0' * len(binary[pivot + 1:]))
# Convert the value back to an integer and reapply the sign.
self.value = int(binary, 2) * sign
|
[
"Read",
"the",
"encoding",
"of",
"the",
"BigInteger",
"from",
"the",
"input",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/primitives.py#L429-L477
|
[
"def",
"read",
"(",
"self",
",",
"istream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"BigInteger",
",",
"self",
")",
".",
"read",
"(",
"istream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"# Check for a valid length before even trying to parse the value.",
"if",
"self",
".",
"length",
"%",
"8",
":",
"raise",
"exceptions",
".",
"InvalidPrimitiveLength",
"(",
"\"invalid big integer length read; \"",
"\"expected: multiple of 8, observed: {0}\"",
".",
"format",
"(",
"self",
".",
"length",
")",
")",
"sign",
"=",
"1",
"binary",
"=",
"''",
"# Read the value byte by byte and convert it into binary, padding each",
"# byte as needed.",
"for",
"_",
"in",
"range",
"(",
"self",
".",
"length",
")",
":",
"byte",
"=",
"struct",
".",
"unpack",
"(",
"'!B'",
",",
"istream",
".",
"read",
"(",
"1",
")",
")",
"[",
"0",
"]",
"bits",
"=",
"\"{0:b}\"",
".",
"format",
"(",
"byte",
")",
"pad",
"=",
"len",
"(",
"bits",
")",
"%",
"8",
"if",
"pad",
":",
"bits",
"=",
"(",
"'0'",
"*",
"(",
"8",
"-",
"pad",
")",
")",
"+",
"bits",
"binary",
"+=",
"bits",
"# If the value is negative, convert via two's complement.",
"if",
"binary",
"[",
"0",
"]",
"==",
"'1'",
":",
"sign",
"=",
"-",
"1",
"binary",
"=",
"binary",
".",
"replace",
"(",
"'1'",
",",
"'i'",
")",
"binary",
"=",
"binary",
".",
"replace",
"(",
"'0'",
",",
"'1'",
")",
"binary",
"=",
"binary",
".",
"replace",
"(",
"'i'",
",",
"'0'",
")",
"pivot",
"=",
"binary",
".",
"rfind",
"(",
"'0'",
")",
"binary",
"=",
"binary",
"[",
"0",
":",
"pivot",
"]",
"+",
"'1'",
"+",
"(",
"'0'",
"*",
"len",
"(",
"binary",
"[",
"pivot",
"+",
"1",
":",
"]",
")",
")",
"# Convert the value back to an integer and reapply the sign.",
"self",
".",
"value",
"=",
"int",
"(",
"binary",
",",
"2",
")",
"*",
"sign"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
BigInteger.write
|
Write the encoding of the BigInteger to the output stream.
Args:
ostream (Stream): A buffer to contain the encoded bytes of a
BigInteger object. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/primitives.py
|
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the encoding of the BigInteger to the output stream.
Args:
ostream (Stream): A buffer to contain the encoded bytes of a
BigInteger object. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
# Convert the value to binary and pad it as needed.
binary = "{0:b}".format(abs(self.value))
binary = ("0" * (64 - (len(binary) % 64))) + binary
# If the value is negative, convert via two's complement.
if self.value < 0:
binary = binary.replace('1', 'i')
binary = binary.replace('0', '1')
binary = binary.replace('i', '0')
pivot = binary.rfind('0')
binary = binary[0:pivot] + '1' + ('0' * len(binary[pivot + 1:]))
# Convert each byte to hex and build the hex string for the value.
hexadecimal = b''
for i in range(0, len(binary), 8):
byte = binary[i:i + 8]
byte = int(byte, 2)
hexadecimal += struct.pack('!B', byte)
self.length = len(hexadecimal)
super(BigInteger, self).write(ostream, kmip_version=kmip_version)
ostream.write(hexadecimal)
|
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the encoding of the BigInteger to the output stream.
Args:
ostream (Stream): A buffer to contain the encoded bytes of a
BigInteger object. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
# Convert the value to binary and pad it as needed.
binary = "{0:b}".format(abs(self.value))
binary = ("0" * (64 - (len(binary) % 64))) + binary
# If the value is negative, convert via two's complement.
if self.value < 0:
binary = binary.replace('1', 'i')
binary = binary.replace('0', '1')
binary = binary.replace('i', '0')
pivot = binary.rfind('0')
binary = binary[0:pivot] + '1' + ('0' * len(binary[pivot + 1:]))
# Convert each byte to hex and build the hex string for the value.
hexadecimal = b''
for i in range(0, len(binary), 8):
byte = binary[i:i + 8]
byte = int(byte, 2)
hexadecimal += struct.pack('!B', byte)
self.length = len(hexadecimal)
super(BigInteger, self).write(ostream, kmip_version=kmip_version)
ostream.write(hexadecimal)
|
[
"Write",
"the",
"encoding",
"of",
"the",
"BigInteger",
"to",
"the",
"output",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/primitives.py#L479-L513
|
[
"def",
"write",
"(",
"self",
",",
"ostream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"# Convert the value to binary and pad it as needed.",
"binary",
"=",
"\"{0:b}\"",
".",
"format",
"(",
"abs",
"(",
"self",
".",
"value",
")",
")",
"binary",
"=",
"(",
"\"0\"",
"*",
"(",
"64",
"-",
"(",
"len",
"(",
"binary",
")",
"%",
"64",
")",
")",
")",
"+",
"binary",
"# If the value is negative, convert via two's complement.",
"if",
"self",
".",
"value",
"<",
"0",
":",
"binary",
"=",
"binary",
".",
"replace",
"(",
"'1'",
",",
"'i'",
")",
"binary",
"=",
"binary",
".",
"replace",
"(",
"'0'",
",",
"'1'",
")",
"binary",
"=",
"binary",
".",
"replace",
"(",
"'i'",
",",
"'0'",
")",
"pivot",
"=",
"binary",
".",
"rfind",
"(",
"'0'",
")",
"binary",
"=",
"binary",
"[",
"0",
":",
"pivot",
"]",
"+",
"'1'",
"+",
"(",
"'0'",
"*",
"len",
"(",
"binary",
"[",
"pivot",
"+",
"1",
":",
"]",
")",
")",
"# Convert each byte to hex and build the hex string for the value.",
"hexadecimal",
"=",
"b''",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"binary",
")",
",",
"8",
")",
":",
"byte",
"=",
"binary",
"[",
"i",
":",
"i",
"+",
"8",
"]",
"byte",
"=",
"int",
"(",
"byte",
",",
"2",
")",
"hexadecimal",
"+=",
"struct",
".",
"pack",
"(",
"'!B'",
",",
"byte",
")",
"self",
".",
"length",
"=",
"len",
"(",
"hexadecimal",
")",
"super",
"(",
"BigInteger",
",",
"self",
")",
".",
"write",
"(",
"ostream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"ostream",
".",
"write",
"(",
"hexadecimal",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
BigInteger.validate
|
Verify that the value of the BigInteger is valid.
Raises:
TypeError: if the value is not of type int or long
|
kmip/core/primitives.py
|
def validate(self):
"""
Verify that the value of the BigInteger is valid.
Raises:
TypeError: if the value is not of type int or long
"""
if self.value is not None:
if not isinstance(self.value, six.integer_types):
raise TypeError('expected (one of): {0}, observed: {1}'.format(
six.integer_types, type(self.value)))
|
def validate(self):
"""
Verify that the value of the BigInteger is valid.
Raises:
TypeError: if the value is not of type int or long
"""
if self.value is not None:
if not isinstance(self.value, six.integer_types):
raise TypeError('expected (one of): {0}, observed: {1}'.format(
six.integer_types, type(self.value)))
|
[
"Verify",
"that",
"the",
"value",
"of",
"the",
"BigInteger",
"is",
"valid",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/primitives.py#L515-L525
|
[
"def",
"validate",
"(",
"self",
")",
":",
"if",
"self",
".",
"value",
"is",
"not",
"None",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"value",
",",
"six",
".",
"integer_types",
")",
":",
"raise",
"TypeError",
"(",
"'expected (one of): {0}, observed: {1}'",
".",
"format",
"(",
"six",
".",
"integer_types",
",",
"type",
"(",
"self",
".",
"value",
")",
")",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
Enumeration.validate
|
Verify that the value of the Enumeration is valid.
Raises:
TypeError: if the enum is not of type Enum
ValueError: if the value is not of the expected Enum subtype or if
the value cannot be represented by an unsigned 32-bit integer
|
kmip/core/primitives.py
|
def validate(self):
"""
Verify that the value of the Enumeration is valid.
Raises:
TypeError: if the enum is not of type Enum
ValueError: if the value is not of the expected Enum subtype or if
the value cannot be represented by an unsigned 32-bit integer
"""
if not isinstance(self.enum, enumeration.EnumMeta):
raise TypeError(
'enumeration type {0} must be of type EnumMeta'.format(
self.enum))
if self.value is not None:
if not isinstance(self.value, self.enum):
raise TypeError(
'enumeration {0} must be of type {1}'.format(
self.value, self.enum))
if type(self.value.value) not in six.integer_types:
raise TypeError('enumeration value must be an int')
else:
if self.value.value > Enumeration.MAX:
raise ValueError(
'enumeration value greater than accepted max')
elif self.value.value < Enumeration.MIN:
raise ValueError(
'enumeration value less than accepted min')
|
def validate(self):
"""
Verify that the value of the Enumeration is valid.
Raises:
TypeError: if the enum is not of type Enum
ValueError: if the value is not of the expected Enum subtype or if
the value cannot be represented by an unsigned 32-bit integer
"""
if not isinstance(self.enum, enumeration.EnumMeta):
raise TypeError(
'enumeration type {0} must be of type EnumMeta'.format(
self.enum))
if self.value is not None:
if not isinstance(self.value, self.enum):
raise TypeError(
'enumeration {0} must be of type {1}'.format(
self.value, self.enum))
if type(self.value.value) not in six.integer_types:
raise TypeError('enumeration value must be an int')
else:
if self.value.value > Enumeration.MAX:
raise ValueError(
'enumeration value greater than accepted max')
elif self.value.value < Enumeration.MIN:
raise ValueError(
'enumeration value less than accepted min')
|
[
"Verify",
"that",
"the",
"value",
"of",
"the",
"Enumeration",
"is",
"valid",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/primitives.py#L633-L659
|
[
"def",
"validate",
"(",
"self",
")",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"enum",
",",
"enumeration",
".",
"EnumMeta",
")",
":",
"raise",
"TypeError",
"(",
"'enumeration type {0} must be of type EnumMeta'",
".",
"format",
"(",
"self",
".",
"enum",
")",
")",
"if",
"self",
".",
"value",
"is",
"not",
"None",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"value",
",",
"self",
".",
"enum",
")",
":",
"raise",
"TypeError",
"(",
"'enumeration {0} must be of type {1}'",
".",
"format",
"(",
"self",
".",
"value",
",",
"self",
".",
"enum",
")",
")",
"if",
"type",
"(",
"self",
".",
"value",
".",
"value",
")",
"not",
"in",
"six",
".",
"integer_types",
":",
"raise",
"TypeError",
"(",
"'enumeration value must be an int'",
")",
"else",
":",
"if",
"self",
".",
"value",
".",
"value",
">",
"Enumeration",
".",
"MAX",
":",
"raise",
"ValueError",
"(",
"'enumeration value greater than accepted max'",
")",
"elif",
"self",
".",
"value",
".",
"value",
"<",
"Enumeration",
".",
"MIN",
":",
"raise",
"ValueError",
"(",
"'enumeration value less than accepted min'",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
Boolean.read_value
|
Read the value of the Boolean object from the input stream.
Args:
istream (Stream): A buffer containing the encoded bytes of the
value of a Boolean object. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: if the read boolean value is not a 0 or 1.
|
kmip/core/primitives.py
|
def read_value(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the value of the Boolean object from the input stream.
Args:
istream (Stream): A buffer containing the encoded bytes of the
value of a Boolean object. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: if the read boolean value is not a 0 or 1.
"""
try:
value = unpack('!Q', istream.read(self.LENGTH))[0]
except Exception:
self.logger.error("Error reading boolean value from buffer")
raise
if value == 1:
self.value = True
elif value == 0:
self.value = False
else:
raise ValueError("expected: 0 or 1, observed: {0}".format(value))
self.validate()
|
def read_value(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the value of the Boolean object from the input stream.
Args:
istream (Stream): A buffer containing the encoded bytes of the
value of a Boolean object. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
ValueError: if the read boolean value is not a 0 or 1.
"""
try:
value = unpack('!Q', istream.read(self.LENGTH))[0]
except Exception:
self.logger.error("Error reading boolean value from buffer")
raise
if value == 1:
self.value = True
elif value == 0:
self.value = False
else:
raise ValueError("expected: 0 or 1, observed: {0}".format(value))
self.validate()
|
[
"Read",
"the",
"value",
"of",
"the",
"Boolean",
"object",
"from",
"the",
"input",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/primitives.py#L710-L738
|
[
"def",
"read_value",
"(",
"self",
",",
"istream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"try",
":",
"value",
"=",
"unpack",
"(",
"'!Q'",
",",
"istream",
".",
"read",
"(",
"self",
".",
"LENGTH",
")",
")",
"[",
"0",
"]",
"except",
"Exception",
":",
"self",
".",
"logger",
".",
"error",
"(",
"\"Error reading boolean value from buffer\"",
")",
"raise",
"if",
"value",
"==",
"1",
":",
"self",
".",
"value",
"=",
"True",
"elif",
"value",
"==",
"0",
":",
"self",
".",
"value",
"=",
"False",
"else",
":",
"raise",
"ValueError",
"(",
"\"expected: 0 or 1, observed: {0}\"",
".",
"format",
"(",
"value",
")",
")",
"self",
".",
"validate",
"(",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
Boolean.write_value
|
Write the value of the Boolean object to the output stream.
Args:
ostream (Stream): A buffer to contain the encoded bytes of the
value of a Boolean object. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/primitives.py
|
def write_value(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the value of the Boolean object to the output stream.
Args:
ostream (Stream): A buffer to contain the encoded bytes of the
value of a Boolean object. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
try:
ostream.write(pack('!Q', self.value))
except Exception:
self.logger.error("Error writing boolean value to buffer")
raise
|
def write_value(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the value of the Boolean object to the output stream.
Args:
ostream (Stream): A buffer to contain the encoded bytes of the
value of a Boolean object. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
try:
ostream.write(pack('!Q', self.value))
except Exception:
self.logger.error("Error writing boolean value to buffer")
raise
|
[
"Write",
"the",
"value",
"of",
"the",
"Boolean",
"object",
"to",
"the",
"output",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/primitives.py#L754-L770
|
[
"def",
"write_value",
"(",
"self",
",",
"ostream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"try",
":",
"ostream",
".",
"write",
"(",
"pack",
"(",
"'!Q'",
",",
"self",
".",
"value",
")",
")",
"except",
"Exception",
":",
"self",
".",
"logger",
".",
"error",
"(",
"\"Error writing boolean value to buffer\"",
")",
"raise"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
Boolean.write
|
Write the encoding of the Boolean object to the output stream.
Args:
ostream (Stream): A buffer to contain the encoded bytes of a
Boolean object. Usually a BytearrayStream object. Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/primitives.py
|
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the encoding of the Boolean object to the output stream.
Args:
ostream (Stream): A buffer to contain the encoded bytes of a
Boolean object. Usually a BytearrayStream object. Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
super(Boolean, self).write(ostream, kmip_version=kmip_version)
self.write_value(ostream, kmip_version=kmip_version)
|
def write(self, ostream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the encoding of the Boolean object to the output stream.
Args:
ostream (Stream): A buffer to contain the encoded bytes of a
Boolean object. Usually a BytearrayStream object. Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
super(Boolean, self).write(ostream, kmip_version=kmip_version)
self.write_value(ostream, kmip_version=kmip_version)
|
[
"Write",
"the",
"encoding",
"of",
"the",
"Boolean",
"object",
"to",
"the",
"output",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/primitives.py#L772-L784
|
[
"def",
"write",
"(",
"self",
",",
"ostream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"Boolean",
",",
"self",
")",
".",
"write",
"(",
"ostream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"write_value",
"(",
"ostream",
",",
"kmip_version",
"=",
"kmip_version",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
Boolean.validate
|
Verify that the value of the Boolean object is valid.
Raises:
TypeError: if the value is not of type bool.
|
kmip/core/primitives.py
|
def validate(self):
"""
Verify that the value of the Boolean object is valid.
Raises:
TypeError: if the value is not of type bool.
"""
if self.value:
if not isinstance(self.value, bool):
raise TypeError("expected: {0}, observed: {1}".format(
bool, type(self.value)))
|
def validate(self):
"""
Verify that the value of the Boolean object is valid.
Raises:
TypeError: if the value is not of type bool.
"""
if self.value:
if not isinstance(self.value, bool):
raise TypeError("expected: {0}, observed: {1}".format(
bool, type(self.value)))
|
[
"Verify",
"that",
"the",
"value",
"of",
"the",
"Boolean",
"object",
"is",
"valid",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/primitives.py#L786-L796
|
[
"def",
"validate",
"(",
"self",
")",
":",
"if",
"self",
".",
"value",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"value",
",",
"bool",
")",
":",
"raise",
"TypeError",
"(",
"\"expected: {0}, observed: {1}\"",
".",
"format",
"(",
"bool",
",",
"type",
"(",
"self",
".",
"value",
")",
")",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
Interval.read
|
Read the encoding of the Interval from the input stream.
Args:
istream (stream): A buffer containing the encoded bytes of the
value of an Interval. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidPrimitiveLength: if the Interval encoding read in has an
invalid encoded length.
InvalidPaddingBytes: if the Interval encoding read in does not use
zeroes for its padding bytes.
|
kmip/core/primitives.py
|
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the encoding of the Interval from the input stream.
Args:
istream (stream): A buffer containing the encoded bytes of the
value of an Interval. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidPrimitiveLength: if the Interval encoding read in has an
invalid encoded length.
InvalidPaddingBytes: if the Interval encoding read in does not use
zeroes for its padding bytes.
"""
super(Interval, self).read(istream, kmip_version=kmip_version)
# Check for a valid length before even trying to parse the value.
if self.length != Interval.LENGTH:
raise exceptions.InvalidPrimitiveLength(
"interval length must be {0}".format(Interval.LENGTH))
# Decode the Interval value and the padding bytes.
self.value = unpack('!I', istream.read(Interval.LENGTH))[0]
pad = unpack('!I', istream.read(Interval.LENGTH))[0]
# Verify that the padding bytes are zero bytes.
if pad != 0:
raise exceptions.InvalidPaddingBytes("padding bytes must be zero")
self.validate()
|
def read(self, istream, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the encoding of the Interval from the input stream.
Args:
istream (stream): A buffer containing the encoded bytes of the
value of an Interval. Usually a BytearrayStream object.
Required.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidPrimitiveLength: if the Interval encoding read in has an
invalid encoded length.
InvalidPaddingBytes: if the Interval encoding read in does not use
zeroes for its padding bytes.
"""
super(Interval, self).read(istream, kmip_version=kmip_version)
# Check for a valid length before even trying to parse the value.
if self.length != Interval.LENGTH:
raise exceptions.InvalidPrimitiveLength(
"interval length must be {0}".format(Interval.LENGTH))
# Decode the Interval value and the padding bytes.
self.value = unpack('!I', istream.read(Interval.LENGTH))[0]
pad = unpack('!I', istream.read(Interval.LENGTH))[0]
# Verify that the padding bytes are zero bytes.
if pad != 0:
raise exceptions.InvalidPaddingBytes("padding bytes must be zero")
self.validate()
|
[
"Read",
"the",
"encoding",
"of",
"the",
"Interval",
"from",
"the",
"input",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/primitives.py#L1064-L1097
|
[
"def",
"read",
"(",
"self",
",",
"istream",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"Interval",
",",
"self",
")",
".",
"read",
"(",
"istream",
",",
"kmip_version",
"=",
"kmip_version",
")",
"# Check for a valid length before even trying to parse the value.",
"if",
"self",
".",
"length",
"!=",
"Interval",
".",
"LENGTH",
":",
"raise",
"exceptions",
".",
"InvalidPrimitiveLength",
"(",
"\"interval length must be {0}\"",
".",
"format",
"(",
"Interval",
".",
"LENGTH",
")",
")",
"# Decode the Interval value and the padding bytes.",
"self",
".",
"value",
"=",
"unpack",
"(",
"'!I'",
",",
"istream",
".",
"read",
"(",
"Interval",
".",
"LENGTH",
")",
")",
"[",
"0",
"]",
"pad",
"=",
"unpack",
"(",
"'!I'",
",",
"istream",
".",
"read",
"(",
"Interval",
".",
"LENGTH",
")",
")",
"[",
"0",
"]",
"# Verify that the padding bytes are zero bytes.",
"if",
"pad",
"!=",
"0",
":",
"raise",
"exceptions",
".",
"InvalidPaddingBytes",
"(",
"\"padding bytes must be zero\"",
")",
"self",
".",
"validate",
"(",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
Interval.validate
|
Verify that the value of the Interval is valid.
Raises:
TypeError: if the value is not of type int or long
ValueError: if the value cannot be represented by an unsigned
32-bit integer
|
kmip/core/primitives.py
|
def validate(self):
"""
Verify that the value of the Interval is valid.
Raises:
TypeError: if the value is not of type int or long
ValueError: if the value cannot be represented by an unsigned
32-bit integer
"""
if self.value is not None:
if type(self.value) not in six.integer_types:
raise TypeError('expected (one of): {0}, observed: {1}'.format(
six.integer_types, type(self.value)))
else:
if self.value > Interval.MAX:
raise ValueError(
'interval value greater than accepted max')
elif self.value < Interval.MIN:
raise ValueError('interval value less than accepted min')
|
def validate(self):
"""
Verify that the value of the Interval is valid.
Raises:
TypeError: if the value is not of type int or long
ValueError: if the value cannot be represented by an unsigned
32-bit integer
"""
if self.value is not None:
if type(self.value) not in six.integer_types:
raise TypeError('expected (one of): {0}, observed: {1}'.format(
six.integer_types, type(self.value)))
else:
if self.value > Interval.MAX:
raise ValueError(
'interval value greater than accepted max')
elif self.value < Interval.MIN:
raise ValueError('interval value less than accepted min')
|
[
"Verify",
"that",
"the",
"value",
"of",
"the",
"Interval",
"is",
"valid",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/primitives.py#L1114-L1132
|
[
"def",
"validate",
"(",
"self",
")",
":",
"if",
"self",
".",
"value",
"is",
"not",
"None",
":",
"if",
"type",
"(",
"self",
".",
"value",
")",
"not",
"in",
"six",
".",
"integer_types",
":",
"raise",
"TypeError",
"(",
"'expected (one of): {0}, observed: {1}'",
".",
"format",
"(",
"six",
".",
"integer_types",
",",
"type",
"(",
"self",
".",
"value",
")",
")",
")",
"else",
":",
"if",
"self",
".",
"value",
">",
"Interval",
".",
"MAX",
":",
"raise",
"ValueError",
"(",
"'interval value greater than accepted max'",
")",
"elif",
"self",
".",
"value",
"<",
"Interval",
".",
"MIN",
":",
"raise",
"ValueError",
"(",
"'interval value less than accepted min'",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
Key.key_wrapping_data
|
Retrieve all of the relevant key wrapping data fields and return them
as a dictionary.
|
kmip/pie/objects.py
|
def key_wrapping_data(self):
"""
Retrieve all of the relevant key wrapping data fields and return them
as a dictionary.
"""
key_wrapping_data = {}
encryption_key_info = {
'unique_identifier': self._kdw_eki_unique_identifier,
'cryptographic_parameters': {
'block_cipher_mode': self._kdw_eki_cp_block_cipher_mode,
'padding_method': self._kdw_eki_cp_padding_method,
'hashing_algorithm': self._kdw_eki_cp_hashing_algorithm,
'key_role_type': self._kdw_eki_cp_key_role_type,
'digital_signature_algorithm':
self._kdw_eki_cp_digital_signature_algorithm,
'cryptographic_algorithm':
self._kdw_eki_cp_cryptographic_algorithm,
'random_iv': self._kdw_eki_cp_random_iv,
'iv_length': self._kdw_eki_cp_iv_length,
'tag_length': self._kdw_eki_cp_tag_length,
'fixed_field_length': self._kdw_eki_cp_fixed_field_length,
'invocation_field_length':
self._kdw_eki_cp_invocation_field_length,
'counter_length': self._kdw_eki_cp_counter_length,
'initial_counter_value':
self._kdw_eki_cp_initial_counter_value
}
}
if not any(encryption_key_info['cryptographic_parameters'].values()):
encryption_key_info['cryptographic_parameters'] = {}
if not any(encryption_key_info.values()):
encryption_key_info = {}
mac_sign_key_info = {
'unique_identifier': self._kdw_mski_unique_identifier,
'cryptographic_parameters': {
'block_cipher_mode': self._kdw_mski_cp_block_cipher_mode,
'padding_method': self._kdw_mski_cp_padding_method,
'hashing_algorithm': self._kdw_mski_cp_hashing_algorithm,
'key_role_type': self._kdw_mski_cp_key_role_type,
'digital_signature_algorithm':
self._kdw_mski_cp_digital_signature_algorithm,
'cryptographic_algorithm':
self._kdw_mski_cp_cryptographic_algorithm,
'random_iv': self._kdw_mski_cp_random_iv,
'iv_length': self._kdw_mski_cp_iv_length,
'tag_length': self._kdw_mski_cp_tag_length,
'fixed_field_length': self._kdw_mski_cp_fixed_field_length,
'invocation_field_length':
self._kdw_mski_cp_invocation_field_length,
'counter_length': self._kdw_mski_cp_counter_length,
'initial_counter_value':
self._kdw_mski_cp_initial_counter_value
}
}
if not any(mac_sign_key_info['cryptographic_parameters'].values()):
mac_sign_key_info['cryptographic_parameters'] = {}
if not any(mac_sign_key_info.values()):
mac_sign_key_info = {}
key_wrapping_data['wrapping_method'] = self._kdw_wrapping_method
key_wrapping_data['encryption_key_information'] = encryption_key_info
key_wrapping_data['mac_signature_key_information'] = mac_sign_key_info
key_wrapping_data['mac_signature'] = self._kdw_mac_signature
key_wrapping_data['iv_counter_nonce'] = self._kdw_iv_counter_nonce
key_wrapping_data['encoding_option'] = self._kdw_encoding_option
if not any(key_wrapping_data.values()):
key_wrapping_data = {}
return key_wrapping_data
|
def key_wrapping_data(self):
"""
Retrieve all of the relevant key wrapping data fields and return them
as a dictionary.
"""
key_wrapping_data = {}
encryption_key_info = {
'unique_identifier': self._kdw_eki_unique_identifier,
'cryptographic_parameters': {
'block_cipher_mode': self._kdw_eki_cp_block_cipher_mode,
'padding_method': self._kdw_eki_cp_padding_method,
'hashing_algorithm': self._kdw_eki_cp_hashing_algorithm,
'key_role_type': self._kdw_eki_cp_key_role_type,
'digital_signature_algorithm':
self._kdw_eki_cp_digital_signature_algorithm,
'cryptographic_algorithm':
self._kdw_eki_cp_cryptographic_algorithm,
'random_iv': self._kdw_eki_cp_random_iv,
'iv_length': self._kdw_eki_cp_iv_length,
'tag_length': self._kdw_eki_cp_tag_length,
'fixed_field_length': self._kdw_eki_cp_fixed_field_length,
'invocation_field_length':
self._kdw_eki_cp_invocation_field_length,
'counter_length': self._kdw_eki_cp_counter_length,
'initial_counter_value':
self._kdw_eki_cp_initial_counter_value
}
}
if not any(encryption_key_info['cryptographic_parameters'].values()):
encryption_key_info['cryptographic_parameters'] = {}
if not any(encryption_key_info.values()):
encryption_key_info = {}
mac_sign_key_info = {
'unique_identifier': self._kdw_mski_unique_identifier,
'cryptographic_parameters': {
'block_cipher_mode': self._kdw_mski_cp_block_cipher_mode,
'padding_method': self._kdw_mski_cp_padding_method,
'hashing_algorithm': self._kdw_mski_cp_hashing_algorithm,
'key_role_type': self._kdw_mski_cp_key_role_type,
'digital_signature_algorithm':
self._kdw_mski_cp_digital_signature_algorithm,
'cryptographic_algorithm':
self._kdw_mski_cp_cryptographic_algorithm,
'random_iv': self._kdw_mski_cp_random_iv,
'iv_length': self._kdw_mski_cp_iv_length,
'tag_length': self._kdw_mski_cp_tag_length,
'fixed_field_length': self._kdw_mski_cp_fixed_field_length,
'invocation_field_length':
self._kdw_mski_cp_invocation_field_length,
'counter_length': self._kdw_mski_cp_counter_length,
'initial_counter_value':
self._kdw_mski_cp_initial_counter_value
}
}
if not any(mac_sign_key_info['cryptographic_parameters'].values()):
mac_sign_key_info['cryptographic_parameters'] = {}
if not any(mac_sign_key_info.values()):
mac_sign_key_info = {}
key_wrapping_data['wrapping_method'] = self._kdw_wrapping_method
key_wrapping_data['encryption_key_information'] = encryption_key_info
key_wrapping_data['mac_signature_key_information'] = mac_sign_key_info
key_wrapping_data['mac_signature'] = self._kdw_mac_signature
key_wrapping_data['iv_counter_nonce'] = self._kdw_iv_counter_nonce
key_wrapping_data['encoding_option'] = self._kdw_encoding_option
if not any(key_wrapping_data.values()):
key_wrapping_data = {}
return key_wrapping_data
|
[
"Retrieve",
"all",
"of",
"the",
"relevant",
"key",
"wrapping",
"data",
"fields",
"and",
"return",
"them",
"as",
"a",
"dictionary",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/pie/objects.py#L424-L493
|
[
"def",
"key_wrapping_data",
"(",
"self",
")",
":",
"key_wrapping_data",
"=",
"{",
"}",
"encryption_key_info",
"=",
"{",
"'unique_identifier'",
":",
"self",
".",
"_kdw_eki_unique_identifier",
",",
"'cryptographic_parameters'",
":",
"{",
"'block_cipher_mode'",
":",
"self",
".",
"_kdw_eki_cp_block_cipher_mode",
",",
"'padding_method'",
":",
"self",
".",
"_kdw_eki_cp_padding_method",
",",
"'hashing_algorithm'",
":",
"self",
".",
"_kdw_eki_cp_hashing_algorithm",
",",
"'key_role_type'",
":",
"self",
".",
"_kdw_eki_cp_key_role_type",
",",
"'digital_signature_algorithm'",
":",
"self",
".",
"_kdw_eki_cp_digital_signature_algorithm",
",",
"'cryptographic_algorithm'",
":",
"self",
".",
"_kdw_eki_cp_cryptographic_algorithm",
",",
"'random_iv'",
":",
"self",
".",
"_kdw_eki_cp_random_iv",
",",
"'iv_length'",
":",
"self",
".",
"_kdw_eki_cp_iv_length",
",",
"'tag_length'",
":",
"self",
".",
"_kdw_eki_cp_tag_length",
",",
"'fixed_field_length'",
":",
"self",
".",
"_kdw_eki_cp_fixed_field_length",
",",
"'invocation_field_length'",
":",
"self",
".",
"_kdw_eki_cp_invocation_field_length",
",",
"'counter_length'",
":",
"self",
".",
"_kdw_eki_cp_counter_length",
",",
"'initial_counter_value'",
":",
"self",
".",
"_kdw_eki_cp_initial_counter_value",
"}",
"}",
"if",
"not",
"any",
"(",
"encryption_key_info",
"[",
"'cryptographic_parameters'",
"]",
".",
"values",
"(",
")",
")",
":",
"encryption_key_info",
"[",
"'cryptographic_parameters'",
"]",
"=",
"{",
"}",
"if",
"not",
"any",
"(",
"encryption_key_info",
".",
"values",
"(",
")",
")",
":",
"encryption_key_info",
"=",
"{",
"}",
"mac_sign_key_info",
"=",
"{",
"'unique_identifier'",
":",
"self",
".",
"_kdw_mski_unique_identifier",
",",
"'cryptographic_parameters'",
":",
"{",
"'block_cipher_mode'",
":",
"self",
".",
"_kdw_mski_cp_block_cipher_mode",
",",
"'padding_method'",
":",
"self",
".",
"_kdw_mski_cp_padding_method",
",",
"'hashing_algorithm'",
":",
"self",
".",
"_kdw_mski_cp_hashing_algorithm",
",",
"'key_role_type'",
":",
"self",
".",
"_kdw_mski_cp_key_role_type",
",",
"'digital_signature_algorithm'",
":",
"self",
".",
"_kdw_mski_cp_digital_signature_algorithm",
",",
"'cryptographic_algorithm'",
":",
"self",
".",
"_kdw_mski_cp_cryptographic_algorithm",
",",
"'random_iv'",
":",
"self",
".",
"_kdw_mski_cp_random_iv",
",",
"'iv_length'",
":",
"self",
".",
"_kdw_mski_cp_iv_length",
",",
"'tag_length'",
":",
"self",
".",
"_kdw_mski_cp_tag_length",
",",
"'fixed_field_length'",
":",
"self",
".",
"_kdw_mski_cp_fixed_field_length",
",",
"'invocation_field_length'",
":",
"self",
".",
"_kdw_mski_cp_invocation_field_length",
",",
"'counter_length'",
":",
"self",
".",
"_kdw_mski_cp_counter_length",
",",
"'initial_counter_value'",
":",
"self",
".",
"_kdw_mski_cp_initial_counter_value",
"}",
"}",
"if",
"not",
"any",
"(",
"mac_sign_key_info",
"[",
"'cryptographic_parameters'",
"]",
".",
"values",
"(",
")",
")",
":",
"mac_sign_key_info",
"[",
"'cryptographic_parameters'",
"]",
"=",
"{",
"}",
"if",
"not",
"any",
"(",
"mac_sign_key_info",
".",
"values",
"(",
")",
")",
":",
"mac_sign_key_info",
"=",
"{",
"}",
"key_wrapping_data",
"[",
"'wrapping_method'",
"]",
"=",
"self",
".",
"_kdw_wrapping_method",
"key_wrapping_data",
"[",
"'encryption_key_information'",
"]",
"=",
"encryption_key_info",
"key_wrapping_data",
"[",
"'mac_signature_key_information'",
"]",
"=",
"mac_sign_key_info",
"key_wrapping_data",
"[",
"'mac_signature'",
"]",
"=",
"self",
".",
"_kdw_mac_signature",
"key_wrapping_data",
"[",
"'iv_counter_nonce'",
"]",
"=",
"self",
".",
"_kdw_iv_counter_nonce",
"key_wrapping_data",
"[",
"'encoding_option'",
"]",
"=",
"self",
".",
"_kdw_encoding_option",
"if",
"not",
"any",
"(",
"key_wrapping_data",
".",
"values",
"(",
")",
")",
":",
"key_wrapping_data",
"=",
"{",
"}",
"return",
"key_wrapping_data"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
Key.key_wrapping_data
|
Set the key wrapping data attributes using a dictionary.
|
kmip/pie/objects.py
|
def key_wrapping_data(self, value):
"""
Set the key wrapping data attributes using a dictionary.
"""
if value is None:
value = {}
elif not isinstance(value, dict):
raise TypeError("Key wrapping data must be a dictionary.")
self._kdw_wrapping_method = value.get('wrapping_method')
eki = value.get('encryption_key_information')
if eki is None:
eki = {}
self._kdw_eki_unique_identifier = eki.get('unique_identifier')
eki_cp = eki.get('cryptographic_parameters')
if eki_cp is None:
eki_cp = {}
self._kdw_eki_cp_block_cipher_mode = eki_cp.get('block_cipher_mode')
self._kdw_eki_cp_padding_method = eki_cp.get('padding_method')
self._kdw_eki_cp_hashing_algorithm = eki_cp.get('hashing_algorithm')
self._kdw_eki_cp_key_role_type = eki_cp.get('key_role_type')
self._kdw_eki_cp_digital_signature_algorithm = \
eki_cp.get('digital_signature_algorithm')
self._kdw_eki_cp_cryptographic_algorithm = \
eki_cp.get('cryptographic_algorithm')
self._kdw_eki_cp_random_iv = eki_cp.get('random_iv')
self._kdw_eki_cp_iv_length = eki_cp.get('iv_length')
self._kdw_eki_cp_tag_length = eki_cp.get('tag_length')
self._kdw_eki_cp_fixed_field_length = eki_cp.get('fixed_field_length')
self._kdw_eki_cp_invocation_field_length = \
eki_cp.get('invocation_field_length')
self._kdw_eki_cp_counter_length = eki_cp.get('counter_length')
self._kdw_eki_cp_initial_counter_value = \
eki_cp.get('initial_counter_value')
mski = value.get('mac_signature_key_information')
if mski is None:
mski = {}
self._kdw_mski_unique_identifier = mski.get('unique_identifier')
mski_cp = mski.get('cryptographic_parameters')
if mski_cp is None:
mski_cp = {}
self._kdw_mski_cp_block_cipher_mode = mski_cp.get('block_cipher_mode')
self._kdw_mski_cp_padding_method = mski_cp.get('padding_method')
self._kdw_mski_cp_hashing_algorithm = mski_cp.get('hashing_algorithm')
self._kdw_mski_cp_key_role_type = mski_cp.get('key_role_type')
self._kdw_mski_cp_digital_signature_algorithm = \
mski_cp.get('digital_signature_algorithm')
self._kdw_mski_cp_cryptographic_algorithm = \
mski_cp.get('cryptographic_algorithm')
self._kdw_mski_cp_random_iv = mski_cp.get('random_iv')
self._kdw_mski_cp_iv_length = mski_cp.get('iv_length')
self._kdw_mski_cp_tag_length = mski_cp.get('tag_length')
self._kdw_mski_cp_fixed_field_length = \
mski_cp.get('fixed_field_length')
self._kdw_mski_cp_invocation_field_length = \
mski_cp.get('invocation_field_length')
self._kdw_mski_cp_counter_length = mski_cp.get('counter_length')
self._kdw_mski_cp_initial_counter_value = \
mski_cp.get('initial_counter_value')
self._kdw_mac_signature = value.get('mac_signature')
self._kdw_iv_counter_nonce = value.get('iv_counter_nonce')
self._kdw_encoding_option = value.get('encoding_option')
|
def key_wrapping_data(self, value):
"""
Set the key wrapping data attributes using a dictionary.
"""
if value is None:
value = {}
elif not isinstance(value, dict):
raise TypeError("Key wrapping data must be a dictionary.")
self._kdw_wrapping_method = value.get('wrapping_method')
eki = value.get('encryption_key_information')
if eki is None:
eki = {}
self._kdw_eki_unique_identifier = eki.get('unique_identifier')
eki_cp = eki.get('cryptographic_parameters')
if eki_cp is None:
eki_cp = {}
self._kdw_eki_cp_block_cipher_mode = eki_cp.get('block_cipher_mode')
self._kdw_eki_cp_padding_method = eki_cp.get('padding_method')
self._kdw_eki_cp_hashing_algorithm = eki_cp.get('hashing_algorithm')
self._kdw_eki_cp_key_role_type = eki_cp.get('key_role_type')
self._kdw_eki_cp_digital_signature_algorithm = \
eki_cp.get('digital_signature_algorithm')
self._kdw_eki_cp_cryptographic_algorithm = \
eki_cp.get('cryptographic_algorithm')
self._kdw_eki_cp_random_iv = eki_cp.get('random_iv')
self._kdw_eki_cp_iv_length = eki_cp.get('iv_length')
self._kdw_eki_cp_tag_length = eki_cp.get('tag_length')
self._kdw_eki_cp_fixed_field_length = eki_cp.get('fixed_field_length')
self._kdw_eki_cp_invocation_field_length = \
eki_cp.get('invocation_field_length')
self._kdw_eki_cp_counter_length = eki_cp.get('counter_length')
self._kdw_eki_cp_initial_counter_value = \
eki_cp.get('initial_counter_value')
mski = value.get('mac_signature_key_information')
if mski is None:
mski = {}
self._kdw_mski_unique_identifier = mski.get('unique_identifier')
mski_cp = mski.get('cryptographic_parameters')
if mski_cp is None:
mski_cp = {}
self._kdw_mski_cp_block_cipher_mode = mski_cp.get('block_cipher_mode')
self._kdw_mski_cp_padding_method = mski_cp.get('padding_method')
self._kdw_mski_cp_hashing_algorithm = mski_cp.get('hashing_algorithm')
self._kdw_mski_cp_key_role_type = mski_cp.get('key_role_type')
self._kdw_mski_cp_digital_signature_algorithm = \
mski_cp.get('digital_signature_algorithm')
self._kdw_mski_cp_cryptographic_algorithm = \
mski_cp.get('cryptographic_algorithm')
self._kdw_mski_cp_random_iv = mski_cp.get('random_iv')
self._kdw_mski_cp_iv_length = mski_cp.get('iv_length')
self._kdw_mski_cp_tag_length = mski_cp.get('tag_length')
self._kdw_mski_cp_fixed_field_length = \
mski_cp.get('fixed_field_length')
self._kdw_mski_cp_invocation_field_length = \
mski_cp.get('invocation_field_length')
self._kdw_mski_cp_counter_length = mski_cp.get('counter_length')
self._kdw_mski_cp_initial_counter_value = \
mski_cp.get('initial_counter_value')
self._kdw_mac_signature = value.get('mac_signature')
self._kdw_iv_counter_nonce = value.get('iv_counter_nonce')
self._kdw_encoding_option = value.get('encoding_option')
|
[
"Set",
"the",
"key",
"wrapping",
"data",
"attributes",
"using",
"a",
"dictionary",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/pie/objects.py#L496-L560
|
[
"def",
"key_wrapping_data",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"value",
"=",
"{",
"}",
"elif",
"not",
"isinstance",
"(",
"value",
",",
"dict",
")",
":",
"raise",
"TypeError",
"(",
"\"Key wrapping data must be a dictionary.\"",
")",
"self",
".",
"_kdw_wrapping_method",
"=",
"value",
".",
"get",
"(",
"'wrapping_method'",
")",
"eki",
"=",
"value",
".",
"get",
"(",
"'encryption_key_information'",
")",
"if",
"eki",
"is",
"None",
":",
"eki",
"=",
"{",
"}",
"self",
".",
"_kdw_eki_unique_identifier",
"=",
"eki",
".",
"get",
"(",
"'unique_identifier'",
")",
"eki_cp",
"=",
"eki",
".",
"get",
"(",
"'cryptographic_parameters'",
")",
"if",
"eki_cp",
"is",
"None",
":",
"eki_cp",
"=",
"{",
"}",
"self",
".",
"_kdw_eki_cp_block_cipher_mode",
"=",
"eki_cp",
".",
"get",
"(",
"'block_cipher_mode'",
")",
"self",
".",
"_kdw_eki_cp_padding_method",
"=",
"eki_cp",
".",
"get",
"(",
"'padding_method'",
")",
"self",
".",
"_kdw_eki_cp_hashing_algorithm",
"=",
"eki_cp",
".",
"get",
"(",
"'hashing_algorithm'",
")",
"self",
".",
"_kdw_eki_cp_key_role_type",
"=",
"eki_cp",
".",
"get",
"(",
"'key_role_type'",
")",
"self",
".",
"_kdw_eki_cp_digital_signature_algorithm",
"=",
"eki_cp",
".",
"get",
"(",
"'digital_signature_algorithm'",
")",
"self",
".",
"_kdw_eki_cp_cryptographic_algorithm",
"=",
"eki_cp",
".",
"get",
"(",
"'cryptographic_algorithm'",
")",
"self",
".",
"_kdw_eki_cp_random_iv",
"=",
"eki_cp",
".",
"get",
"(",
"'random_iv'",
")",
"self",
".",
"_kdw_eki_cp_iv_length",
"=",
"eki_cp",
".",
"get",
"(",
"'iv_length'",
")",
"self",
".",
"_kdw_eki_cp_tag_length",
"=",
"eki_cp",
".",
"get",
"(",
"'tag_length'",
")",
"self",
".",
"_kdw_eki_cp_fixed_field_length",
"=",
"eki_cp",
".",
"get",
"(",
"'fixed_field_length'",
")",
"self",
".",
"_kdw_eki_cp_invocation_field_length",
"=",
"eki_cp",
".",
"get",
"(",
"'invocation_field_length'",
")",
"self",
".",
"_kdw_eki_cp_counter_length",
"=",
"eki_cp",
".",
"get",
"(",
"'counter_length'",
")",
"self",
".",
"_kdw_eki_cp_initial_counter_value",
"=",
"eki_cp",
".",
"get",
"(",
"'initial_counter_value'",
")",
"mski",
"=",
"value",
".",
"get",
"(",
"'mac_signature_key_information'",
")",
"if",
"mski",
"is",
"None",
":",
"mski",
"=",
"{",
"}",
"self",
".",
"_kdw_mski_unique_identifier",
"=",
"mski",
".",
"get",
"(",
"'unique_identifier'",
")",
"mski_cp",
"=",
"mski",
".",
"get",
"(",
"'cryptographic_parameters'",
")",
"if",
"mski_cp",
"is",
"None",
":",
"mski_cp",
"=",
"{",
"}",
"self",
".",
"_kdw_mski_cp_block_cipher_mode",
"=",
"mski_cp",
".",
"get",
"(",
"'block_cipher_mode'",
")",
"self",
".",
"_kdw_mski_cp_padding_method",
"=",
"mski_cp",
".",
"get",
"(",
"'padding_method'",
")",
"self",
".",
"_kdw_mski_cp_hashing_algorithm",
"=",
"mski_cp",
".",
"get",
"(",
"'hashing_algorithm'",
")",
"self",
".",
"_kdw_mski_cp_key_role_type",
"=",
"mski_cp",
".",
"get",
"(",
"'key_role_type'",
")",
"self",
".",
"_kdw_mski_cp_digital_signature_algorithm",
"=",
"mski_cp",
".",
"get",
"(",
"'digital_signature_algorithm'",
")",
"self",
".",
"_kdw_mski_cp_cryptographic_algorithm",
"=",
"mski_cp",
".",
"get",
"(",
"'cryptographic_algorithm'",
")",
"self",
".",
"_kdw_mski_cp_random_iv",
"=",
"mski_cp",
".",
"get",
"(",
"'random_iv'",
")",
"self",
".",
"_kdw_mski_cp_iv_length",
"=",
"mski_cp",
".",
"get",
"(",
"'iv_length'",
")",
"self",
".",
"_kdw_mski_cp_tag_length",
"=",
"mski_cp",
".",
"get",
"(",
"'tag_length'",
")",
"self",
".",
"_kdw_mski_cp_fixed_field_length",
"=",
"mski_cp",
".",
"get",
"(",
"'fixed_field_length'",
")",
"self",
".",
"_kdw_mski_cp_invocation_field_length",
"=",
"mski_cp",
".",
"get",
"(",
"'invocation_field_length'",
")",
"self",
".",
"_kdw_mski_cp_counter_length",
"=",
"mski_cp",
".",
"get",
"(",
"'counter_length'",
")",
"self",
".",
"_kdw_mski_cp_initial_counter_value",
"=",
"mski_cp",
".",
"get",
"(",
"'initial_counter_value'",
")",
"self",
".",
"_kdw_mac_signature",
"=",
"value",
".",
"get",
"(",
"'mac_signature'",
")",
"self",
".",
"_kdw_iv_counter_nonce",
"=",
"value",
".",
"get",
"(",
"'iv_counter_nonce'",
")",
"self",
".",
"_kdw_encoding_option",
"=",
"value",
".",
"get",
"(",
"'encoding_option'",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
PublicKey.validate
|
Verify that the contents of the PublicKey object are valid.
Raises:
TypeError: if the types of any PublicKey attributes are invalid.
|
kmip/pie/objects.py
|
def validate(self):
"""
Verify that the contents of the PublicKey object are valid.
Raises:
TypeError: if the types of any PublicKey attributes are invalid.
"""
if not isinstance(self.value, bytes):
raise TypeError("key value must be bytes")
elif not isinstance(self.cryptographic_algorithm,
enums.CryptographicAlgorithm):
raise TypeError("key algorithm must be a CryptographicAlgorithm "
"enumeration")
elif not isinstance(self.cryptographic_length, six.integer_types):
raise TypeError("key length must be an integer")
elif not isinstance(self.key_format_type, enums.KeyFormatType):
raise TypeError("key format type must be a KeyFormatType "
"enumeration")
elif self.key_format_type not in self._valid_formats:
raise ValueError("key format type must be one of {0}".format(
self._valid_formats))
# TODO (peter-hamilton) Verify that the key bytes match the key format
mask_count = len(self.cryptographic_usage_masks)
for i in range(mask_count):
mask = self.cryptographic_usage_masks[i]
if not isinstance(mask, enums.CryptographicUsageMask):
position = "({0} in list)".format(i)
raise TypeError(
"key mask {0} must be a CryptographicUsageMask "
"enumeration".format(position))
name_count = len(self.names)
for i in range(name_count):
name = self.names[i]
if not isinstance(name, six.string_types):
position = "({0} in list)".format(i)
raise TypeError("key name {0} must be a string".format(
position))
|
def validate(self):
"""
Verify that the contents of the PublicKey object are valid.
Raises:
TypeError: if the types of any PublicKey attributes are invalid.
"""
if not isinstance(self.value, bytes):
raise TypeError("key value must be bytes")
elif not isinstance(self.cryptographic_algorithm,
enums.CryptographicAlgorithm):
raise TypeError("key algorithm must be a CryptographicAlgorithm "
"enumeration")
elif not isinstance(self.cryptographic_length, six.integer_types):
raise TypeError("key length must be an integer")
elif not isinstance(self.key_format_type, enums.KeyFormatType):
raise TypeError("key format type must be a KeyFormatType "
"enumeration")
elif self.key_format_type not in self._valid_formats:
raise ValueError("key format type must be one of {0}".format(
self._valid_formats))
# TODO (peter-hamilton) Verify that the key bytes match the key format
mask_count = len(self.cryptographic_usage_masks)
for i in range(mask_count):
mask = self.cryptographic_usage_masks[i]
if not isinstance(mask, enums.CryptographicUsageMask):
position = "({0} in list)".format(i)
raise TypeError(
"key mask {0} must be a CryptographicUsageMask "
"enumeration".format(position))
name_count = len(self.names)
for i in range(name_count):
name = self.names[i]
if not isinstance(name, six.string_types):
position = "({0} in list)".format(i)
raise TypeError("key name {0} must be a string".format(
position))
|
[
"Verify",
"that",
"the",
"contents",
"of",
"the",
"PublicKey",
"object",
"are",
"valid",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/pie/objects.py#L806-L845
|
[
"def",
"validate",
"(",
"self",
")",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"value",
",",
"bytes",
")",
":",
"raise",
"TypeError",
"(",
"\"key value must be bytes\"",
")",
"elif",
"not",
"isinstance",
"(",
"self",
".",
"cryptographic_algorithm",
",",
"enums",
".",
"CryptographicAlgorithm",
")",
":",
"raise",
"TypeError",
"(",
"\"key algorithm must be a CryptographicAlgorithm \"",
"\"enumeration\"",
")",
"elif",
"not",
"isinstance",
"(",
"self",
".",
"cryptographic_length",
",",
"six",
".",
"integer_types",
")",
":",
"raise",
"TypeError",
"(",
"\"key length must be an integer\"",
")",
"elif",
"not",
"isinstance",
"(",
"self",
".",
"key_format_type",
",",
"enums",
".",
"KeyFormatType",
")",
":",
"raise",
"TypeError",
"(",
"\"key format type must be a KeyFormatType \"",
"\"enumeration\"",
")",
"elif",
"self",
".",
"key_format_type",
"not",
"in",
"self",
".",
"_valid_formats",
":",
"raise",
"ValueError",
"(",
"\"key format type must be one of {0}\"",
".",
"format",
"(",
"self",
".",
"_valid_formats",
")",
")",
"# TODO (peter-hamilton) Verify that the key bytes match the key format",
"mask_count",
"=",
"len",
"(",
"self",
".",
"cryptographic_usage_masks",
")",
"for",
"i",
"in",
"range",
"(",
"mask_count",
")",
":",
"mask",
"=",
"self",
".",
"cryptographic_usage_masks",
"[",
"i",
"]",
"if",
"not",
"isinstance",
"(",
"mask",
",",
"enums",
".",
"CryptographicUsageMask",
")",
":",
"position",
"=",
"\"({0} in list)\"",
".",
"format",
"(",
"i",
")",
"raise",
"TypeError",
"(",
"\"key mask {0} must be a CryptographicUsageMask \"",
"\"enumeration\"",
".",
"format",
"(",
"position",
")",
")",
"name_count",
"=",
"len",
"(",
"self",
".",
"names",
")",
"for",
"i",
"in",
"range",
"(",
"name_count",
")",
":",
"name",
"=",
"self",
".",
"names",
"[",
"i",
"]",
"if",
"not",
"isinstance",
"(",
"name",
",",
"six",
".",
"string_types",
")",
":",
"position",
"=",
"\"({0} in list)\"",
".",
"format",
"(",
"i",
")",
"raise",
"TypeError",
"(",
"\"key name {0} must be a string\"",
".",
"format",
"(",
"position",
")",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
SecretData.validate
|
Verify that the contents of the SecretData object are valid.
Raises:
TypeError: if the types of any SecretData attributes are invalid.
|
kmip/pie/objects.py
|
def validate(self):
"""
Verify that the contents of the SecretData object are valid.
Raises:
TypeError: if the types of any SecretData attributes are invalid.
"""
if not isinstance(self.value, bytes):
raise TypeError("secret value must be bytes")
elif not isinstance(self.data_type, enums.SecretDataType):
raise TypeError("secret data type must be a SecretDataType "
"enumeration")
mask_count = len(self.cryptographic_usage_masks)
for i in range(mask_count):
mask = self.cryptographic_usage_masks[i]
if not isinstance(mask, enums.CryptographicUsageMask):
position = "({0} in list)".format(i)
raise TypeError(
"secret data mask {0} must be a CryptographicUsageMask "
"enumeration".format(position))
name_count = len(self.names)
for i in range(name_count):
name = self.names[i]
if not isinstance(name, six.string_types):
position = "({0} in list)".format(i)
raise TypeError("secret data name {0} must be a string".format(
position))
|
def validate(self):
"""
Verify that the contents of the SecretData object are valid.
Raises:
TypeError: if the types of any SecretData attributes are invalid.
"""
if not isinstance(self.value, bytes):
raise TypeError("secret value must be bytes")
elif not isinstance(self.data_type, enums.SecretDataType):
raise TypeError("secret data type must be a SecretDataType "
"enumeration")
mask_count = len(self.cryptographic_usage_masks)
for i in range(mask_count):
mask = self.cryptographic_usage_masks[i]
if not isinstance(mask, enums.CryptographicUsageMask):
position = "({0} in list)".format(i)
raise TypeError(
"secret data mask {0} must be a CryptographicUsageMask "
"enumeration".format(position))
name_count = len(self.names)
for i in range(name_count):
name = self.names[i]
if not isinstance(name, six.string_types):
position = "({0} in list)".format(i)
raise TypeError("secret data name {0} must be a string".format(
position))
|
[
"Verify",
"that",
"the",
"contents",
"of",
"the",
"SecretData",
"object",
"are",
"valid",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/pie/objects.py#L1291-L1319
|
[
"def",
"validate",
"(",
"self",
")",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"value",
",",
"bytes",
")",
":",
"raise",
"TypeError",
"(",
"\"secret value must be bytes\"",
")",
"elif",
"not",
"isinstance",
"(",
"self",
".",
"data_type",
",",
"enums",
".",
"SecretDataType",
")",
":",
"raise",
"TypeError",
"(",
"\"secret data type must be a SecretDataType \"",
"\"enumeration\"",
")",
"mask_count",
"=",
"len",
"(",
"self",
".",
"cryptographic_usage_masks",
")",
"for",
"i",
"in",
"range",
"(",
"mask_count",
")",
":",
"mask",
"=",
"self",
".",
"cryptographic_usage_masks",
"[",
"i",
"]",
"if",
"not",
"isinstance",
"(",
"mask",
",",
"enums",
".",
"CryptographicUsageMask",
")",
":",
"position",
"=",
"\"({0} in list)\"",
".",
"format",
"(",
"i",
")",
"raise",
"TypeError",
"(",
"\"secret data mask {0} must be a CryptographicUsageMask \"",
"\"enumeration\"",
".",
"format",
"(",
"position",
")",
")",
"name_count",
"=",
"len",
"(",
"self",
".",
"names",
")",
"for",
"i",
"in",
"range",
"(",
"name_count",
")",
":",
"name",
"=",
"self",
".",
"names",
"[",
"i",
"]",
"if",
"not",
"isinstance",
"(",
"name",
",",
"six",
".",
"string_types",
")",
":",
"position",
"=",
"\"({0} in list)\"",
".",
"format",
"(",
"i",
")",
"raise",
"TypeError",
"(",
"\"secret data name {0} must be a string\"",
".",
"format",
"(",
"position",
")",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
OpaqueObject.validate
|
Verify that the contents of the OpaqueObject are valid.
Raises:
TypeError: if the types of any OpaqueObject attributes are invalid.
|
kmip/pie/objects.py
|
def validate(self):
"""
Verify that the contents of the OpaqueObject are valid.
Raises:
TypeError: if the types of any OpaqueObject attributes are invalid.
"""
if not isinstance(self.value, bytes):
raise TypeError("opaque value must be bytes")
elif not isinstance(self.opaque_type, enums.OpaqueDataType):
raise TypeError("opaque data type must be an OpaqueDataType "
"enumeration")
name_count = len(self.names)
for i in range(name_count):
name = self.names[i]
if not isinstance(name, six.string_types):
position = "({0} in list)".format(i)
raise TypeError("opaque data name {0} must be a string".format(
position))
|
def validate(self):
"""
Verify that the contents of the OpaqueObject are valid.
Raises:
TypeError: if the types of any OpaqueObject attributes are invalid.
"""
if not isinstance(self.value, bytes):
raise TypeError("opaque value must be bytes")
elif not isinstance(self.opaque_type, enums.OpaqueDataType):
raise TypeError("opaque data type must be an OpaqueDataType "
"enumeration")
name_count = len(self.names)
for i in range(name_count):
name = self.names[i]
if not isinstance(name, six.string_types):
position = "({0} in list)".format(i)
raise TypeError("opaque data name {0} must be a string".format(
position))
|
[
"Verify",
"that",
"the",
"contents",
"of",
"the",
"OpaqueObject",
"are",
"valid",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/pie/objects.py#L1407-L1426
|
[
"def",
"validate",
"(",
"self",
")",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"value",
",",
"bytes",
")",
":",
"raise",
"TypeError",
"(",
"\"opaque value must be bytes\"",
")",
"elif",
"not",
"isinstance",
"(",
"self",
".",
"opaque_type",
",",
"enums",
".",
"OpaqueDataType",
")",
":",
"raise",
"TypeError",
"(",
"\"opaque data type must be an OpaqueDataType \"",
"\"enumeration\"",
")",
"name_count",
"=",
"len",
"(",
"self",
".",
"names",
")",
"for",
"i",
"in",
"range",
"(",
"name_count",
")",
":",
"name",
"=",
"self",
".",
"names",
"[",
"i",
"]",
"if",
"not",
"isinstance",
"(",
"name",
",",
"six",
".",
"string_types",
")",
":",
"position",
"=",
"\"({0} in list)\"",
".",
"format",
"(",
"i",
")",
"raise",
"TypeError",
"(",
"\"opaque data name {0} must be a string\"",
".",
"format",
"(",
"position",
")",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
convert_attribute_name_to_tag
|
A utility function that converts an attribute name string into the
corresponding attribute tag.
For example: 'State' -> enums.Tags.STATE
Args:
value (string): The string name of the attribute.
Returns:
enum: The Tags enumeration value that corresponds to the attribute
name string.
Raises:
ValueError: if the attribute name string is not a string or if it is
an unrecognized attribute name
|
kmip/core/enums.py
|
def convert_attribute_name_to_tag(value):
"""
A utility function that converts an attribute name string into the
corresponding attribute tag.
For example: 'State' -> enums.Tags.STATE
Args:
value (string): The string name of the attribute.
Returns:
enum: The Tags enumeration value that corresponds to the attribute
name string.
Raises:
ValueError: if the attribute name string is not a string or if it is
an unrecognized attribute name
"""
if not isinstance(value, six.string_types):
raise ValueError("The attribute name must be a string.")
for entry in attribute_name_tag_table:
if value == entry[0]:
return entry[1]
raise ValueError("Unrecognized attribute name: '{}'".format(value))
|
def convert_attribute_name_to_tag(value):
"""
A utility function that converts an attribute name string into the
corresponding attribute tag.
For example: 'State' -> enums.Tags.STATE
Args:
value (string): The string name of the attribute.
Returns:
enum: The Tags enumeration value that corresponds to the attribute
name string.
Raises:
ValueError: if the attribute name string is not a string or if it is
an unrecognized attribute name
"""
if not isinstance(value, six.string_types):
raise ValueError("The attribute name must be a string.")
for entry in attribute_name_tag_table:
if value == entry[0]:
return entry[1]
raise ValueError("Unrecognized attribute name: '{}'".format(value))
|
[
"A",
"utility",
"function",
"that",
"converts",
"an",
"attribute",
"name",
"string",
"into",
"the",
"corresponding",
"attribute",
"tag",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/enums.py#L1762-L1787
|
[
"def",
"convert_attribute_name_to_tag",
"(",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"six",
".",
"string_types",
")",
":",
"raise",
"ValueError",
"(",
"\"The attribute name must be a string.\"",
")",
"for",
"entry",
"in",
"attribute_name_tag_table",
":",
"if",
"value",
"==",
"entry",
"[",
"0",
"]",
":",
"return",
"entry",
"[",
"1",
"]",
"raise",
"ValueError",
"(",
"\"Unrecognized attribute name: '{}'\"",
".",
"format",
"(",
"value",
")",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
convert_attribute_tag_to_name
|
A utility function that converts an attribute tag into the corresponding
attribute name string.
For example: enums.Tags.STATE -> 'State'
Args:
value (enum): The Tags enumeration value of the attribute.
Returns:
string: The attribute name string that corresponds to the attribute
tag.
Raises:
ValueError: if the attribute tag is not a Tags enumeration or if it
is unrecognized attribute tag
|
kmip/core/enums.py
|
def convert_attribute_tag_to_name(value):
"""
A utility function that converts an attribute tag into the corresponding
attribute name string.
For example: enums.Tags.STATE -> 'State'
Args:
value (enum): The Tags enumeration value of the attribute.
Returns:
string: The attribute name string that corresponds to the attribute
tag.
Raises:
ValueError: if the attribute tag is not a Tags enumeration or if it
is unrecognized attribute tag
"""
if not isinstance(value, Tags):
raise ValueError("The attribute tag must be a Tags enumeration.")
for entry in attribute_name_tag_table:
if value == entry[1]:
return entry[0]
raise ValueError("Unrecognized attribute tag: {}".format(value))
|
def convert_attribute_tag_to_name(value):
"""
A utility function that converts an attribute tag into the corresponding
attribute name string.
For example: enums.Tags.STATE -> 'State'
Args:
value (enum): The Tags enumeration value of the attribute.
Returns:
string: The attribute name string that corresponds to the attribute
tag.
Raises:
ValueError: if the attribute tag is not a Tags enumeration or if it
is unrecognized attribute tag
"""
if not isinstance(value, Tags):
raise ValueError("The attribute tag must be a Tags enumeration.")
for entry in attribute_name_tag_table:
if value == entry[1]:
return entry[0]
raise ValueError("Unrecognized attribute tag: {}".format(value))
|
[
"A",
"utility",
"function",
"that",
"converts",
"an",
"attribute",
"tag",
"into",
"the",
"corresponding",
"attribute",
"name",
"string",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/enums.py#L1790-L1815
|
[
"def",
"convert_attribute_tag_to_name",
"(",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"Tags",
")",
":",
"raise",
"ValueError",
"(",
"\"The attribute tag must be a Tags enumeration.\"",
")",
"for",
"entry",
"in",
"attribute_name_tag_table",
":",
"if",
"value",
"==",
"entry",
"[",
"1",
"]",
":",
"return",
"entry",
"[",
"0",
"]",
"raise",
"ValueError",
"(",
"\"Unrecognized attribute tag: {}\"",
".",
"format",
"(",
"value",
")",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
get_bit_mask_from_enumerations
|
A utility function that computes a bit mask from a collection of
enumeration values.
Args:
enumerations (list): A list of enumeration values to be combined in a
composite bit mask.
Returns:
int: The composite bit mask.
|
kmip/core/enums.py
|
def get_bit_mask_from_enumerations(enumerations):
"""
A utility function that computes a bit mask from a collection of
enumeration values.
Args:
enumerations (list): A list of enumeration values to be combined in a
composite bit mask.
Returns:
int: The composite bit mask.
"""
return functools.reduce(
lambda x, y: x | y, [z.value for z in enumerations]
)
|
def get_bit_mask_from_enumerations(enumerations):
"""
A utility function that computes a bit mask from a collection of
enumeration values.
Args:
enumerations (list): A list of enumeration values to be combined in a
composite bit mask.
Returns:
int: The composite bit mask.
"""
return functools.reduce(
lambda x, y: x | y, [z.value for z in enumerations]
)
|
[
"A",
"utility",
"function",
"that",
"computes",
"a",
"bit",
"mask",
"from",
"a",
"collection",
"of",
"enumeration",
"values",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/enums.py#L1818-L1832
|
[
"def",
"get_bit_mask_from_enumerations",
"(",
"enumerations",
")",
":",
"return",
"functools",
".",
"reduce",
"(",
"lambda",
"x",
",",
"y",
":",
"x",
"|",
"y",
",",
"[",
"z",
".",
"value",
"for",
"z",
"in",
"enumerations",
"]",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
get_enumerations_from_bit_mask
|
A utility function that creates a list of enumeration values from a bit
mask for a specific mask enumeration class.
Args:
enumeration (class): The enumeration class from which to draw
enumeration values.
mask (int): The bit mask from which to identify enumeration values.
Returns:
list: A list of enumeration values corresponding to the bit mask.
|
kmip/core/enums.py
|
def get_enumerations_from_bit_mask(enumeration, mask):
"""
A utility function that creates a list of enumeration values from a bit
mask for a specific mask enumeration class.
Args:
enumeration (class): The enumeration class from which to draw
enumeration values.
mask (int): The bit mask from which to identify enumeration values.
Returns:
list: A list of enumeration values corresponding to the bit mask.
"""
return [x for x in enumeration if (x.value & mask) == x.value]
|
def get_enumerations_from_bit_mask(enumeration, mask):
"""
A utility function that creates a list of enumeration values from a bit
mask for a specific mask enumeration class.
Args:
enumeration (class): The enumeration class from which to draw
enumeration values.
mask (int): The bit mask from which to identify enumeration values.
Returns:
list: A list of enumeration values corresponding to the bit mask.
"""
return [x for x in enumeration if (x.value & mask) == x.value]
|
[
"A",
"utility",
"function",
"that",
"creates",
"a",
"list",
"of",
"enumeration",
"values",
"from",
"a",
"bit",
"mask",
"for",
"a",
"specific",
"mask",
"enumeration",
"class",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/enums.py#L1835-L1848
|
[
"def",
"get_enumerations_from_bit_mask",
"(",
"enumeration",
",",
"mask",
")",
":",
"return",
"[",
"x",
"for",
"x",
"in",
"enumeration",
"if",
"(",
"x",
".",
"value",
"&",
"mask",
")",
"==",
"x",
".",
"value",
"]"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
is_bit_mask
|
A utility function that checks if the provided value is a composite bit
mask of enumeration values in the specified enumeration class.
Args:
enumeration (class): One of the mask enumeration classes found in this
file. These include:
* Cryptographic Usage Mask
* Protection Storage Mask
* Storage Status Mask
potential_mask (int): A potential bit mask composed of enumeration
values belonging to the enumeration class.
Returns:
True: if the potential mask is a valid bit mask of the mask enumeration
False: otherwise
|
kmip/core/enums.py
|
def is_bit_mask(enumeration, potential_mask):
"""
A utility function that checks if the provided value is a composite bit
mask of enumeration values in the specified enumeration class.
Args:
enumeration (class): One of the mask enumeration classes found in this
file. These include:
* Cryptographic Usage Mask
* Protection Storage Mask
* Storage Status Mask
potential_mask (int): A potential bit mask composed of enumeration
values belonging to the enumeration class.
Returns:
True: if the potential mask is a valid bit mask of the mask enumeration
False: otherwise
"""
if not isinstance(potential_mask, six.integer_types):
return False
mask_enumerations = (
CryptographicUsageMask,
ProtectionStorageMask,
StorageStatusMask
)
if enumeration not in mask_enumerations:
return False
mask = 0
for value in [e.value for e in enumeration]:
if (value & potential_mask) == value:
mask |= value
if mask != potential_mask:
return False
return True
|
def is_bit_mask(enumeration, potential_mask):
"""
A utility function that checks if the provided value is a composite bit
mask of enumeration values in the specified enumeration class.
Args:
enumeration (class): One of the mask enumeration classes found in this
file. These include:
* Cryptographic Usage Mask
* Protection Storage Mask
* Storage Status Mask
potential_mask (int): A potential bit mask composed of enumeration
values belonging to the enumeration class.
Returns:
True: if the potential mask is a valid bit mask of the mask enumeration
False: otherwise
"""
if not isinstance(potential_mask, six.integer_types):
return False
mask_enumerations = (
CryptographicUsageMask,
ProtectionStorageMask,
StorageStatusMask
)
if enumeration not in mask_enumerations:
return False
mask = 0
for value in [e.value for e in enumeration]:
if (value & potential_mask) == value:
mask |= value
if mask != potential_mask:
return False
return True
|
[
"A",
"utility",
"function",
"that",
"checks",
"if",
"the",
"provided",
"value",
"is",
"a",
"composite",
"bit",
"mask",
"of",
"enumeration",
"values",
"in",
"the",
"specified",
"enumeration",
"class",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/enums.py#L1851-L1888
|
[
"def",
"is_bit_mask",
"(",
"enumeration",
",",
"potential_mask",
")",
":",
"if",
"not",
"isinstance",
"(",
"potential_mask",
",",
"six",
".",
"integer_types",
")",
":",
"return",
"False",
"mask_enumerations",
"=",
"(",
"CryptographicUsageMask",
",",
"ProtectionStorageMask",
",",
"StorageStatusMask",
")",
"if",
"enumeration",
"not",
"in",
"mask_enumerations",
":",
"return",
"False",
"mask",
"=",
"0",
"for",
"value",
"in",
"[",
"e",
".",
"value",
"for",
"e",
"in",
"enumeration",
"]",
":",
"if",
"(",
"value",
"&",
"potential_mask",
")",
"==",
"value",
":",
"mask",
"|=",
"value",
"if",
"mask",
"!=",
"potential_mask",
":",
"return",
"False",
"return",
"True"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
is_attribute
|
A utility function that checks if the tag is a valid attribute tag.
Args:
tag (enum): A Tags enumeration that may or may not correspond to a
KMIP attribute type.
kmip_version (enum): The KMIPVersion enumeration that should be used
when checking if the tag is a valid attribute tag. Optional,
defaults to None. If None, the tag is compared with all possible
attribute tags across all KMIP versions. Otherwise, only the
attribute tags for a specific KMIP version are checked.
Returns:
True: if the tag is a valid attribute tag
False: otherwise
|
kmip/core/enums.py
|
def is_attribute(tag, kmip_version=None):
"""
A utility function that checks if the tag is a valid attribute tag.
Args:
tag (enum): A Tags enumeration that may or may not correspond to a
KMIP attribute type.
kmip_version (enum): The KMIPVersion enumeration that should be used
when checking if the tag is a valid attribute tag. Optional,
defaults to None. If None, the tag is compared with all possible
attribute tags across all KMIP versions. Otherwise, only the
attribute tags for a specific KMIP version are checked.
Returns:
True: if the tag is a valid attribute tag
False: otherwise
"""
kmip_1_0_attribute_tags = [
Tags.UNIQUE_IDENTIFIER,
Tags.NAME,
Tags.OBJECT_TYPE,
Tags.CRYPTOGRAPHIC_ALGORITHM,
Tags.CRYPTOGRAPHIC_LENGTH,
Tags.CRYPTOGRAPHIC_PARAMETERS,
Tags.CRYPTOGRAPHIC_DOMAIN_PARAMETERS,
Tags.CERTIFICATE_TYPE,
Tags.CERTIFICATE_IDENTIFIER,
Tags.CERTIFICATE_SUBJECT,
Tags.CERTIFICATE_ISSUER,
Tags.DIGEST,
Tags.OPERATION_POLICY_NAME,
Tags.CRYPTOGRAPHIC_USAGE_MASK,
Tags.LEASE_TIME,
Tags.USAGE_LIMITS,
Tags.STATE,
Tags.INITIAL_DATE,
Tags.ACTIVATION_DATE,
Tags.PROCESS_START_DATE,
Tags.PROTECT_STOP_DATE,
Tags.DEACTIVATION_DATE,
Tags.DESTROY_DATE,
Tags.COMPROMISE_OCCURRENCE_DATE,
Tags.COMPROMISE_DATE,
Tags.REVOCATION_REASON,
Tags.ARCHIVE_DATE,
Tags.OBJECT_GROUP,
Tags.LINK,
Tags.APPLICATION_SPECIFIC_INFORMATION,
Tags.CONTACT_INFORMATION,
Tags.LAST_CHANGE_DATE,
Tags.CUSTOM_ATTRIBUTE
]
kmip_1_1_attribute_tags = copy.deepcopy(kmip_1_0_attribute_tags) + [
Tags.CERTIFICATE_LENGTH,
Tags.X_509_CERTIFICATE_IDENTIFIER,
Tags.X_509_CERTIFICATE_SUBJECT,
Tags.X_509_CERTIFICATE_ISSUER,
Tags.DIGITAL_SIGNATURE_ALGORITHM,
Tags.FRESH
]
kmip_1_2_attribute_tags = copy.deepcopy(kmip_1_1_attribute_tags) + [
Tags.ALTERNATIVE_NAME,
Tags.KEY_VALUE_PRESENT,
Tags.KEY_VALUE_LOCATION,
Tags.ORIGINAL_CREATION_DATE
]
kmip_1_3_attribute_tags = copy.deepcopy(kmip_1_2_attribute_tags) + [
Tags.RANDOM_NUMBER_GENERATOR
]
kmip_1_4_attribute_tags = copy.deepcopy(kmip_1_3_attribute_tags) + [
Tags.PKCS12_FRIENDLY_NAME,
Tags.DESCRIPTION,
Tags.COMMENT,
Tags.SENSITIVE,
Tags.ALWAYS_SENSITIVE,
Tags.EXTRACTABLE,
Tags.NEVER_EXTRACTABLE
]
kmip_2_0_attribute_tags = copy.deepcopy(kmip_1_4_attribute_tags) + [
Tags.CERTIFICATE_SUBJECT_CN,
Tags.CERTIFICATE_SUBJECT_O,
Tags.CERTIFICATE_SUBJECT_OU,
Tags.CERTIFICATE_SUBJECT_EMAIL,
Tags.CERTIFICATE_SUBJECT_C,
Tags.CERTIFICATE_SUBJECT_ST,
Tags.CERTIFICATE_SUBJECT_L,
Tags.CERTIFICATE_SUBJECT_UID,
Tags.CERTIFICATE_SUBJECT_SERIAL_NUMBER,
Tags.CERTIFICATE_SUBJECT_TITLE,
Tags.CERTIFICATE_SUBJECT_DC,
Tags.CERTIFICATE_SUBJECT_DN_QUALIFIER,
Tags.CERTIFICATE_ISSUER_CN,
Tags.CERTIFICATE_ISSUER_O,
Tags.CERTIFICATE_ISSUER_OU,
Tags.CERTIFICATE_ISSUER_EMAIL,
Tags.CERTIFICATE_ISSUER_C,
Tags.CERTIFICATE_ISSUER_ST,
Tags.CERTIFICATE_ISSUER_L,
Tags.CERTIFICATE_ISSUER_UID,
Tags.CERTIFICATE_ISSUER_SERIAL_NUMBER,
Tags.CERTIFICATE_ISSUER_TITLE,
Tags.CERTIFICATE_ISSUER_DC,
Tags.CERTIFICATE_ISSUER_DN_QUALIFIER,
Tags.KEY_FORMAT_TYPE,
Tags.NIST_KEY_TYPE,
Tags.OPAQUE_DATA_TYPE,
Tags.PROTECTION_LEVEL,
Tags.PROTECTION_PERIOD,
Tags.PROTECTION_STORAGE_MASK,
Tags.QUANTUM_SAFE,
Tags.SHORT_UNIQUE_IDENTIFIER,
Tags.ATTRIBUTE
]
kmip_2_0_attribute_tags.remove(Tags.CERTIFICATE_IDENTIFIER)
kmip_2_0_attribute_tags.remove(Tags.CERTIFICATE_SUBJECT)
kmip_2_0_attribute_tags.remove(Tags.CERTIFICATE_ISSUER)
kmip_2_0_attribute_tags.remove(Tags.OPERATION_POLICY_NAME)
kmip_2_0_attribute_tags.remove(Tags.CUSTOM_ATTRIBUTE)
if kmip_version == KMIPVersion.KMIP_1_0:
return tag in kmip_1_0_attribute_tags
elif kmip_version == KMIPVersion.KMIP_1_1:
return tag in kmip_1_1_attribute_tags
elif kmip_version == KMIPVersion.KMIP_1_2:
return tag in kmip_1_2_attribute_tags
elif kmip_version == KMIPVersion.KMIP_1_3:
return tag in kmip_1_3_attribute_tags
elif kmip_version == KMIPVersion.KMIP_1_4:
return tag in kmip_1_4_attribute_tags
elif kmip_version == KMIPVersion.KMIP_2_0:
return tag in kmip_2_0_attribute_tags
else:
all_attribute_tags = set(
kmip_1_0_attribute_tags +
kmip_1_1_attribute_tags +
kmip_1_2_attribute_tags +
kmip_1_3_attribute_tags +
kmip_1_4_attribute_tags +
kmip_2_0_attribute_tags
)
return tag in all_attribute_tags
|
def is_attribute(tag, kmip_version=None):
"""
A utility function that checks if the tag is a valid attribute tag.
Args:
tag (enum): A Tags enumeration that may or may not correspond to a
KMIP attribute type.
kmip_version (enum): The KMIPVersion enumeration that should be used
when checking if the tag is a valid attribute tag. Optional,
defaults to None. If None, the tag is compared with all possible
attribute tags across all KMIP versions. Otherwise, only the
attribute tags for a specific KMIP version are checked.
Returns:
True: if the tag is a valid attribute tag
False: otherwise
"""
kmip_1_0_attribute_tags = [
Tags.UNIQUE_IDENTIFIER,
Tags.NAME,
Tags.OBJECT_TYPE,
Tags.CRYPTOGRAPHIC_ALGORITHM,
Tags.CRYPTOGRAPHIC_LENGTH,
Tags.CRYPTOGRAPHIC_PARAMETERS,
Tags.CRYPTOGRAPHIC_DOMAIN_PARAMETERS,
Tags.CERTIFICATE_TYPE,
Tags.CERTIFICATE_IDENTIFIER,
Tags.CERTIFICATE_SUBJECT,
Tags.CERTIFICATE_ISSUER,
Tags.DIGEST,
Tags.OPERATION_POLICY_NAME,
Tags.CRYPTOGRAPHIC_USAGE_MASK,
Tags.LEASE_TIME,
Tags.USAGE_LIMITS,
Tags.STATE,
Tags.INITIAL_DATE,
Tags.ACTIVATION_DATE,
Tags.PROCESS_START_DATE,
Tags.PROTECT_STOP_DATE,
Tags.DEACTIVATION_DATE,
Tags.DESTROY_DATE,
Tags.COMPROMISE_OCCURRENCE_DATE,
Tags.COMPROMISE_DATE,
Tags.REVOCATION_REASON,
Tags.ARCHIVE_DATE,
Tags.OBJECT_GROUP,
Tags.LINK,
Tags.APPLICATION_SPECIFIC_INFORMATION,
Tags.CONTACT_INFORMATION,
Tags.LAST_CHANGE_DATE,
Tags.CUSTOM_ATTRIBUTE
]
kmip_1_1_attribute_tags = copy.deepcopy(kmip_1_0_attribute_tags) + [
Tags.CERTIFICATE_LENGTH,
Tags.X_509_CERTIFICATE_IDENTIFIER,
Tags.X_509_CERTIFICATE_SUBJECT,
Tags.X_509_CERTIFICATE_ISSUER,
Tags.DIGITAL_SIGNATURE_ALGORITHM,
Tags.FRESH
]
kmip_1_2_attribute_tags = copy.deepcopy(kmip_1_1_attribute_tags) + [
Tags.ALTERNATIVE_NAME,
Tags.KEY_VALUE_PRESENT,
Tags.KEY_VALUE_LOCATION,
Tags.ORIGINAL_CREATION_DATE
]
kmip_1_3_attribute_tags = copy.deepcopy(kmip_1_2_attribute_tags) + [
Tags.RANDOM_NUMBER_GENERATOR
]
kmip_1_4_attribute_tags = copy.deepcopy(kmip_1_3_attribute_tags) + [
Tags.PKCS12_FRIENDLY_NAME,
Tags.DESCRIPTION,
Tags.COMMENT,
Tags.SENSITIVE,
Tags.ALWAYS_SENSITIVE,
Tags.EXTRACTABLE,
Tags.NEVER_EXTRACTABLE
]
kmip_2_0_attribute_tags = copy.deepcopy(kmip_1_4_attribute_tags) + [
Tags.CERTIFICATE_SUBJECT_CN,
Tags.CERTIFICATE_SUBJECT_O,
Tags.CERTIFICATE_SUBJECT_OU,
Tags.CERTIFICATE_SUBJECT_EMAIL,
Tags.CERTIFICATE_SUBJECT_C,
Tags.CERTIFICATE_SUBJECT_ST,
Tags.CERTIFICATE_SUBJECT_L,
Tags.CERTIFICATE_SUBJECT_UID,
Tags.CERTIFICATE_SUBJECT_SERIAL_NUMBER,
Tags.CERTIFICATE_SUBJECT_TITLE,
Tags.CERTIFICATE_SUBJECT_DC,
Tags.CERTIFICATE_SUBJECT_DN_QUALIFIER,
Tags.CERTIFICATE_ISSUER_CN,
Tags.CERTIFICATE_ISSUER_O,
Tags.CERTIFICATE_ISSUER_OU,
Tags.CERTIFICATE_ISSUER_EMAIL,
Tags.CERTIFICATE_ISSUER_C,
Tags.CERTIFICATE_ISSUER_ST,
Tags.CERTIFICATE_ISSUER_L,
Tags.CERTIFICATE_ISSUER_UID,
Tags.CERTIFICATE_ISSUER_SERIAL_NUMBER,
Tags.CERTIFICATE_ISSUER_TITLE,
Tags.CERTIFICATE_ISSUER_DC,
Tags.CERTIFICATE_ISSUER_DN_QUALIFIER,
Tags.KEY_FORMAT_TYPE,
Tags.NIST_KEY_TYPE,
Tags.OPAQUE_DATA_TYPE,
Tags.PROTECTION_LEVEL,
Tags.PROTECTION_PERIOD,
Tags.PROTECTION_STORAGE_MASK,
Tags.QUANTUM_SAFE,
Tags.SHORT_UNIQUE_IDENTIFIER,
Tags.ATTRIBUTE
]
kmip_2_0_attribute_tags.remove(Tags.CERTIFICATE_IDENTIFIER)
kmip_2_0_attribute_tags.remove(Tags.CERTIFICATE_SUBJECT)
kmip_2_0_attribute_tags.remove(Tags.CERTIFICATE_ISSUER)
kmip_2_0_attribute_tags.remove(Tags.OPERATION_POLICY_NAME)
kmip_2_0_attribute_tags.remove(Tags.CUSTOM_ATTRIBUTE)
if kmip_version == KMIPVersion.KMIP_1_0:
return tag in kmip_1_0_attribute_tags
elif kmip_version == KMIPVersion.KMIP_1_1:
return tag in kmip_1_1_attribute_tags
elif kmip_version == KMIPVersion.KMIP_1_2:
return tag in kmip_1_2_attribute_tags
elif kmip_version == KMIPVersion.KMIP_1_3:
return tag in kmip_1_3_attribute_tags
elif kmip_version == KMIPVersion.KMIP_1_4:
return tag in kmip_1_4_attribute_tags
elif kmip_version == KMIPVersion.KMIP_2_0:
return tag in kmip_2_0_attribute_tags
else:
all_attribute_tags = set(
kmip_1_0_attribute_tags +
kmip_1_1_attribute_tags +
kmip_1_2_attribute_tags +
kmip_1_3_attribute_tags +
kmip_1_4_attribute_tags +
kmip_2_0_attribute_tags
)
return tag in all_attribute_tags
|
[
"A",
"utility",
"function",
"that",
"checks",
"if",
"the",
"tag",
"is",
"a",
"valid",
"attribute",
"tag",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/enums.py#L1913-L2053
|
[
"def",
"is_attribute",
"(",
"tag",
",",
"kmip_version",
"=",
"None",
")",
":",
"kmip_1_0_attribute_tags",
"=",
"[",
"Tags",
".",
"UNIQUE_IDENTIFIER",
",",
"Tags",
".",
"NAME",
",",
"Tags",
".",
"OBJECT_TYPE",
",",
"Tags",
".",
"CRYPTOGRAPHIC_ALGORITHM",
",",
"Tags",
".",
"CRYPTOGRAPHIC_LENGTH",
",",
"Tags",
".",
"CRYPTOGRAPHIC_PARAMETERS",
",",
"Tags",
".",
"CRYPTOGRAPHIC_DOMAIN_PARAMETERS",
",",
"Tags",
".",
"CERTIFICATE_TYPE",
",",
"Tags",
".",
"CERTIFICATE_IDENTIFIER",
",",
"Tags",
".",
"CERTIFICATE_SUBJECT",
",",
"Tags",
".",
"CERTIFICATE_ISSUER",
",",
"Tags",
".",
"DIGEST",
",",
"Tags",
".",
"OPERATION_POLICY_NAME",
",",
"Tags",
".",
"CRYPTOGRAPHIC_USAGE_MASK",
",",
"Tags",
".",
"LEASE_TIME",
",",
"Tags",
".",
"USAGE_LIMITS",
",",
"Tags",
".",
"STATE",
",",
"Tags",
".",
"INITIAL_DATE",
",",
"Tags",
".",
"ACTIVATION_DATE",
",",
"Tags",
".",
"PROCESS_START_DATE",
",",
"Tags",
".",
"PROTECT_STOP_DATE",
",",
"Tags",
".",
"DEACTIVATION_DATE",
",",
"Tags",
".",
"DESTROY_DATE",
",",
"Tags",
".",
"COMPROMISE_OCCURRENCE_DATE",
",",
"Tags",
".",
"COMPROMISE_DATE",
",",
"Tags",
".",
"REVOCATION_REASON",
",",
"Tags",
".",
"ARCHIVE_DATE",
",",
"Tags",
".",
"OBJECT_GROUP",
",",
"Tags",
".",
"LINK",
",",
"Tags",
".",
"APPLICATION_SPECIFIC_INFORMATION",
",",
"Tags",
".",
"CONTACT_INFORMATION",
",",
"Tags",
".",
"LAST_CHANGE_DATE",
",",
"Tags",
".",
"CUSTOM_ATTRIBUTE",
"]",
"kmip_1_1_attribute_tags",
"=",
"copy",
".",
"deepcopy",
"(",
"kmip_1_0_attribute_tags",
")",
"+",
"[",
"Tags",
".",
"CERTIFICATE_LENGTH",
",",
"Tags",
".",
"X_509_CERTIFICATE_IDENTIFIER",
",",
"Tags",
".",
"X_509_CERTIFICATE_SUBJECT",
",",
"Tags",
".",
"X_509_CERTIFICATE_ISSUER",
",",
"Tags",
".",
"DIGITAL_SIGNATURE_ALGORITHM",
",",
"Tags",
".",
"FRESH",
"]",
"kmip_1_2_attribute_tags",
"=",
"copy",
".",
"deepcopy",
"(",
"kmip_1_1_attribute_tags",
")",
"+",
"[",
"Tags",
".",
"ALTERNATIVE_NAME",
",",
"Tags",
".",
"KEY_VALUE_PRESENT",
",",
"Tags",
".",
"KEY_VALUE_LOCATION",
",",
"Tags",
".",
"ORIGINAL_CREATION_DATE",
"]",
"kmip_1_3_attribute_tags",
"=",
"copy",
".",
"deepcopy",
"(",
"kmip_1_2_attribute_tags",
")",
"+",
"[",
"Tags",
".",
"RANDOM_NUMBER_GENERATOR",
"]",
"kmip_1_4_attribute_tags",
"=",
"copy",
".",
"deepcopy",
"(",
"kmip_1_3_attribute_tags",
")",
"+",
"[",
"Tags",
".",
"PKCS12_FRIENDLY_NAME",
",",
"Tags",
".",
"DESCRIPTION",
",",
"Tags",
".",
"COMMENT",
",",
"Tags",
".",
"SENSITIVE",
",",
"Tags",
".",
"ALWAYS_SENSITIVE",
",",
"Tags",
".",
"EXTRACTABLE",
",",
"Tags",
".",
"NEVER_EXTRACTABLE",
"]",
"kmip_2_0_attribute_tags",
"=",
"copy",
".",
"deepcopy",
"(",
"kmip_1_4_attribute_tags",
")",
"+",
"[",
"Tags",
".",
"CERTIFICATE_SUBJECT_CN",
",",
"Tags",
".",
"CERTIFICATE_SUBJECT_O",
",",
"Tags",
".",
"CERTIFICATE_SUBJECT_OU",
",",
"Tags",
".",
"CERTIFICATE_SUBJECT_EMAIL",
",",
"Tags",
".",
"CERTIFICATE_SUBJECT_C",
",",
"Tags",
".",
"CERTIFICATE_SUBJECT_ST",
",",
"Tags",
".",
"CERTIFICATE_SUBJECT_L",
",",
"Tags",
".",
"CERTIFICATE_SUBJECT_UID",
",",
"Tags",
".",
"CERTIFICATE_SUBJECT_SERIAL_NUMBER",
",",
"Tags",
".",
"CERTIFICATE_SUBJECT_TITLE",
",",
"Tags",
".",
"CERTIFICATE_SUBJECT_DC",
",",
"Tags",
".",
"CERTIFICATE_SUBJECT_DN_QUALIFIER",
",",
"Tags",
".",
"CERTIFICATE_ISSUER_CN",
",",
"Tags",
".",
"CERTIFICATE_ISSUER_O",
",",
"Tags",
".",
"CERTIFICATE_ISSUER_OU",
",",
"Tags",
".",
"CERTIFICATE_ISSUER_EMAIL",
",",
"Tags",
".",
"CERTIFICATE_ISSUER_C",
",",
"Tags",
".",
"CERTIFICATE_ISSUER_ST",
",",
"Tags",
".",
"CERTIFICATE_ISSUER_L",
",",
"Tags",
".",
"CERTIFICATE_ISSUER_UID",
",",
"Tags",
".",
"CERTIFICATE_ISSUER_SERIAL_NUMBER",
",",
"Tags",
".",
"CERTIFICATE_ISSUER_TITLE",
",",
"Tags",
".",
"CERTIFICATE_ISSUER_DC",
",",
"Tags",
".",
"CERTIFICATE_ISSUER_DN_QUALIFIER",
",",
"Tags",
".",
"KEY_FORMAT_TYPE",
",",
"Tags",
".",
"NIST_KEY_TYPE",
",",
"Tags",
".",
"OPAQUE_DATA_TYPE",
",",
"Tags",
".",
"PROTECTION_LEVEL",
",",
"Tags",
".",
"PROTECTION_PERIOD",
",",
"Tags",
".",
"PROTECTION_STORAGE_MASK",
",",
"Tags",
".",
"QUANTUM_SAFE",
",",
"Tags",
".",
"SHORT_UNIQUE_IDENTIFIER",
",",
"Tags",
".",
"ATTRIBUTE",
"]",
"kmip_2_0_attribute_tags",
".",
"remove",
"(",
"Tags",
".",
"CERTIFICATE_IDENTIFIER",
")",
"kmip_2_0_attribute_tags",
".",
"remove",
"(",
"Tags",
".",
"CERTIFICATE_SUBJECT",
")",
"kmip_2_0_attribute_tags",
".",
"remove",
"(",
"Tags",
".",
"CERTIFICATE_ISSUER",
")",
"kmip_2_0_attribute_tags",
".",
"remove",
"(",
"Tags",
".",
"OPERATION_POLICY_NAME",
")",
"kmip_2_0_attribute_tags",
".",
"remove",
"(",
"Tags",
".",
"CUSTOM_ATTRIBUTE",
")",
"if",
"kmip_version",
"==",
"KMIPVersion",
".",
"KMIP_1_0",
":",
"return",
"tag",
"in",
"kmip_1_0_attribute_tags",
"elif",
"kmip_version",
"==",
"KMIPVersion",
".",
"KMIP_1_1",
":",
"return",
"tag",
"in",
"kmip_1_1_attribute_tags",
"elif",
"kmip_version",
"==",
"KMIPVersion",
".",
"KMIP_1_2",
":",
"return",
"tag",
"in",
"kmip_1_2_attribute_tags",
"elif",
"kmip_version",
"==",
"KMIPVersion",
".",
"KMIP_1_3",
":",
"return",
"tag",
"in",
"kmip_1_3_attribute_tags",
"elif",
"kmip_version",
"==",
"KMIPVersion",
".",
"KMIP_1_4",
":",
"return",
"tag",
"in",
"kmip_1_4_attribute_tags",
"elif",
"kmip_version",
"==",
"KMIPVersion",
".",
"KMIP_2_0",
":",
"return",
"tag",
"in",
"kmip_2_0_attribute_tags",
"else",
":",
"all_attribute_tags",
"=",
"set",
"(",
"kmip_1_0_attribute_tags",
"+",
"kmip_1_1_attribute_tags",
"+",
"kmip_1_2_attribute_tags",
"+",
"kmip_1_3_attribute_tags",
"+",
"kmip_1_4_attribute_tags",
"+",
"kmip_2_0_attribute_tags",
")",
"return",
"tag",
"in",
"all_attribute_tags"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
CreateKeyPairRequestPayload.read
|
Read the data encoding the CreateKeyPair request payload and decode it
into its constituent parts.
Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/messages/payloads/create_key_pair.py
|
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the CreateKeyPair request payload and decode it
into its constituent parts.
Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(CreateKeyPairRequestPayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self.is_tag_next(
enums.Tags.COMMON_TEMPLATE_ATTRIBUTE,
local_buffer
):
self._common_template_attribute = objects.TemplateAttribute(
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
)
self._common_template_attribute.read(
local_buffer,
kmip_version=kmip_version
)
else:
if self.is_tag_next(enums.Tags.COMMON_ATTRIBUTES, local_buffer):
attributes = objects.Attributes(
tag=enums.Tags.COMMON_ATTRIBUTES
)
attributes.read(local_buffer, kmip_version=kmip_version)
self._common_template_attribute = \
objects.convert_attributes_to_template_attribute(
attributes
)
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self.is_tag_next(
enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE,
local_buffer
):
self._private_key_template_attribute = \
objects.TemplateAttribute(
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
)
self._private_key_template_attribute.read(
local_buffer,
kmip_version=kmip_version
)
else:
if self.is_tag_next(
enums.Tags.PRIVATE_KEY_ATTRIBUTES,
local_buffer
):
attributes = objects.Attributes(
tag=enums.Tags.PRIVATE_KEY_ATTRIBUTES
)
attributes.read(local_buffer, kmip_version=kmip_version)
self._private_key_template_attribute = \
objects.convert_attributes_to_template_attribute(
attributes
)
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self.is_tag_next(
enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE,
local_buffer
):
self._public_key_template_attribute = \
objects.TemplateAttribute(
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
)
self._public_key_template_attribute.read(
local_buffer,
kmip_version=kmip_version
)
else:
if self.is_tag_next(
enums.Tags.PUBLIC_KEY_ATTRIBUTES,
local_buffer
):
attributes = objects.Attributes(
tag=enums.Tags.PUBLIC_KEY_ATTRIBUTES
)
attributes.read(local_buffer, kmip_version=kmip_version)
self._public_key_template_attribute = \
objects.convert_attributes_to_template_attribute(
attributes
)
self.is_oversized(local_buffer)
|
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the CreateKeyPair request payload and decode it
into its constituent parts.
Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(CreateKeyPairRequestPayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self.is_tag_next(
enums.Tags.COMMON_TEMPLATE_ATTRIBUTE,
local_buffer
):
self._common_template_attribute = objects.TemplateAttribute(
tag=enums.Tags.COMMON_TEMPLATE_ATTRIBUTE
)
self._common_template_attribute.read(
local_buffer,
kmip_version=kmip_version
)
else:
if self.is_tag_next(enums.Tags.COMMON_ATTRIBUTES, local_buffer):
attributes = objects.Attributes(
tag=enums.Tags.COMMON_ATTRIBUTES
)
attributes.read(local_buffer, kmip_version=kmip_version)
self._common_template_attribute = \
objects.convert_attributes_to_template_attribute(
attributes
)
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self.is_tag_next(
enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE,
local_buffer
):
self._private_key_template_attribute = \
objects.TemplateAttribute(
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
)
self._private_key_template_attribute.read(
local_buffer,
kmip_version=kmip_version
)
else:
if self.is_tag_next(
enums.Tags.PRIVATE_KEY_ATTRIBUTES,
local_buffer
):
attributes = objects.Attributes(
tag=enums.Tags.PRIVATE_KEY_ATTRIBUTES
)
attributes.read(local_buffer, kmip_version=kmip_version)
self._private_key_template_attribute = \
objects.convert_attributes_to_template_attribute(
attributes
)
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self.is_tag_next(
enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE,
local_buffer
):
self._public_key_template_attribute = \
objects.TemplateAttribute(
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
)
self._public_key_template_attribute.read(
local_buffer,
kmip_version=kmip_version
)
else:
if self.is_tag_next(
enums.Tags.PUBLIC_KEY_ATTRIBUTES,
local_buffer
):
attributes = objects.Attributes(
tag=enums.Tags.PUBLIC_KEY_ATTRIBUTES
)
attributes.read(local_buffer, kmip_version=kmip_version)
self._public_key_template_attribute = \
objects.convert_attributes_to_template_attribute(
attributes
)
self.is_oversized(local_buffer)
|
[
"Read",
"the",
"data",
"encoding",
"the",
"CreateKeyPair",
"request",
"payload",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/create_key_pair.py#L139-L234
|
[
"def",
"read",
"(",
"self",
",",
"input_buffer",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"CreateKeyPairRequestPayload",
",",
"self",
")",
".",
"read",
"(",
"input_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"local_buffer",
"=",
"utils",
".",
"BytearrayStream",
"(",
"input_buffer",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"if",
"kmip_version",
"<",
"enums",
".",
"KMIPVersion",
".",
"KMIP_2_0",
":",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"COMMON_TEMPLATE_ATTRIBUTE",
",",
"local_buffer",
")",
":",
"self",
".",
"_common_template_attribute",
"=",
"objects",
".",
"TemplateAttribute",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"COMMON_TEMPLATE_ATTRIBUTE",
")",
"self",
".",
"_common_template_attribute",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"COMMON_ATTRIBUTES",
",",
"local_buffer",
")",
":",
"attributes",
"=",
"objects",
".",
"Attributes",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"COMMON_ATTRIBUTES",
")",
"attributes",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"_common_template_attribute",
"=",
"objects",
".",
"convert_attributes_to_template_attribute",
"(",
"attributes",
")",
"if",
"kmip_version",
"<",
"enums",
".",
"KMIPVersion",
".",
"KMIP_2_0",
":",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"PRIVATE_KEY_TEMPLATE_ATTRIBUTE",
",",
"local_buffer",
")",
":",
"self",
".",
"_private_key_template_attribute",
"=",
"objects",
".",
"TemplateAttribute",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"PRIVATE_KEY_TEMPLATE_ATTRIBUTE",
")",
"self",
".",
"_private_key_template_attribute",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"PRIVATE_KEY_ATTRIBUTES",
",",
"local_buffer",
")",
":",
"attributes",
"=",
"objects",
".",
"Attributes",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"PRIVATE_KEY_ATTRIBUTES",
")",
"attributes",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"_private_key_template_attribute",
"=",
"objects",
".",
"convert_attributes_to_template_attribute",
"(",
"attributes",
")",
"if",
"kmip_version",
"<",
"enums",
".",
"KMIPVersion",
".",
"KMIP_2_0",
":",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"PUBLIC_KEY_TEMPLATE_ATTRIBUTE",
",",
"local_buffer",
")",
":",
"self",
".",
"_public_key_template_attribute",
"=",
"objects",
".",
"TemplateAttribute",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"PUBLIC_KEY_TEMPLATE_ATTRIBUTE",
")",
"self",
".",
"_public_key_template_attribute",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"PUBLIC_KEY_ATTRIBUTES",
",",
"local_buffer",
")",
":",
"attributes",
"=",
"objects",
".",
"Attributes",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"PUBLIC_KEY_ATTRIBUTES",
")",
"attributes",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"_public_key_template_attribute",
"=",
"objects",
".",
"convert_attributes_to_template_attribute",
"(",
"attributes",
")",
"self",
".",
"is_oversized",
"(",
"local_buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
CreateKeyPairRequestPayload.write
|
Write the data encoding the CreateKeyPair request payload to a buffer.
Args:
output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/messages/payloads/create_key_pair.py
|
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the CreateKeyPair request payload to a buffer.
Args:
output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_buffer = utils.BytearrayStream()
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self._common_template_attribute is not None:
self._common_template_attribute.write(
local_buffer,
kmip_version=kmip_version
)
else:
if self._common_template_attribute is not None:
attributes = objects.convert_template_attribute_to_attributes(
self._common_template_attribute
)
attributes.write(local_buffer, kmip_version=kmip_version)
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self._private_key_template_attribute is not None:
self._private_key_template_attribute.write(
local_buffer,
kmip_version=kmip_version
)
else:
if self._private_key_template_attribute is not None:
attributes = objects.convert_template_attribute_to_attributes(
self._private_key_template_attribute
)
attributes.write(local_buffer, kmip_version=kmip_version)
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self._public_key_template_attribute is not None:
self._public_key_template_attribute.write(
local_buffer,
kmip_version=kmip_version
)
else:
if self._public_key_template_attribute is not None:
attributes = objects.convert_template_attribute_to_attributes(
self._public_key_template_attribute
)
attributes.write(local_buffer, kmip_version=kmip_version)
self.length = local_buffer.length()
super(CreateKeyPairRequestPayload, self).write(
output_buffer,
kmip_version=kmip_version
)
output_buffer.write(local_buffer.buffer)
|
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the CreateKeyPair request payload to a buffer.
Args:
output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_buffer = utils.BytearrayStream()
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self._common_template_attribute is not None:
self._common_template_attribute.write(
local_buffer,
kmip_version=kmip_version
)
else:
if self._common_template_attribute is not None:
attributes = objects.convert_template_attribute_to_attributes(
self._common_template_attribute
)
attributes.write(local_buffer, kmip_version=kmip_version)
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self._private_key_template_attribute is not None:
self._private_key_template_attribute.write(
local_buffer,
kmip_version=kmip_version
)
else:
if self._private_key_template_attribute is not None:
attributes = objects.convert_template_attribute_to_attributes(
self._private_key_template_attribute
)
attributes.write(local_buffer, kmip_version=kmip_version)
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self._public_key_template_attribute is not None:
self._public_key_template_attribute.write(
local_buffer,
kmip_version=kmip_version
)
else:
if self._public_key_template_attribute is not None:
attributes = objects.convert_template_attribute_to_attributes(
self._public_key_template_attribute
)
attributes.write(local_buffer, kmip_version=kmip_version)
self.length = local_buffer.length()
super(CreateKeyPairRequestPayload, self).write(
output_buffer,
kmip_version=kmip_version
)
output_buffer.write(local_buffer.buffer)
|
[
"Write",
"the",
"data",
"encoding",
"the",
"CreateKeyPair",
"request",
"payload",
"to",
"a",
"buffer",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/create_key_pair.py#L236-L293
|
[
"def",
"write",
"(",
"self",
",",
"output_buffer",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"local_buffer",
"=",
"utils",
".",
"BytearrayStream",
"(",
")",
"if",
"kmip_version",
"<",
"enums",
".",
"KMIPVersion",
".",
"KMIP_2_0",
":",
"if",
"self",
".",
"_common_template_attribute",
"is",
"not",
"None",
":",
"self",
".",
"_common_template_attribute",
".",
"write",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"if",
"self",
".",
"_common_template_attribute",
"is",
"not",
"None",
":",
"attributes",
"=",
"objects",
".",
"convert_template_attribute_to_attributes",
"(",
"self",
".",
"_common_template_attribute",
")",
"attributes",
".",
"write",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"kmip_version",
"<",
"enums",
".",
"KMIPVersion",
".",
"KMIP_2_0",
":",
"if",
"self",
".",
"_private_key_template_attribute",
"is",
"not",
"None",
":",
"self",
".",
"_private_key_template_attribute",
".",
"write",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"if",
"self",
".",
"_private_key_template_attribute",
"is",
"not",
"None",
":",
"attributes",
"=",
"objects",
".",
"convert_template_attribute_to_attributes",
"(",
"self",
".",
"_private_key_template_attribute",
")",
"attributes",
".",
"write",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"kmip_version",
"<",
"enums",
".",
"KMIPVersion",
".",
"KMIP_2_0",
":",
"if",
"self",
".",
"_public_key_template_attribute",
"is",
"not",
"None",
":",
"self",
".",
"_public_key_template_attribute",
".",
"write",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"if",
"self",
".",
"_public_key_template_attribute",
"is",
"not",
"None",
":",
"attributes",
"=",
"objects",
".",
"convert_template_attribute_to_attributes",
"(",
"self",
".",
"_public_key_template_attribute",
")",
"attributes",
".",
"write",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"length",
"=",
"local_buffer",
".",
"length",
"(",
")",
"super",
"(",
"CreateKeyPairRequestPayload",
",",
"self",
")",
".",
"write",
"(",
"output_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"output_buffer",
".",
"write",
"(",
"local_buffer",
".",
"buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
CreateKeyPairResponsePayload.read
|
Read the data encoding the CreateKeyPair response payload and decode it
into its constituent parts.
Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidKmipEncoding: Raised if the private key unique identifier or
the public key unique identifier is missing from the encoded
payload.
|
kmip/core/messages/payloads/create_key_pair.py
|
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the CreateKeyPair response payload and decode it
into its constituent parts.
Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidKmipEncoding: Raised if the private key unique identifier or
the public key unique identifier is missing from the encoded
payload.
"""
super(CreateKeyPairResponsePayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(
enums.Tags.PRIVATE_KEY_UNIQUE_IDENTIFIER,
local_buffer
):
self._private_key_unique_identifier = primitives.TextString(
tag=enums.Tags.PRIVATE_KEY_UNIQUE_IDENTIFIER
)
self._private_key_unique_identifier.read(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidKmipEncoding(
"The CreateKeyPair response payload encoding is missing the "
"private key unique identifier."
)
if self.is_tag_next(
enums.Tags.PUBLIC_KEY_UNIQUE_IDENTIFIER,
local_buffer
):
self._public_key_unique_identifier = primitives.TextString(
tag=enums.Tags.PUBLIC_KEY_UNIQUE_IDENTIFIER
)
self._public_key_unique_identifier.read(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidKmipEncoding(
"The CreateKeyPair response payload encoding is missing the "
"public key unique identifier."
)
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self.is_tag_next(
enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE,
local_buffer
):
self._private_key_template_attribute = \
objects.TemplateAttribute(
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
)
self._private_key_template_attribute.read(
local_buffer,
kmip_version=kmip_version
)
if self.is_tag_next(
enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE,
local_buffer
):
self._public_key_template_attribute = \
objects.TemplateAttribute(
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
)
self._public_key_template_attribute.read(
local_buffer,
kmip_version=kmip_version
)
self.is_oversized(local_buffer)
|
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the CreateKeyPair response payload and decode it
into its constituent parts.
Args:
input_buffer (stream): A data buffer containing encoded object
data, supporting a read method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidKmipEncoding: Raised if the private key unique identifier or
the public key unique identifier is missing from the encoded
payload.
"""
super(CreateKeyPairResponsePayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(
enums.Tags.PRIVATE_KEY_UNIQUE_IDENTIFIER,
local_buffer
):
self._private_key_unique_identifier = primitives.TextString(
tag=enums.Tags.PRIVATE_KEY_UNIQUE_IDENTIFIER
)
self._private_key_unique_identifier.read(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidKmipEncoding(
"The CreateKeyPair response payload encoding is missing the "
"private key unique identifier."
)
if self.is_tag_next(
enums.Tags.PUBLIC_KEY_UNIQUE_IDENTIFIER,
local_buffer
):
self._public_key_unique_identifier = primitives.TextString(
tag=enums.Tags.PUBLIC_KEY_UNIQUE_IDENTIFIER
)
self._public_key_unique_identifier.read(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidKmipEncoding(
"The CreateKeyPair response payload encoding is missing the "
"public key unique identifier."
)
if kmip_version < enums.KMIPVersion.KMIP_2_0:
if self.is_tag_next(
enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE,
local_buffer
):
self._private_key_template_attribute = \
objects.TemplateAttribute(
tag=enums.Tags.PRIVATE_KEY_TEMPLATE_ATTRIBUTE
)
self._private_key_template_attribute.read(
local_buffer,
kmip_version=kmip_version
)
if self.is_tag_next(
enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE,
local_buffer
):
self._public_key_template_attribute = \
objects.TemplateAttribute(
tag=enums.Tags.PUBLIC_KEY_TEMPLATE_ATTRIBUTE
)
self._public_key_template_attribute.read(
local_buffer,
kmip_version=kmip_version
)
self.is_oversized(local_buffer)
|
[
"Read",
"the",
"data",
"encoding",
"the",
"CreateKeyPair",
"response",
"payload",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/create_key_pair.py#L484-L568
|
[
"def",
"read",
"(",
"self",
",",
"input_buffer",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"CreateKeyPairResponsePayload",
",",
"self",
")",
".",
"read",
"(",
"input_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"local_buffer",
"=",
"utils",
".",
"BytearrayStream",
"(",
"input_buffer",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"PRIVATE_KEY_UNIQUE_IDENTIFIER",
",",
"local_buffer",
")",
":",
"self",
".",
"_private_key_unique_identifier",
"=",
"primitives",
".",
"TextString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"PRIVATE_KEY_UNIQUE_IDENTIFIER",
")",
"self",
".",
"_private_key_unique_identifier",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"exceptions",
".",
"InvalidKmipEncoding",
"(",
"\"The CreateKeyPair response payload encoding is missing the \"",
"\"private key unique identifier.\"",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"PUBLIC_KEY_UNIQUE_IDENTIFIER",
",",
"local_buffer",
")",
":",
"self",
".",
"_public_key_unique_identifier",
"=",
"primitives",
".",
"TextString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"PUBLIC_KEY_UNIQUE_IDENTIFIER",
")",
"self",
".",
"_public_key_unique_identifier",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"exceptions",
".",
"InvalidKmipEncoding",
"(",
"\"The CreateKeyPair response payload encoding is missing the \"",
"\"public key unique identifier.\"",
")",
"if",
"kmip_version",
"<",
"enums",
".",
"KMIPVersion",
".",
"KMIP_2_0",
":",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"PRIVATE_KEY_TEMPLATE_ATTRIBUTE",
",",
"local_buffer",
")",
":",
"self",
".",
"_private_key_template_attribute",
"=",
"objects",
".",
"TemplateAttribute",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"PRIVATE_KEY_TEMPLATE_ATTRIBUTE",
")",
"self",
".",
"_private_key_template_attribute",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"PUBLIC_KEY_TEMPLATE_ATTRIBUTE",
",",
"local_buffer",
")",
":",
"self",
".",
"_public_key_template_attribute",
"=",
"objects",
".",
"TemplateAttribute",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"PUBLIC_KEY_TEMPLATE_ATTRIBUTE",
")",
"self",
".",
"_public_key_template_attribute",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"is_oversized",
"(",
"local_buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
CreateKeyPairResponsePayload.write
|
Write the data encoding the CreateKeyPair response payload to a buffer.
Args:
output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidField: Raised if the private key unique identifier or the
public key unique identifier is not defined.
|
kmip/core/messages/payloads/create_key_pair.py
|
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the CreateKeyPair response payload to a buffer.
Args:
output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidField: Raised if the private key unique identifier or the
public key unique identifier is not defined.
"""
local_buffer = utils.BytearrayStream()
if self._private_key_unique_identifier:
self._private_key_unique_identifier.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
"The CreateKeyPair response payload is missing the private "
"key unique identifier field."
)
if self._public_key_unique_identifier:
self._public_key_unique_identifier.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
"The CreateKeyPair response payload is missing the public "
"key unique identifier field."
)
if self._private_key_template_attribute:
self._private_key_template_attribute.write(
local_buffer,
kmip_version=kmip_version
)
if self._public_key_template_attribute:
self._public_key_template_attribute.write(
local_buffer,
kmip_version=kmip_version
)
self.length = local_buffer.length()
super(CreateKeyPairResponsePayload, self).write(
output_buffer,
kmip_version=kmip_version
)
output_buffer.write(local_buffer.buffer)
|
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the CreateKeyPair response payload to a buffer.
Args:
output_buffer (stream): A data buffer in which to encode object
data, supporting a write method.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidField: Raised if the private key unique identifier or the
public key unique identifier is not defined.
"""
local_buffer = utils.BytearrayStream()
if self._private_key_unique_identifier:
self._private_key_unique_identifier.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
"The CreateKeyPair response payload is missing the private "
"key unique identifier field."
)
if self._public_key_unique_identifier:
self._public_key_unique_identifier.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
"The CreateKeyPair response payload is missing the public "
"key unique identifier field."
)
if self._private_key_template_attribute:
self._private_key_template_attribute.write(
local_buffer,
kmip_version=kmip_version
)
if self._public_key_template_attribute:
self._public_key_template_attribute.write(
local_buffer,
kmip_version=kmip_version
)
self.length = local_buffer.length()
super(CreateKeyPairResponsePayload, self).write(
output_buffer,
kmip_version=kmip_version
)
output_buffer.write(local_buffer.buffer)
|
[
"Write",
"the",
"data",
"encoding",
"the",
"CreateKeyPair",
"response",
"payload",
"to",
"a",
"buffer",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/create_key_pair.py#L570-L626
|
[
"def",
"write",
"(",
"self",
",",
"output_buffer",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"local_buffer",
"=",
"utils",
".",
"BytearrayStream",
"(",
")",
"if",
"self",
".",
"_private_key_unique_identifier",
":",
"self",
".",
"_private_key_unique_identifier",
".",
"write",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"exceptions",
".",
"InvalidField",
"(",
"\"The CreateKeyPair response payload is missing the private \"",
"\"key unique identifier field.\"",
")",
"if",
"self",
".",
"_public_key_unique_identifier",
":",
"self",
".",
"_public_key_unique_identifier",
".",
"write",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"exceptions",
".",
"InvalidField",
"(",
"\"The CreateKeyPair response payload is missing the public \"",
"\"key unique identifier field.\"",
")",
"if",
"self",
".",
"_private_key_template_attribute",
":",
"self",
".",
"_private_key_template_attribute",
".",
"write",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"if",
"self",
".",
"_public_key_template_attribute",
":",
"self",
".",
"_public_key_template_attribute",
".",
"write",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"length",
"=",
"local_buffer",
".",
"length",
"(",
")",
"super",
"(",
"CreateKeyPairResponsePayload",
",",
"self",
")",
".",
"write",
"(",
"output_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"output_buffer",
".",
"write",
"(",
"local_buffer",
".",
"buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
GetAttributeListRequestPayload.read
|
Read the data encoding the GetAttributeList request payload and decode
it into its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/messages/payloads/get_attribute_list.py
|
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the GetAttributeList request payload and decode
it into its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(GetAttributeListRequestPayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_buffer,
kmip_version=kmip_version
)
else:
self._unique_identifier = None
self.is_oversized(local_buffer)
|
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the GetAttributeList request payload and decode
it into its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
"""
super(GetAttributeListRequestPayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_buffer,
kmip_version=kmip_version
)
else:
self._unique_identifier = None
self.is_oversized(local_buffer)
|
[
"Read",
"the",
"data",
"encoding",
"the",
"GetAttributeList",
"request",
"payload",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/get_attribute_list.py#L73-L103
|
[
"def",
"read",
"(",
"self",
",",
"input_buffer",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"GetAttributeListRequestPayload",
",",
"self",
")",
".",
"read",
"(",
"input_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"local_buffer",
"=",
"utils",
".",
"BytearrayStream",
"(",
"input_buffer",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"UNIQUE_IDENTIFIER",
",",
"local_buffer",
")",
":",
"self",
".",
"_unique_identifier",
"=",
"primitives",
".",
"TextString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"UNIQUE_IDENTIFIER",
")",
"self",
".",
"_unique_identifier",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"self",
".",
"_unique_identifier",
"=",
"None",
"self",
".",
"is_oversized",
"(",
"local_buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
GetAttributeListRequestPayload.write
|
Write the data encoding the GetAttributeList request payload to a
stream.
Args:
output_buffer (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
|
kmip/core/messages/payloads/get_attribute_list.py
|
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the GetAttributeList request payload to a
stream.
Args:
output_buffer (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_buffer = utils.BytearrayStream()
if self._unique_identifier:
self._unique_identifier.write(
local_buffer,
kmip_version=kmip_version
)
self.length = local_buffer.length()
super(GetAttributeListRequestPayload, self).write(
output_buffer,
kmip_version=kmip_version
)
output_buffer.write(local_buffer.buffer)
|
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the GetAttributeList request payload to a
stream.
Args:
output_buffer (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
"""
local_buffer = utils.BytearrayStream()
if self._unique_identifier:
self._unique_identifier.write(
local_buffer,
kmip_version=kmip_version
)
self.length = local_buffer.length()
super(GetAttributeListRequestPayload, self).write(
output_buffer,
kmip_version=kmip_version
)
output_buffer.write(local_buffer.buffer)
|
[
"Write",
"the",
"data",
"encoding",
"the",
"GetAttributeList",
"request",
"payload",
"to",
"a",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/get_attribute_list.py#L105-L131
|
[
"def",
"write",
"(",
"self",
",",
"output_buffer",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"local_buffer",
"=",
"utils",
".",
"BytearrayStream",
"(",
")",
"if",
"self",
".",
"_unique_identifier",
":",
"self",
".",
"_unique_identifier",
".",
"write",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"self",
".",
"length",
"=",
"local_buffer",
".",
"length",
"(",
")",
"super",
"(",
"GetAttributeListRequestPayload",
",",
"self",
")",
".",
"write",
"(",
"output_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"output_buffer",
".",
"write",
"(",
"local_buffer",
".",
"buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
GetAttributeListResponsePayload.read
|
Read the data encoding the GetAttributeList response payload and
decode it into its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidKmipEncoding: Raised if the unique identifier or attribute
names are missing from the encoded payload.
|
kmip/core/messages/payloads/get_attribute_list.py
|
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the GetAttributeList response payload and
decode it into its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidKmipEncoding: Raised if the unique identifier or attribute
names are missing from the encoded payload.
"""
super(GetAttributeListResponsePayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidKmipEncoding(
"The GetAttributeList response payload encoding is missing "
"the unique identifier."
)
names = list()
if kmip_version < enums.KMIPVersion.KMIP_2_0:
while self.is_tag_next(enums.Tags.ATTRIBUTE_NAME, local_buffer):
name = primitives.TextString(tag=enums.Tags.ATTRIBUTE_NAME)
name.read(local_buffer, kmip_version=kmip_version)
names.append(name)
if len(names) == 0:
raise exceptions.InvalidKmipEncoding(
"The GetAttributeList response payload encoding is "
"missing the attribute names."
)
self._attribute_names = names
else:
while self.is_tag_next(
enums.Tags.ATTRIBUTE_REFERENCE,
local_buffer
):
if self.is_type_next(enums.Types.STRUCTURE, local_buffer):
reference = objects.AttributeReference()
reference.read(local_buffer, kmip_version=kmip_version)
names.append(
primitives.TextString(
value=reference.attribute_name,
tag=enums.Tags.ATTRIBUTE_NAME
)
)
elif self.is_type_next(enums.Types.ENUMERATION, local_buffer):
reference = primitives.Enumeration(
enums.Tags,
tag=enums.Tags.ATTRIBUTE_REFERENCE
)
reference.read(local_buffer, kmip_version=kmip_version)
name = enums.convert_attribute_tag_to_name(reference.value)
names.append(
primitives.TextString(
value=name,
tag=enums.Tags.ATTRIBUTE_NAME
)
)
else:
raise exceptions.InvalidKmipEncoding(
"The GetAttributeList response payload encoding "
"contains an invalid AttributeReference type."
)
self._attribute_names = names
self.is_oversized(local_buffer)
|
def read(self, input_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Read the data encoding the GetAttributeList response payload and
decode it into its constituent parts.
Args:
input_buffer (stream): A data stream containing encoded object
data, supporting a read method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be decoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidKmipEncoding: Raised if the unique identifier or attribute
names are missing from the encoded payload.
"""
super(GetAttributeListResponsePayload, self).read(
input_buffer,
kmip_version=kmip_version
)
local_buffer = utils.BytearrayStream(input_buffer.read(self.length))
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_buffer):
self._unique_identifier = primitives.TextString(
tag=enums.Tags.UNIQUE_IDENTIFIER
)
self._unique_identifier.read(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidKmipEncoding(
"The GetAttributeList response payload encoding is missing "
"the unique identifier."
)
names = list()
if kmip_version < enums.KMIPVersion.KMIP_2_0:
while self.is_tag_next(enums.Tags.ATTRIBUTE_NAME, local_buffer):
name = primitives.TextString(tag=enums.Tags.ATTRIBUTE_NAME)
name.read(local_buffer, kmip_version=kmip_version)
names.append(name)
if len(names) == 0:
raise exceptions.InvalidKmipEncoding(
"The GetAttributeList response payload encoding is "
"missing the attribute names."
)
self._attribute_names = names
else:
while self.is_tag_next(
enums.Tags.ATTRIBUTE_REFERENCE,
local_buffer
):
if self.is_type_next(enums.Types.STRUCTURE, local_buffer):
reference = objects.AttributeReference()
reference.read(local_buffer, kmip_version=kmip_version)
names.append(
primitives.TextString(
value=reference.attribute_name,
tag=enums.Tags.ATTRIBUTE_NAME
)
)
elif self.is_type_next(enums.Types.ENUMERATION, local_buffer):
reference = primitives.Enumeration(
enums.Tags,
tag=enums.Tags.ATTRIBUTE_REFERENCE
)
reference.read(local_buffer, kmip_version=kmip_version)
name = enums.convert_attribute_tag_to_name(reference.value)
names.append(
primitives.TextString(
value=name,
tag=enums.Tags.ATTRIBUTE_NAME
)
)
else:
raise exceptions.InvalidKmipEncoding(
"The GetAttributeList response payload encoding "
"contains an invalid AttributeReference type."
)
self._attribute_names = names
self.is_oversized(local_buffer)
|
[
"Read",
"the",
"data",
"encoding",
"the",
"GetAttributeList",
"response",
"payload",
"and",
"decode",
"it",
"into",
"its",
"constituent",
"parts",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/get_attribute_list.py#L250-L333
|
[
"def",
"read",
"(",
"self",
",",
"input_buffer",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"super",
"(",
"GetAttributeListResponsePayload",
",",
"self",
")",
".",
"read",
"(",
"input_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"local_buffer",
"=",
"utils",
".",
"BytearrayStream",
"(",
"input_buffer",
".",
"read",
"(",
"self",
".",
"length",
")",
")",
"if",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"UNIQUE_IDENTIFIER",
",",
"local_buffer",
")",
":",
"self",
".",
"_unique_identifier",
"=",
"primitives",
".",
"TextString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"UNIQUE_IDENTIFIER",
")",
"self",
".",
"_unique_identifier",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"exceptions",
".",
"InvalidKmipEncoding",
"(",
"\"The GetAttributeList response payload encoding is missing \"",
"\"the unique identifier.\"",
")",
"names",
"=",
"list",
"(",
")",
"if",
"kmip_version",
"<",
"enums",
".",
"KMIPVersion",
".",
"KMIP_2_0",
":",
"while",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"ATTRIBUTE_NAME",
",",
"local_buffer",
")",
":",
"name",
"=",
"primitives",
".",
"TextString",
"(",
"tag",
"=",
"enums",
".",
"Tags",
".",
"ATTRIBUTE_NAME",
")",
"name",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"names",
".",
"append",
"(",
"name",
")",
"if",
"len",
"(",
"names",
")",
"==",
"0",
":",
"raise",
"exceptions",
".",
"InvalidKmipEncoding",
"(",
"\"The GetAttributeList response payload encoding is \"",
"\"missing the attribute names.\"",
")",
"self",
".",
"_attribute_names",
"=",
"names",
"else",
":",
"while",
"self",
".",
"is_tag_next",
"(",
"enums",
".",
"Tags",
".",
"ATTRIBUTE_REFERENCE",
",",
"local_buffer",
")",
":",
"if",
"self",
".",
"is_type_next",
"(",
"enums",
".",
"Types",
".",
"STRUCTURE",
",",
"local_buffer",
")",
":",
"reference",
"=",
"objects",
".",
"AttributeReference",
"(",
")",
"reference",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"names",
".",
"append",
"(",
"primitives",
".",
"TextString",
"(",
"value",
"=",
"reference",
".",
"attribute_name",
",",
"tag",
"=",
"enums",
".",
"Tags",
".",
"ATTRIBUTE_NAME",
")",
")",
"elif",
"self",
".",
"is_type_next",
"(",
"enums",
".",
"Types",
".",
"ENUMERATION",
",",
"local_buffer",
")",
":",
"reference",
"=",
"primitives",
".",
"Enumeration",
"(",
"enums",
".",
"Tags",
",",
"tag",
"=",
"enums",
".",
"Tags",
".",
"ATTRIBUTE_REFERENCE",
")",
"reference",
".",
"read",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"name",
"=",
"enums",
".",
"convert_attribute_tag_to_name",
"(",
"reference",
".",
"value",
")",
"names",
".",
"append",
"(",
"primitives",
".",
"TextString",
"(",
"value",
"=",
"name",
",",
"tag",
"=",
"enums",
".",
"Tags",
".",
"ATTRIBUTE_NAME",
")",
")",
"else",
":",
"raise",
"exceptions",
".",
"InvalidKmipEncoding",
"(",
"\"The GetAttributeList response payload encoding \"",
"\"contains an invalid AttributeReference type.\"",
")",
"self",
".",
"_attribute_names",
"=",
"names",
"self",
".",
"is_oversized",
"(",
"local_buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
GetAttributeListResponsePayload.write
|
Write the data encoding the GetAttributeList response payload to a
stream.
Args:
output_buffer (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidField: Raised if the unique identifier or attribute name
are not defined.
|
kmip/core/messages/payloads/get_attribute_list.py
|
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the GetAttributeList response payload to a
stream.
Args:
output_buffer (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidField: Raised if the unique identifier or attribute name
are not defined.
"""
local_buffer = utils.BytearrayStream()
if self._unique_identifier:
self._unique_identifier.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
"The GetAttributeList response payload is missing the unique "
"identifier field."
)
if self._attribute_names:
if kmip_version < enums.KMIPVersion.KMIP_2_0:
for attribute_name in self._attribute_names:
attribute_name.write(
local_buffer,
kmip_version=kmip_version
)
else:
# NOTE (ph) This approach simplifies backwards compatible
# issues but limits easy support for Attribute
# Reference structures going forward, specifically
# limiting the use of VendorIdentification for
# custom attributes. If custom attributes need to
# be retrieved using the GetAttributeList operation
# for KMIP 2.0 applications this code will need to
# change.
for attribute_name in self._attribute_names:
t = enums.convert_attribute_name_to_tag(
attribute_name.value
)
e = primitives.Enumeration(
enums.Tags,
value=t,
tag=enums.Tags.ATTRIBUTE_REFERENCE
)
e.write(local_buffer, kmip_version=kmip_version)
else:
raise exceptions.InvalidField(
"The GetAttributeList response payload is missing the "
"attribute names field."
)
self.length = local_buffer.length()
super(GetAttributeListResponsePayload, self).write(
output_buffer,
kmip_version=kmip_version
)
output_buffer.write(local_buffer.buffer)
|
def write(self, output_buffer, kmip_version=enums.KMIPVersion.KMIP_1_0):
"""
Write the data encoding the GetAttributeList response payload to a
stream.
Args:
output_buffer (stream): A data stream in which to encode object
data, supporting a write method; usually a BytearrayStream
object.
kmip_version (KMIPVersion): An enumeration defining the KMIP
version with which the object will be encoded. Optional,
defaults to KMIP 1.0.
Raises:
InvalidField: Raised if the unique identifier or attribute name
are not defined.
"""
local_buffer = utils.BytearrayStream()
if self._unique_identifier:
self._unique_identifier.write(
local_buffer,
kmip_version=kmip_version
)
else:
raise exceptions.InvalidField(
"The GetAttributeList response payload is missing the unique "
"identifier field."
)
if self._attribute_names:
if kmip_version < enums.KMIPVersion.KMIP_2_0:
for attribute_name in self._attribute_names:
attribute_name.write(
local_buffer,
kmip_version=kmip_version
)
else:
# NOTE (ph) This approach simplifies backwards compatible
# issues but limits easy support for Attribute
# Reference structures going forward, specifically
# limiting the use of VendorIdentification for
# custom attributes. If custom attributes need to
# be retrieved using the GetAttributeList operation
# for KMIP 2.0 applications this code will need to
# change.
for attribute_name in self._attribute_names:
t = enums.convert_attribute_name_to_tag(
attribute_name.value
)
e = primitives.Enumeration(
enums.Tags,
value=t,
tag=enums.Tags.ATTRIBUTE_REFERENCE
)
e.write(local_buffer, kmip_version=kmip_version)
else:
raise exceptions.InvalidField(
"The GetAttributeList response payload is missing the "
"attribute names field."
)
self.length = local_buffer.length()
super(GetAttributeListResponsePayload, self).write(
output_buffer,
kmip_version=kmip_version
)
output_buffer.write(local_buffer.buffer)
|
[
"Write",
"the",
"data",
"encoding",
"the",
"GetAttributeList",
"response",
"payload",
"to",
"a",
"stream",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/core/messages/payloads/get_attribute_list.py#L335-L403
|
[
"def",
"write",
"(",
"self",
",",
"output_buffer",
",",
"kmip_version",
"=",
"enums",
".",
"KMIPVersion",
".",
"KMIP_1_0",
")",
":",
"local_buffer",
"=",
"utils",
".",
"BytearrayStream",
"(",
")",
"if",
"self",
".",
"_unique_identifier",
":",
"self",
".",
"_unique_identifier",
".",
"write",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"exceptions",
".",
"InvalidField",
"(",
"\"The GetAttributeList response payload is missing the unique \"",
"\"identifier field.\"",
")",
"if",
"self",
".",
"_attribute_names",
":",
"if",
"kmip_version",
"<",
"enums",
".",
"KMIPVersion",
".",
"KMIP_2_0",
":",
"for",
"attribute_name",
"in",
"self",
".",
"_attribute_names",
":",
"attribute_name",
".",
"write",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"# NOTE (ph) This approach simplifies backwards compatible",
"# issues but limits easy support for Attribute",
"# Reference structures going forward, specifically",
"# limiting the use of VendorIdentification for",
"# custom attributes. If custom attributes need to",
"# be retrieved using the GetAttributeList operation",
"# for KMIP 2.0 applications this code will need to",
"# change.",
"for",
"attribute_name",
"in",
"self",
".",
"_attribute_names",
":",
"t",
"=",
"enums",
".",
"convert_attribute_name_to_tag",
"(",
"attribute_name",
".",
"value",
")",
"e",
"=",
"primitives",
".",
"Enumeration",
"(",
"enums",
".",
"Tags",
",",
"value",
"=",
"t",
",",
"tag",
"=",
"enums",
".",
"Tags",
".",
"ATTRIBUTE_REFERENCE",
")",
"e",
".",
"write",
"(",
"local_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"else",
":",
"raise",
"exceptions",
".",
"InvalidField",
"(",
"\"The GetAttributeList response payload is missing the \"",
"\"attribute names field.\"",
")",
"self",
".",
"length",
"=",
"local_buffer",
".",
"length",
"(",
")",
"super",
"(",
"GetAttributeListResponsePayload",
",",
"self",
")",
".",
"write",
"(",
"output_buffer",
",",
"kmip_version",
"=",
"kmip_version",
")",
"output_buffer",
".",
"write",
"(",
"local_buffer",
".",
"buffer",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
get_json_files
|
Scan the provided policy directory for all JSON policy files.
|
kmip/services/server/monitor.py
|
def get_json_files(p):
"""
Scan the provided policy directory for all JSON policy files.
"""
f = [os.path.join(p, x) for x in os.listdir(p) if x.endswith(".json")]
return sorted(f)
|
def get_json_files(p):
"""
Scan the provided policy directory for all JSON policy files.
"""
f = [os.path.join(p, x) for x in os.listdir(p) if x.endswith(".json")]
return sorted(f)
|
[
"Scan",
"the",
"provided",
"policy",
"directory",
"for",
"all",
"JSON",
"policy",
"files",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/monitor.py#L25-L30
|
[
"def",
"get_json_files",
"(",
"p",
")",
":",
"f",
"=",
"[",
"os",
".",
"path",
".",
"join",
"(",
"p",
",",
"x",
")",
"for",
"x",
"in",
"os",
".",
"listdir",
"(",
"p",
")",
"if",
"x",
".",
"endswith",
"(",
"\".json\"",
")",
"]",
"return",
"sorted",
"(",
"f",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
PolicyDirectoryMonitor.scan_policies
|
Scan the policy directory for policy data.
|
kmip/services/server/monitor.py
|
def scan_policies(self):
"""
Scan the policy directory for policy data.
"""
policy_files = get_json_files(self.policy_directory)
for f in set(policy_files) - set(self.policy_files):
self.file_timestamps[f] = 0
for f in set(self.policy_files) - set(policy_files):
self.logger.info("Removing policies for file: {}".format(f))
self.file_timestamps.pop(f, None)
for p in self.policy_cache.keys():
self.disassociate_policy_and_file(p, f)
for p in [k for k, v in self.policy_map.items() if v == f]:
self.restore_or_delete_policy(p)
self.policy_files = policy_files
for f in sorted(self.file_timestamps.keys()):
t = os.path.getmtime(f)
if t > self.file_timestamps[f]:
self.logger.info("Loading policies for file: {}".format(f))
self.file_timestamps[f] = t
old_p = [k for k, v in self.policy_map.items() if v == f]
try:
new_p = operation_policy.read_policy_from_file(f)
except ValueError:
self.logger.error("Failure loading file: {}".format(f))
self.logger.debug("", exc_info=True)
continue
for p in new_p.keys():
self.logger.info("Loading policy: {}".format(p))
if p in self.reserved_policies:
self.logger.warning(
"Policy '{}' overwrites a reserved policy and "
"will be thrown out.".format(p)
)
continue
if p in sorted(self.policy_store.keys()):
self.logger.debug(
"Policy '{}' overwrites an existing "
"policy.".format(p)
)
if f != self.policy_map.get(p):
self.policy_cache.get(p).append(
(
time.time(),
self.policy_map.get(p),
self.policy_store.get(p)
)
)
else:
self.policy_cache[p] = []
self.policy_store[p] = new_p.get(p)
self.policy_map[p] = f
for p in set(old_p) - set(new_p.keys()):
self.disassociate_policy_and_file(p, f)
self.restore_or_delete_policy(p)
|
def scan_policies(self):
"""
Scan the policy directory for policy data.
"""
policy_files = get_json_files(self.policy_directory)
for f in set(policy_files) - set(self.policy_files):
self.file_timestamps[f] = 0
for f in set(self.policy_files) - set(policy_files):
self.logger.info("Removing policies for file: {}".format(f))
self.file_timestamps.pop(f, None)
for p in self.policy_cache.keys():
self.disassociate_policy_and_file(p, f)
for p in [k for k, v in self.policy_map.items() if v == f]:
self.restore_or_delete_policy(p)
self.policy_files = policy_files
for f in sorted(self.file_timestamps.keys()):
t = os.path.getmtime(f)
if t > self.file_timestamps[f]:
self.logger.info("Loading policies for file: {}".format(f))
self.file_timestamps[f] = t
old_p = [k for k, v in self.policy_map.items() if v == f]
try:
new_p = operation_policy.read_policy_from_file(f)
except ValueError:
self.logger.error("Failure loading file: {}".format(f))
self.logger.debug("", exc_info=True)
continue
for p in new_p.keys():
self.logger.info("Loading policy: {}".format(p))
if p in self.reserved_policies:
self.logger.warning(
"Policy '{}' overwrites a reserved policy and "
"will be thrown out.".format(p)
)
continue
if p in sorted(self.policy_store.keys()):
self.logger.debug(
"Policy '{}' overwrites an existing "
"policy.".format(p)
)
if f != self.policy_map.get(p):
self.policy_cache.get(p).append(
(
time.time(),
self.policy_map.get(p),
self.policy_store.get(p)
)
)
else:
self.policy_cache[p] = []
self.policy_store[p] = new_p.get(p)
self.policy_map[p] = f
for p in set(old_p) - set(new_p.keys()):
self.disassociate_policy_and_file(p, f)
self.restore_or_delete_policy(p)
|
[
"Scan",
"the",
"policy",
"directory",
"for",
"policy",
"data",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/monitor.py#L78-L133
|
[
"def",
"scan_policies",
"(",
"self",
")",
":",
"policy_files",
"=",
"get_json_files",
"(",
"self",
".",
"policy_directory",
")",
"for",
"f",
"in",
"set",
"(",
"policy_files",
")",
"-",
"set",
"(",
"self",
".",
"policy_files",
")",
":",
"self",
".",
"file_timestamps",
"[",
"f",
"]",
"=",
"0",
"for",
"f",
"in",
"set",
"(",
"self",
".",
"policy_files",
")",
"-",
"set",
"(",
"policy_files",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"Removing policies for file: {}\"",
".",
"format",
"(",
"f",
")",
")",
"self",
".",
"file_timestamps",
".",
"pop",
"(",
"f",
",",
"None",
")",
"for",
"p",
"in",
"self",
".",
"policy_cache",
".",
"keys",
"(",
")",
":",
"self",
".",
"disassociate_policy_and_file",
"(",
"p",
",",
"f",
")",
"for",
"p",
"in",
"[",
"k",
"for",
"k",
",",
"v",
"in",
"self",
".",
"policy_map",
".",
"items",
"(",
")",
"if",
"v",
"==",
"f",
"]",
":",
"self",
".",
"restore_or_delete_policy",
"(",
"p",
")",
"self",
".",
"policy_files",
"=",
"policy_files",
"for",
"f",
"in",
"sorted",
"(",
"self",
".",
"file_timestamps",
".",
"keys",
"(",
")",
")",
":",
"t",
"=",
"os",
".",
"path",
".",
"getmtime",
"(",
"f",
")",
"if",
"t",
">",
"self",
".",
"file_timestamps",
"[",
"f",
"]",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"Loading policies for file: {}\"",
".",
"format",
"(",
"f",
")",
")",
"self",
".",
"file_timestamps",
"[",
"f",
"]",
"=",
"t",
"old_p",
"=",
"[",
"k",
"for",
"k",
",",
"v",
"in",
"self",
".",
"policy_map",
".",
"items",
"(",
")",
"if",
"v",
"==",
"f",
"]",
"try",
":",
"new_p",
"=",
"operation_policy",
".",
"read_policy_from_file",
"(",
"f",
")",
"except",
"ValueError",
":",
"self",
".",
"logger",
".",
"error",
"(",
"\"Failure loading file: {}\"",
".",
"format",
"(",
"f",
")",
")",
"self",
".",
"logger",
".",
"debug",
"(",
"\"\"",
",",
"exc_info",
"=",
"True",
")",
"continue",
"for",
"p",
"in",
"new_p",
".",
"keys",
"(",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"Loading policy: {}\"",
".",
"format",
"(",
"p",
")",
")",
"if",
"p",
"in",
"self",
".",
"reserved_policies",
":",
"self",
".",
"logger",
".",
"warning",
"(",
"\"Policy '{}' overwrites a reserved policy and \"",
"\"will be thrown out.\"",
".",
"format",
"(",
"p",
")",
")",
"continue",
"if",
"p",
"in",
"sorted",
"(",
"self",
".",
"policy_store",
".",
"keys",
"(",
")",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"\"Policy '{}' overwrites an existing \"",
"\"policy.\"",
".",
"format",
"(",
"p",
")",
")",
"if",
"f",
"!=",
"self",
".",
"policy_map",
".",
"get",
"(",
"p",
")",
":",
"self",
".",
"policy_cache",
".",
"get",
"(",
"p",
")",
".",
"append",
"(",
"(",
"time",
".",
"time",
"(",
")",
",",
"self",
".",
"policy_map",
".",
"get",
"(",
"p",
")",
",",
"self",
".",
"policy_store",
".",
"get",
"(",
"p",
")",
")",
")",
"else",
":",
"self",
".",
"policy_cache",
"[",
"p",
"]",
"=",
"[",
"]",
"self",
".",
"policy_store",
"[",
"p",
"]",
"=",
"new_p",
".",
"get",
"(",
"p",
")",
"self",
".",
"policy_map",
"[",
"p",
"]",
"=",
"f",
"for",
"p",
"in",
"set",
"(",
"old_p",
")",
"-",
"set",
"(",
"new_p",
".",
"keys",
"(",
")",
")",
":",
"self",
".",
"disassociate_policy_and_file",
"(",
"p",
",",
"f",
")",
"self",
".",
"restore_or_delete_policy",
"(",
"p",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
test
|
PolicyDirectoryMonitor.run
|
Start monitoring operation policy files.
|
kmip/services/server/monitor.py
|
def run(self):
"""
Start monitoring operation policy files.
"""
self.initialize_tracking_structures()
if self.live_monitoring:
self.logger.info("Starting up the operation policy file monitor.")
while not self.halt_trigger.is_set():
time.sleep(1)
self.scan_policies()
self.logger.info("Stopping the operation policy file monitor.")
else:
self.scan_policies()
|
def run(self):
"""
Start monitoring operation policy files.
"""
self.initialize_tracking_structures()
if self.live_monitoring:
self.logger.info("Starting up the operation policy file monitor.")
while not self.halt_trigger.is_set():
time.sleep(1)
self.scan_policies()
self.logger.info("Stopping the operation policy file monitor.")
else:
self.scan_policies()
|
[
"Start",
"monitoring",
"operation",
"policy",
"files",
"."
] |
OpenKMIP/PyKMIP
|
python
|
https://github.com/OpenKMIP/PyKMIP/blob/b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e/kmip/services/server/monitor.py#L135-L148
|
[
"def",
"run",
"(",
"self",
")",
":",
"self",
".",
"initialize_tracking_structures",
"(",
")",
"if",
"self",
".",
"live_monitoring",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"Starting up the operation policy file monitor.\"",
")",
"while",
"not",
"self",
".",
"halt_trigger",
".",
"is_set",
"(",
")",
":",
"time",
".",
"sleep",
"(",
"1",
")",
"self",
".",
"scan_policies",
"(",
")",
"self",
".",
"logger",
".",
"info",
"(",
"\"Stopping the operation policy file monitor.\"",
")",
"else",
":",
"self",
".",
"scan_policies",
"(",
")"
] |
b51c5b044bd05f8c85a1d65d13a583a4d8fc1b0e
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.