diff options
author | alaviss <alaviss@users.noreply.github.com> | 2020-03-26 13:47:15 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-26 14:47:15 +0100 |
commit | 6162da812af822f739dd00bb1b6c12658a89c669 (patch) | |
tree | cb22d1cbcb34a0429c0d2c4387586ecff9e2b74f /lib/pure | |
parent | 2da438c33b55ddfefd5d0e5e876721a00dabd42c (diff) | |
download | Nim-6162da812af822f739dd00bb1b6c12658a89c669.tar.gz |
ssl_certs: add Haiku support (#13761)
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/ssl_certs.nim | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/lib/pure/ssl_certs.nim b/lib/pure/ssl_certs.nim index 7b1550004..9845de9b6 100644 --- a/lib/pure/ssl_certs.nim +++ b/lib/pure/ssl_certs.nim @@ -49,6 +49,18 @@ const certificate_paths = [ "/etc/openssl/certs", ] +when defined(haiku): + const + B_FIND_PATH_EXISTING_ONLY = 0x4 + B_FIND_PATH_DATA_DIRECTORY = 6 + + proc find_paths_etc(architecture: cstring, baseDirectory: cint, + subPath: cstring, flags: uint32, + paths: var ptr UncheckedArray[cstring], + pathCount: var csize): int32 + {.importc, header: "<FindDirectory.h>".} + proc free(p: pointer) {.importc, header: "<stdlib.h>".} + iterator scanSSLCertificates*(useEnvVars = false): string = ## Scan for SSL/TLS CA certificates on disk. ## @@ -64,13 +76,26 @@ iterator scanSSLCertificates*(useEnvVars = false): string = yield fn else: - for p in certificate_paths: - if p.endsWith(".pem") or p.endsWith(".crt"): - if existsFile(p): - yield p - elif existsDir(p): - for fn in joinPath(p, "*").walkFiles(): - yield fn + when not defined(haiku): + for p in certificate_paths: + if p.endsWith(".pem") or p.endsWith(".crt"): + if existsFile(p): + yield p + elif existsDir(p): + for fn in joinPath(p, "*").walkFiles(): + yield fn + else: + var + paths: ptr UncheckedArray[cstring] + size: csize + let err = find_paths_etc( + nil, B_FIND_PATH_DATA_DIRECTORY, "ssl/CARootCertificates.pem", + B_FIND_PATH_EXISTING_ONLY, paths, size + ) + if err == 0: + defer: free(paths) + for i in 0 ..< size: + yield $paths[i] # Certificates management on windows # when defined(windows) or defined(nimdoc): |