2018-04-06 16:52:10 +02:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2018 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2018-01-31 14:57:05 +02:00
|
|
|
import strutils, sequtils
|
|
|
|
|
|
|
|
# proc toBytes*(value: cstring): seq[byte] =
|
|
|
|
# result = newSeq[byte](value.len)
|
|
|
|
# for z, c in value:
|
|
|
|
# result[z] = c.byte
|
|
|
|
# # result = toSeq(value)
|
|
|
|
|
|
|
|
# proc toCString*(value: seq[byte]): cstring =
|
|
|
|
# var res = ""
|
|
|
|
# for c in value:
|
|
|
|
# res.add(c.char)
|
|
|
|
# cstring(res) # TODO: faster
|
|
|
|
|
|
|
|
proc toString*(value: seq[byte]): string =
|
2018-02-20 19:27:43 +02:00
|
|
|
"0x" & value.mapIt(it.int.toHex(2)).join("").toLowerAscii
|
2018-01-31 14:57:05 +02:00
|
|
|
|
|
|
|
proc toBytes*(value: string): seq[byte] =
|
|
|
|
result = value.mapIt(it.byte)
|
2018-02-20 19:27:43 +02:00
|
|
|
|
|
|
|
|