You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
527 B

  1. package keys
  2. import "fmt"
  3. type CryptoAlgo string
  4. const (
  5. AlgoEd25519 = CryptoAlgo("ed25519")
  6. AlgoSecp256k1 = CryptoAlgo("secp256k1")
  7. )
  8. func cryptoAlgoToByte(key CryptoAlgo) byte {
  9. switch key {
  10. case AlgoEd25519:
  11. return 0x01
  12. case AlgoSecp256k1:
  13. return 0x02
  14. default:
  15. panic(fmt.Sprintf("Unexpected type key %v", key))
  16. }
  17. }
  18. func byteToCryptoAlgo(b byte) CryptoAlgo {
  19. switch b {
  20. case 0x01:
  21. return AlgoEd25519
  22. case 0x02:
  23. return AlgoSecp256k1
  24. default:
  25. panic(fmt.Sprintf("Unexpected type byte %X", b))
  26. }
  27. }