java.lang.Object
org.python.core.PyObject
com.inductiveautomation.ignition.common.script.abc.ContextManager
com.inductiveautomation.ignition.common.secrets.PyPlaintext
All Implemented Interfaces:
Serializable

public class PyPlaintext extends ContextManager
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

    Constructors
    Constructor
    Description
    Constructs a PyPlaintext instance that wraps the given Plaintext instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.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.
    void
    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.
    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

    Methods inherited from class java.lang.Object

    clone, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PyPlaintext

      public PyPlaintext(Plaintext plaintext)
      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

      public String 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

      public String getSecretAsString(String charsetName)
      Decode the wrapped byte array into a String given a Character set.
      Parameters:
      charsetName - the name of the requested Charset to 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 supported
      IllegalStateException - 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, eg f in:
           with open("file.txt") as f:
               print f.readlines()
       
      Specified by:
      __enter__ in class ContextManager
    • __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 class ContextManager
      Parameters:
      type - The type of the exception thrown in the block of code, if any (can be Py.None).
      value - The actual exception instance, if any was thrown (can be Py.None).
      traceback - A 'traceback' object, with detail about the exception, if any was thrown (can be Py.None).