Skip to main content

ts_keys/
lib.rs

1#![doc = include_str!("../README.md")]
2#![no_std]
3
4extern crate alloc;
5
6mod keystate;
7mod macros;
8
9#[doc(inline)]
10pub use keystate::{NodeState, PersistState};
11use macros::{
12    _create_x25519_base_key_type, create_x25519_keypair_types, create_x25519_private_key_type,
13    create_x25519_public_key_type,
14};
15
16/// Errors that may occur when parsing a string into a key type.
17#[derive(Debug, Copy, Clone, PartialEq, Eq, thiserror::Error)]
18pub enum ParseError {
19    /// Key string was formatted incorrectly.
20    #[error("key string was formatted incorrectly")]
21    InvalidFormat,
22
23    /// Key was the wrong length.
24    #[error("key was the wrong length")]
25    WrongLength,
26
27    /// Parsed prefix did not match the key type.
28    #[error("parsed prefix did not match the key type")]
29    BadPrefix,
30}
31
32// The client never handles challenge private keys, so we only create a public key type rather than
33// public/private/keypair types.
34create_x25519_public_key_type!(
35    /// The X25519 public key of a challenge issued by control to a Tailnet node during registration.
36    ChallengePublicKey,
37    "chalpub"
38);
39
40// The client never handles DERP server private keys, so we only create a public key type rather
41// than public/private/keypair types.
42create_x25519_public_key_type!(
43    /// The X25519 public key of a DERP server.
44    DerpServerPublicKey,
45    "derp"
46);
47create_x25519_keypair_types!(
48    /// The X25519 public key a Tailscale node uses for the Disco protocol.
49    DiscoPublicKey,
50    "discokey",
51    /// The X25519 private key a Tailscale node uses for the Disco protocol.
52    DiscoPrivateKey,
53    "privkey",
54    /// The X25519 public/private key pair a Tailscale node uses for the Disco protocol.
55    DiscoKeyPair
56);
57
58create_x25519_keypair_types!(
59    /// The X25519 public key of a unique piece of hardware running one or more Tailscale nodes.
60    /// Also the key type sent from a control server to a Tailscale node during the initial control
61    /// handshake.
62    MachinePublicKey,
63    "mkey",
64    /// The X25519 private key of a unique piece of hardware running one or more Tailscale nodes.
65    MachinePrivateKey,
66    "privkey",
67    /// The X25519 public/private key pair of a unique piece of hardware running one or more
68    /// Tailscale nodes.
69    MachineKeyPair
70);
71
72create_x25519_keypair_types!(
73    /// The X25519 public key of a Tailscale node for use with Tailnet Lock.
74    NetworkLockPublicKey,
75    "nlpub",
76    /// The X25519 private key of a Tailscale node for use with Tailnet Lock.
77    NetworkLockPrivateKey,
78    "nlpriv",
79    /// The X25519 public/private key pair of a Tailscale node for use with Tailnet Lock.
80    NetworkLockKeyPair
81);
82
83create_x25519_keypair_types!(
84    /// The X25519 public key of a Tailscale node.
85    NodePublicKey,
86    "nodekey",
87    /// The X25519 private key of a Tailscale node.
88    NodePrivateKey,
89    "privkey",
90    /// The X25519 public/private key pair of a Tailscale node.
91    NodeKeyPair
92);