Changeset 40248 in project


Ignore:
Timestamp:
07/02/21 12:01:09 (4 weeks ago)
Author:
Vasilij Schneidermann
Message:

openssl: Improve error handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/5/openssl/trunk/openssl.cipher.scm

    r40247 r40248  
    7777(define EVP_CIPHER_CTX_ctrl (foreign-lambda int "EVP_CIPHER_CTX_ctrl" EVP_CIPHER_CTX* int int blob))
    7878(define EVP_CIPHER_CTX_flags (foreign-lambda int "EVP_CIPHER_CTX_flags" EVP_CIPHER_CTX*))
     79(define EVP_CIPHER_CTX_cipher (foreign-lambda EVP_CIPHER* "EVP_CIPHER_CTX_cipher" EVP_CIPHER_CTX*))
    7980
    8081(define EVP_CipherInit_ex (foreign-lambda bool "EVP_CipherInit_ex" EVP_CIPHER_CTX* EVP_CIPHER* c-pointer blob blob int))
     
    154155  (let ((ctx (cipher-context-ptr context)))
    155156    (when (not ctx)
    156       (openssl-type-error 'cipher-context-unwrap! "valid context pointer"))
     157      (openssl-type-error 'cipher-context-unwrap! "valid context pointer" #f))
    157158    ctx))
    158159
     
    231232        (openssl-type-error 'cipher-context-init! "decrypt mode" mode))
    232233      (when (not tag-length)
    233         (openssl-type-error 'cipher-context-init! "tag length"))
     234        (openssl-type-error 'cipher-context-init! "tag length" #f))
    234235      (when (> tag-length (blob-size expected-tag))
    235         (openssl-type-error 'cipher-context-init! "tag shorter than tag length"))
     236        (openssl-type-error 'cipher-context-init! "tag shorter than tag length" tag-length (blob-size expected-tag)))
    236237      (when (not (EVP_CIPHER_CTX_ctrl ctx EVP_CTRL_AEAD_SET_TAG tag-length expected-tag))
    237238        (openssl-error 'cipher-context-init! (list expected-tag tag-length))))
     
    291292    (ERR_clear_error)
    292293    (when (not (aead-cipher? ctx))
    293       (openssl-type-error 'cipher-context-get-tag "AEAD cipher"))
    294     (let* ((tag-length (cipher-context-tag-length context))
    295            (buf (make-blob tag-length)))
     294      (openssl-type-error 'cipher-context-get-tag "AEAD cipher" (cipher-name (EVP_CIPHER_CTX_cipher ctx))))
     295    (let ((tag-length (cipher-context-tag-length context)))
    296296      (when (not tag-length)
    297         (openssl-type-error 'cipher-context-get-tag "tag length to be set"))
    298       (when (not (EVP_CIPHER_CTX_ctrl ctx EVP_CTRL_AEAD_GET_TAG tag-length buf))
    299         (openssl-error 'cipher-context-get-tag tag-length))
    300       buf)))
     297        (openssl-type-error 'cipher-context-get-tag "tag length to be set" #f))
     298      (let ((buf (make-blob tag-length)))
     299        (when (not (EVP_CIPHER_CTX_ctrl ctx EVP_CTRL_AEAD_GET_TAG tag-length buf))
     300          (openssl-error 'cipher-context-get-tag tag-length))
     301        buf))))
    301302
    302303(define (string-cipher cipher str key iv #!rest options)
Note: See TracChangeset for help on using the changeset viewer.