File: writessh.R

package info (click to toggle)
r-cran-openssl 1.4.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,288 kB
  • sloc: ansic: 3,021; sh: 97; makefile: 5
file content (22 lines) | stat: -rw-r--r-- 547 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#' @export
#' @rdname write_pem
#' @param pubkey a public key
#' @examples # Generate RSA keypair
#' key <- rsa_keygen()
#' pubkey <- key$pubkey
#'
#' # Write to output formats
#' write_ssh(pubkey)
#' write_pem(pubkey)
#' write_pem(key, password = "super secret")
write_ssh <- function(pubkey, path = NULL){
  if(inherits(pubkey, "key"))
    pubkey <- derive_pubkey(pubkey)
  if(!inherits(pubkey, "pubkey"))
    stop("Invalid pubkey file.")
  str <- as.list(pubkey)$ssh
  if(is.null(path)) return(str)
  writeLines(str, path)
  invisible(path)
}