From 218bc54a5f6c942ac02be0d9baf4d9a207b57c19 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sat, 11 Sep 2021 23:05:31 +0900 Subject: [PATCH] Define Instance::set_keypair() --- plume-models/src/instance.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plume-models/src/instance.rs b/plume-models/src/instance.rs index db771afa..1576b7c5 100644 --- a/plume-models/src/instance.rs +++ b/plume-models/src/instance.rs @@ -242,6 +242,20 @@ impl Instance { }) .map_err(Error::from) } + + pub fn set_keypair(&self, conn: &Connection) -> Result<()> { + let (pub_key, priv_key) = gen_keypair(); + let private_key = String::from_utf8(priv_key).or(Err(Error::Signature))?; + let public_key = String::from_utf8(pub_key).or(Err(Error::Signature))?; + diesel::update(self) + .set(( + instances::private_key.eq(Some(private_key)), + instances::public_key.eq(Some(public_key)), + )) + .execute(conn) + .and(Ok(())) + .map_err(Error::from) + } } impl NewInstance {