File: list.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 (44 lines) | stat: -rw-r--r-- 996 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#' @export
as.list.key <- function(x, ...){
  key <- x
  pubkey <- derive_pubkey(key)
  pk <- as.list(pubkey)
  list(
    type = pk$type,
    size = pk$size,
    pubkey = pubkey,
    data = decompose(key)
  )
}

#' @export
as.list.pubkey <- function(x, ...){
  pubkey <- x
  data <- decompose(pubkey)
  type <- ifelse(inherits(pubkey, "ed25519"), "ed25519", pubkey_type(pubkey))
  size <- pubkey_bitsize(pubkey)
  header <- switch(type,
   "rsa" = "ssh-rsa",
   "dsa" = "ssh-dss",
   "ed25519" = "ssh-ed25519",
   "x25519" = "(no-ssh)",
   "ecdsa" = paste0("ecdsa-sha2-nistp", substring(data$curve, 3)),
   stop("Unsupported keytype: ", type)
  )
  fp <- unlist(unname(fpdata(pubkey)))
  list(
    type = type,
    size = size,
    ssh = paste(header, base64_encode(fp)),
    fingerprint = md5(fp),
    data = data
  )
}

#' @export
as.list.cert <- function(x, ..., name_format = NULL){
  cert <- x
  info <- cert_info(cert, name_format = name_format)
  info$pubkey <- cert_pubkey(cert)
  info
}