Skip to content

toMD5 does not work at compile time but documentation claims otherwise #19305

@metagn

Description

@metagn

md5 docs says "Note: The procs in this module can be used at compile time.". However, toMD5 does not work.

Example

import md5

static:
  block working:
    doAssert(getMD5("Franz jagt im komplett verwahrlosten Taxi quer durch Bayern") ==
      "a3cca2b2aa1e3b5b3b5aad99a8529074")
    doAssert(getMD5("Frank jagt im komplett verwahrlosten Taxi quer durch Bayern") ==
      "7e716d0e702df0505fc72e2b89467910")
  block failing:
    doAssert($toMD5("") == "d41d8cd98f00b204e9800998ecf8427e")
    discard toMD5("")

Current Output

nim/lib/system/memory.nim(21, 5) Error: cannot 'importc' variable at compile time; c_memset

Expected Output

compiles

Possible Solution

Looking at the code, there is no reason for md5 to use cstring/pointer behavior. There is already some use of openarray so it's puzzling why it doesn't use openarray in place of cstring/pointer as well, the buffer used is an array[0..63, uint8]. Same seems to go for endians/oids/sha1.

Additional Information

$ nim -v
Nim Compiler Version 1.6.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions