mirror of
https://github.com/logos-storage/logos-storage-docs-obsidian.git
synced 2026-01-08 00:03:08 +00:00
22 lines
761 B
Markdown
22 lines
761 B
Markdown
Having a Nim sequence:
|
|
|
|
```nim
|
|
var buff = newSeq[byte](buffSize)
|
|
```
|
|
|
|
if you want to get a pointer to the underlying data buffer that is suitable for being passed to a C library, you can simply use:
|
|
|
|
```nim
|
|
sha256Update(ctx, addr buff[0], input[i].len.uint)
|
|
```
|
|
|
|
If your input is a `string`, you can use the following:
|
|
|
|
```nim
|
|
let str = "abcdefghijklmnopqrstuvwxyz"
|
|
sha256Update(ctx, str.cstring, input[i].len.uint)
|
|
```
|
|
|
|
Here we use `sha256Update` from [[BearSSL]] library. See [[How to create a hash using BearSSL]] for more complete examples.
|
|
See also [Accessing seq pointer](https://forum.nim-lang.org/t/1489), [Use cstring for C binding](https://forum.nim-lang.org/t/8179), and [Arrays and Sequences in nim](https://forum.nim-lang.org/t/5703) on Nim forum.
|