SecretExchange
Superclasses: Object
- Constructors:
SecretExchange(**properties)
new(protocol:str=None) -> Gcr.SecretExchange
Constructors
- class SecretExchange
- classmethod new(protocol: str | None = None) SecretExchange
Create a new secret exchange object.
Specify a protocol of
None
to allow any protocol. This is especially relevant on the side of the exchange that does not callbegin
, that is the originator. Currently the only protocol supported isSECRET_EXCHANGE_PROTOCOL_1
.- Parameters:
protocol – the exchange protocol to use
Methods
- class SecretExchange
- begin() str
Begin the secret exchange. The resulting string should be sent to the other side of the exchange. The other side should use
receive
to process the string.
- get_protocol() str
Will return
None
if no protocol was specified, and eitherbegin
orreceive
have not been called successfully.
- get_secret() list[str]
Returns the last secret received. If no secret has yet been received this will return
None
. The string is owned by theSecretExchange
object and will be valid until the next time thatreceive()
is called on this object, or the object is destroyed.Depending on the secret passed into the other side of the secret exchange, the result may be a binary string. It does however have a null terminator, so if you’re certain that it is does not contain arbitrary binary data, it can be used as a string.
- receive(exchange: str) bool
Receive a string from the other side of secret exchange. This string will have been created by
begin
orsend
.After this call completes successfully the value returned from
get_secret()
will have changed.- Parameters:
exchange – the string received
- send(secret: str | None, secret_len: int) str
Send a reply to the other side of the secret exchange, optionally sending a secret.
receive
must have been successfully called at least once on this object. In other words this object must have received data from the other side of the secret exchange, before we can send a secret.- Parameters:
secret – optionally, a secret to send to the other side
secret_len – length of
secret
, or -1 if null terminated