diff options
author | Rutger Broekhoff | 2021-05-25 20:35:16 +0200 |
---|---|---|
committer | Rutger Broekhoff | 2021-05-25 20:35:16 +0200 |
commit | 199e078c124ee60e642dfbc10016394fb1197a57 (patch) | |
tree | c1b75b7a1d50f30f046e29f78a376391afefc2c5 | |
parent | 5fc11d694ad86bdb08fe61a3007aa0c44ba894aa (diff) | |
download | zig-nkeys-199e078c124ee60e642dfbc10016394fb1197a57.tar.gz zig-nkeys-199e078c124ee60e642dfbc10016394fb1197a57.zip |
Update formatting slightly
-rw-r--r-- | src/nkeys.zig | 33 |
1 files changed, 6 insertions, 27 deletions
diff --git a/src/nkeys.zig b/src/nkeys.zig index 3b77719..1d15623 100644 --- a/src/nkeys.zig +++ b/src/nkeys.zig | |||
@@ -139,18 +139,11 @@ pub const SeedKeyPair = struct { | |||
139 | return Self{ .role = role, .kp = try Ed25519.KeyPair.create(raw_seed.*) }; | 139 | return Self{ .role = role, .kp = try Ed25519.KeyPair.create(raw_seed.*) }; |
140 | } | 140 | } |
141 | 141 | ||
142 | pub fn sign( | 142 | pub fn sign(self: *const Self, msg: []const u8) SignError![Ed25519.signature_length]u8 { |
143 | self: *const Self, | ||
144 | msg: []const u8, | ||
145 | ) SignError![Ed25519.signature_length]u8 { | ||
146 | return Ed25519.sign(msg, self.kp, null); | 143 | return Ed25519.sign(msg, self.kp, null); |
147 | } | 144 | } |
148 | 145 | ||
149 | pub fn verify( | 146 | pub fn verify(self: *const Self, msg: []const u8, sig: [Ed25519.signature_length]u8) InvalidSignatureError!void { |
150 | self: *const Self, | ||
151 | msg: []const u8, | ||
152 | sig: [Ed25519.signature_length]u8, | ||
153 | ) InvalidSignatureError!void { | ||
154 | Ed25519.verify(sig, msg, self.kp.public_key) catch return error.InvalidSignature; | 147 | Ed25519.verify(sig, msg, self.kp.public_key) catch return error.InvalidSignature; |
155 | } | 148 | } |
156 | 149 | ||
@@ -204,10 +197,7 @@ pub const PublicKey = struct { | |||
204 | }; | 197 | }; |
205 | } | 198 | } |
206 | 199 | ||
207 | pub fn fromRawPublicKey( | 200 | pub fn fromRawPublicKey(role: Role, raw_key: *const [Ed25519.public_length]u8) Self { |
208 | role: Role, | ||
209 | raw_key: *const [Ed25519.public_length]u8, | ||
210 | ) Self { | ||
211 | return Self{ .role = role, .key = raw_key.* }; | 201 | return Self{ .role = role, .key = raw_key.* }; |
212 | } | 202 | } |
213 | 203 | ||
@@ -215,11 +205,7 @@ pub const PublicKey = struct { | |||
215 | return encode(1, self.key.len, &.{self.role.publicPrefixByte()}, &self.key); | 205 | return encode(1, self.key.len, &.{self.role.publicPrefixByte()}, &self.key); |
216 | } | 206 | } |
217 | 207 | ||
218 | pub fn verify( | 208 | pub fn verify(self: *const Self, msg: []const u8, sig: [Ed25519.signature_length]u8) InvalidSignatureError!void { |
219 | self: *const Self, | ||
220 | msg: []const u8, | ||
221 | sig: [Ed25519.signature_length]u8, | ||
222 | ) InvalidSignatureError!void { | ||
223 | Ed25519.verify(sig, msg, self.key) catch return error.InvalidSignature; | 209 | Ed25519.verify(sig, msg, self.key) catch return error.InvalidSignature; |
224 | } | 210 | } |
225 | 211 | ||
@@ -264,18 +250,11 @@ pub const PrivateKey = struct { | |||
264 | return encode(1, self.kp.secret_key.len, &.{prefix_byte_private}, &self.kp.secret_key); | 250 | return encode(1, self.kp.secret_key.len, &.{prefix_byte_private}, &self.kp.secret_key); |
265 | } | 251 | } |
266 | 252 | ||
267 | pub fn sign( | 253 | pub fn sign(self: *const Self, msg: []const u8) SignError![Ed25519.signature_length]u8 { |
268 | self: *const Self, | ||
269 | msg: []const u8, | ||
270 | ) SignError![Ed25519.signature_length]u8 { | ||
271 | return Ed25519.sign(msg, self.kp, null); | 254 | return Ed25519.sign(msg, self.kp, null); |
272 | } | 255 | } |
273 | 256 | ||
274 | pub fn verify( | 257 | pub fn verify(self: *const Self, msg: []const u8, sig: [Ed25519.signature_length]u8) InvalidSignatureError!void { |
275 | self: *const Self, | ||
276 | msg: []const u8, | ||
277 | sig: [Ed25519.signature_length]u8, | ||
278 | ) InvalidSignatureError!void { | ||
279 | Ed25519.verify(sig, msg, self.kp.public_key) catch return error.InvalidSignature; | 258 | Ed25519.verify(sig, msg, self.kp.public_key) catch return error.InvalidSignature; |
280 | } | 259 | } |
281 | 260 | ||