def format_secret(session, secret, content_type):
 if (not isinstance(secret, bytes)):
  secret = secret.encode('utf-8')
 if (not session.encrypted):
  return dbus.Struct((session.object_path, '', dbus.ByteArray(secret), content_type))
 padding = (16 - (len(secret) & 15))
 secret += bytes((bytearray((padding,)) * padding))
 aes_iv = os.urandom(16)
 aes = Cipher.AES.new(session.aes_key, Cipher.MODE_CBC, Cipher.AES.aes_iv)
 encrypted_secret = aes.encrypt(secret)
 return dbus.Struct((session.object_path, dbus.Array(aes_iv), dbus.Array(bytearray(encrypted_secret)), content_type))

def format_secret ( session , secret , content_type ) : if ( not isinstance ( secret , bytes ) ) : secret = secret . encode ( 'utf-8' ) if ( not session . encrypted ) : return dbus . Struct ( ( session . object_path , '' , dbus . ByteArray ( secret ) , content_type ) ) padding = ( 16 - ( len ( secret ) & 15 ) ) secret += bytes ( ( bytearray ( ( padding , ) ) * padding ) ) aes_iv = os . urandom ( 16 ) aes = Cipher . AES . new ( session . aes_key , Cipher . MODE_CBC , Cipher . AES . aes_iv ) encrypted_secret = aes . encrypt ( secret ) return dbus . Struct ( ( session . object_path , dbus . Array ( aes_iv ) , dbus . Array ( bytearray ( encrypted_secret ) ) , content_type ) )
formats secret to make possible to pass it to the secret service api .