JuliaLang / JuliaLang/MbedTLS.jl

`encrypt` method mentioned in the documentation does not actually work

Open
#263 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
42
Forks
51
PR merge metrics
No merged PRs in 30d

Description

In the documentation for [`encrypt`](https://docs.juliahub.com/MbedTLS/bf9T0/1.0.2/autodocs/#MbedTLS.encrypt) one possible method to specify the cipher is as a `Cipher` object. However, this throws an error:

```julia
julia> using MbedTLS

julia> secret_key = rand(UInt8, 32);

julia> encrypt(Cipher(CIPHER_AES), secret_key, "message")
ERROR: MethodError: no method matching Cipher(::Cipher)
Closest candidates are:
Cipher() at ~/.julia/packages/MbedTLS/lqmet/src/cipher.jl:93
Cipher(::Union{MbedTLS.CipherID, MbedTLS.CipherKind}) at ~/.julia/packages/MbedTLS/lqmet/src/cipher.jl:182
Cipher(::MbedTLS.CipherInfo) at ~/.julia/packages/MbedTLS/lqmet/src/cipher.jl:166
Stacktrace:
[1] crypt(cipher_info::Cipher, op::MbedTLS.Operation, key::Vector{UInt8}, iv::Nothing, msg::String)
@ MbedTLS ~/.julia/packages/MbedTLS/lqmet/src/cipher.jl:277
[2] encrypt(cipher::Cipher, key::Vector{UInt8}, msg::String, iv::Nothing) (repeats 2 times)
@ MbedTLS ~/.julia/packages/MbedTLS/lqmet/src/cipher.jl:306
[3] top-level scope
@ REPL[6]:1
```

Looking at the source code, it looks like [`encrypt` calls `crypt`](https://github.com/JuliaLang/MbedTLS.jl/blob/master/src/cipher.jl#L306), which [calls the `Cipher` constructor on the `cipher_info` parameter](https://github.com/JuliaLang/MbedTLS.jl/blob/e84f9732360700a0f5baf59a65d5211411cb97fd/src/cipher.jl#L277C4-L277C4), which in this case is already a `Cipher`!

Maybe in the documentation it should say that the cipher can be a `CipherInfo` object instead of a `Cipher` object? This works:

```julia
julia> encrypt(MbedTLS.CipherInfo(CIPHER_AES), secret_key, "message")
16-element Vector{UInt8}:
0xbd
0x5f
0x2b
0x20
0x33
0xa3
0x7e
0x54
0x86
0x03
0x68
0x26
0xa9
0xa2
0xaf
0xa5
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with src/cipher.jl around the encrypt and crypt definitions cited in the report, then compare their accepted argument types with the generated encrypt documentation. Confirm whether the intended correction is to the API or its documentation, and verify the reported CipherInfo example and the documented Cipher example before marking the mismatch resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
cryptography, documentation
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.