retrieve_object: Retrieve an object from a connection(or a file)

View source: R/save.R

retrieve_objectR Documentation

Retrieve an object from a connection(or a file)

Description

save_object encrypts a R object to raw or text connection or a file. retrieve_object decrypts a raw or a text connection or a file (encrypted by save_object). Note that retrieve_object returns the object.

Usage

retrieve_object(conn, key = "pass", pkey = NULL, ascii = FALSE)

Arguments

conn

A connection or a file where the decrypted content is written. If ascii is TRUE, an decrypted text is written to the connection. Else, when ascii is FALSE(default), a raw object is written to the connection

key

For symmetric decryption, 'pkey' should be NULL (default) and 'key' can be either a string (Default is 'pass') or a raw object. For asymmetric decryption, both 'key' (private key of the decrypter) and 'pkey' (public key of the encrypter) should be raw objects.

pkey

See 'key'

ascii

TRUE, if the encrypted output is a string(written to the text connection). FALSE, if the encrypted output is a raw object(written to the raw connection)

Value

An invisible TRUE

Examples

# symmetric case:
all(
  save_object(iris, conn = "iris_safer.bin")
  , identical(retrieve_object(conn = "iris_safer.bin"), iris)
  , unlink("iris_safer.bin") == 0
)

all(
  save_object(iris, conn = "iris_safer_2.txt", ascii = TRUE)
  , identical(retrieve_object(conn = "iris_safer_2.txt", ascii = TRUE), iris)
  , unlink("iris_safer_2.txt") == 0
)

# asymmetric case:
alice <- keypair()
bob   <- keypair()
all(
  save_object(iris, alice$private_key, bob$public_key, conn = "iris_safer.bin")
  , identical(retrieve_object(conn = "iris_safer.bin", bob$private_key, alice$public_key), iris)
  , unlink("iris_safer.bin") == 0
)


talegari/safer documentation built on Feb. 9, 2023, 3:43 p.m.