Coverage report: /home/ellis/.stash/lisp/cl-plus-ssl/src/random.lisp
Kind | Covered | All | % |
expression | 0 | 23 | 0.0 |
branch | 0 | 2 | 0.0 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; indent-tabs-mode: nil; coding: utf-8; show-trailing-whitespace: t -*-
3
;;; Copyright (C) contributors as per cl+ssl git history
5
;;; See LICENSE for details.
9
(defun random-bytes (count)
10
"Generates COUNT cryptographically strong pseudo-random bytes. Returns
11
the bytes as a SIMPLE-ARRAY with ELEMENT-TYPE '(UNSIGNED-BYTE 8). Signals
12
an ERROR in case of problems; for example, when the OpenSSL random number
13
generator has not been seeded with enough randomness to ensure an
14
unpredictable byte sequence."
15
(let* ((result (make-array count :element-type '(unsigned-byte 8)))
16
(buf (make-buffer count))
17
(ret (with-pointer-to-vector-data (ptr buf)
18
(rand-bytes ptr count))))
20
(error "RANDOM-BYTES failed: error reported by the OpenSSL RAND_bytes function. ~A."
21
(format-ssl-error-queue nil (read-ssl-error-queue))))
22
(s/b-replace result buf)))
24
;; TODO: Should we define random-specific constants and condition classes for
25
;; RAND_F_RAND_GET_RAND_METHOD, RAND_F_SSLEAY_RAND_BYTES, RAND_R_PRNG_NOT_SEEDED
26
;; (defined in the rand.h file of the OpenSSl sources)?
27
;; Where to place these constants/condtitions, here or in the conditions.lisp?
28
;; On the other hand, those constants are just numbers defined for C,
29
;; for now we jsut report human readable strings, without possibility
30
;; to distinguish these error causes programmatically.