Class PyPlaintext
java.lang.Object
org.python.core.PyObject
com.inductiveautomation.ignition.common.script.abc.ContextManager
com.inductiveautomation.ignition.common.secrets.PyPlaintext
- All Implemented Interfaces:
Serializable
A Python wrapper for the
Plaintext class, allowing it to be used as a context manager in Jython scripts,
which means it can be used in a with...as statement. After the with...as statement
concludes, the plaintext data is cleared, ensuring that sensitive information is not left in memory longer than
necessary. Any attempt to access the plaintext data after it has been cleared will throw an
IllegalStateException.
with system.secrets.decrypt(json) as secret:
print secret.getSecretAsString()
Alternatively, the clear() method can be called to clear the plaintext data, ensuring that sensitive data
is not left in memory longer than necessary. Any attempt to access the plaintext data after it has been cleared will
throw an IllegalStateException.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.python.core.PyObject
org.python.core.PyObject.ConversionException -
Field Summary
Fields inherited from class org.python.core.PyObject
attributes, gcMonitorGlobal, objtype, TYPE -
Constructor Summary
ConstructorsConstructorDescriptionPyPlaintext(Plaintext plaintext) Constructs a PyPlaintext instance that wraps the given Plaintext instance. -
Method Summary
Modifier and TypeMethodDescriptionorg.python.core.PyObject"Enter" this context manager.void__exit__(org.python.core.PyObject type, org.python.core.PyObject value, org.python.core.PyObject traceback) "Exit" this context manager - should be used to close any resources opened on initialization.voidclear()Zeroes the wrapped byte array and clears the reference to the byte array.byte[]Returns a direct reference to the wrapped byte array.UTF-8 decode the wrapped byte array into a String.getSecretAsString(String charsetName) Decode the wrapped byte array into a String given a Character set.Methods inherited from class org.python.core.PyObject
__abs__, __add__, __and__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __cmp__, __coerce__, __coerce_ex__, __complex__, __contains__, __delattr__, __delattr__, __delete__, __delitem__, __delitem__, __delslice__, __delslice__, __dir__, __div__, __divmod__, __ensure_finalizer__, __eq__, __findattr__, __findattr__, __findattr_ex__, __finditem__, __finditem__, __finditem__, __float__, __floordiv__, __format__, __ge__, __get__, __getattr__, __getattr__, __getitem__, __getitem__, __getnewargs__, __getslice__, __getslice__, __gt__, __hash__, __hex__, __iadd__, __iand__, __idiv__, __idivmod__, __ifloordiv__, __ilshift__, __imod__, __imul__, __index__, __int__, __invert__, __ior__, __ipow__, __irshift__, __isub__, __iter__, __iternext__, __itruediv__, __ixor__, __le__, __len__, __long__, __lshift__, __lt__, __mod__, __mul__, __ne__, __neg__, __nonzero__, __not__, __oct__, __or__, __pos__, __pow__, __pow__, __radd__, __rand__, __rawdir__, __rdiv__, __rdivmod__, __reduce__, __reduce_ex__, __reduce_ex__, __repr__, __rfloordiv__, __rlshift__, __rmod__, __rmul__, __ror__, __rpow__, __rrshift__, __rshift__, __rsub__, __rtruediv__, __rxor__, __set__, __setattr__, __setattr__, __setitem__, __setitem__, __setitem__, __setslice__, __setslice__, __str__, __sub__, __tojava__, __truediv__, __trunc__, __unicode__, __xor__, _add, _and, _callextra, _cmp, _div, _divmod, _doget, _doget, _doset, _eq, _floordiv, _ge, _gt, _iadd, _iand, _idiv, _idivmod, _ifloordiv, _ilshift, _imod, _imul, _in, _ior, _ipow, _irshift, _is, _isnot, _isub, _itruediv, _ixor, _jcall, _jcallexc, _jthrow, _le, _lshift, _lt, _mod, _mul, _ne, _notin, _or, _pow, _rshift, _sub, _truediv, _unsupportedop, _xor, adaptToCoerceTuple, asDouble, asIndex, asIndex, asInt, asInt, asIterable, asLong, asLong, asName, asName, asString, asString, asStringOrNull, asStringOrNull, bit_length, conjugate, delDict, delType, dispatch__init__, equals, fastGetClass, fastGetDict, finalize, getDict, getJavaProxy, getType, hashCode, impAttr, implementsDescrDelete, implementsDescrGet, implementsDescrSet, invoke, invoke, invoke, invoke, invoke, invoke, isCallable, isDataDescr, isIndex, isInteger, isMappingType, isNumberType, isSequenceType, mergeClassDict, mergeDictAttr, mergeListAttr, noAttributeError, object___subclasshook__, readonlyAttributeError, runsupportedopMessage, setDict, setType, toString, unsupportedopMessage
-
Constructor Details
-
PyPlaintext
Constructs a PyPlaintext instance that wraps the given Plaintext instance.- Parameters:
plaintext- the Plaintext instance to wrap. cannot be null.- Throws:
NullPointerException- if the plaintext argument is null
-
-
Method Details
-
getSecretAsBytes
public byte[] getSecretAsBytes()Returns a direct reference to the wrapped byte array.- Returns:
- a direct reference to the wrapped byte array. never null.
- Throws:
IllegalStateException- if the Plaintext instance is cleared
-
getSecretAsString
UTF-8 decode the wrapped byte array into a String.- Returns:
- a new String instance from decoding the wrapped UTF-8 encoded byte array. never null.
- Throws:
IllegalStateException- if the Plaintext instance is cleared- See Also:
-
getSecretAsString
Decode the wrapped byte array into a String given a Character set.- Parameters:
charsetName- the name of the requestedCharsetto be used to decode the wrapped byte array into a String- Returns:
- a new String instance from decoding the wrapped byte array. never null.
- Throws:
IllegalArgumentException- if the given charset name is invalid, null, or not supportedIllegalStateException- if the Plaintext instance is cleared
-
clear
public void clear()Zeroes the wrapped byte array and clears the reference to the byte array. The Plaintext instance is no longer usable after it is cleared.- Throws:
IllegalStateException- if the Plaintext instance has already been cleared
-
__enter__
public org.python.core.PyObject __enter__()Description copied from class:ContextManager"Enter" this context manager. Returns an object that can be aliased by the `with` statement, egfin:with open("file.txt") as f: print f.readlines()- Specified by:
__enter__in classContextManager
-
__exit__
public void __exit__(org.python.core.PyObject type, org.python.core.PyObject value, org.python.core.PyObject traceback) Description copied from class:ContextManager"Exit" this context manager - should be used to close any resources opened on initialization.- Specified by:
__exit__in classContextManager- Parameters:
type- The type of the exception thrown in the block of code, if any (can bePy.None).value- The actual exception instance, if any was thrown (can bePy.None).traceback- A 'traceback' object, with detail about the exception, if any was thrown (can bePy.None).
-