Skip to content

Add secret_encrypt_file() and secret_decrypt_file()#289

Merged
hadley merged 7 commits intomainfrom
secret-file
Sep 5, 2023
Merged

Add secret_encrypt_file() and secret_decrypt_file()#289
hadley merged 7 commits intomainfrom
secret-file

Conversation

@hadley
Copy link
Copy Markdown
Member

@hadley hadley commented Aug 28, 2023

Fixes #237

@hadley hadley requested a review from jennybc August 28, 2023 22:30
Comment thread NEWS.md Outdated
Comment thread R/secret.R Outdated
Comment thread R/secret.R Outdated
Comment thread R/secret.R Outdated
Comment thread R/secret.R Outdated
Comment thread R/secret.R Outdated
#' want to pass the unencrypted file to another function.
#' @rdname secrets
secret_decrypt_file <- function(path, key, envir = parent.frame()) {
val <- readChar(path, file.info(path)$size)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason for focusing on text files? I think httr2's focus on encrypting/decrypting strings and text is part of how I ended up writing gargle::secret_(write|read)_rds() and gmailr::gm_token_(write|read).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just because secret_encrypt() returns a base64 encoded string. This isn't really necessary for files, but it seems simple enough to keep it. It shouldn't affect your ability to encrypt and decrypt binary files. (And there's already secret_write_rds() and secret_read_rds() if you want rds files).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh but I still need to read a binary file when encrypting. So probably better to be consistent.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And that made me realise that there's a bunch of duplicate code between string and rds encryption, so overall a nice refactoring. Thanks for spotting the problem!

@hadley hadley merged commit d0164e4 into main Sep 5, 2023
@hadley hadley deleted the secret-file branch September 5, 2023 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Helpers for encrypting/decrypting files

2 participants