Skip to content

Commit

Permalink
Move most of init implementation out into go.sandstorm.
Browse files Browse the repository at this point in the history
  • Loading branch information
zenhack committed Aug 7, 2020
1 parent 108deae commit 8b15975
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 300 deletions.
41 changes: 5 additions & 36 deletions init.go
Original file line number Diff line number Diff line change
@@ -1,48 +1,17 @@
package main

import (
"crypto/rand"
"encoding/binary"
"flag"
"os"

"zenhack.net/go/sandstorm/exp/spk"
)

type PkgDefParams struct {
SchemaId uint64
AppId string
}

func randU64() uint64 {
// It would probably be fine to use math/rand.Uint64 for this, but
// elsewhere randomly generating a key, and I(zenhack) am generally
// nervous about mixing cryptographc and non-cryptographic rngs in
// nearby code.
var ret uint64
if err := binary.Read(rand.Reader, binary.LittleEndian, &ret); err != nil {
panic(err)
}
return ret
}

func initCmd() {
flag.Parse()

key, err := spk.GenerateKey(nil)
chkfatal("Generating a key", err)

appId, err := key.AppId()
chkfatal("Getting public key", err)

params := &PkgDefParams{
AppId: appId.String(),
SchemaId: randU64() | (1 << 63),
}

chkfatal("Saving the app key", key.AddToFile(*keyringPath))

pkgDefFile, err := os.Create("sandstorm-pkgdef.capnp")
chkfatal("Creating sandstorm-pkgdef.capnp", err)
chkfatal("Outputting sandstorm-pkgdef.capnp", PkgDefTemplate.Execute(pkgDefFile, params))
pkgdef, err := spk.NewApp()
chkfatal("Generating app info", err)
pkgdef.KeyringPath = *keyringPath
pkgdef.PkgDefPath = "sandstorm-pkgdef.capnp"
chkfatal("Emitting app scaffolding", pkgdef.Emit())
}
38 changes: 0 additions & 38 deletions internal/embed-template.go

This file was deleted.

218 changes: 0 additions & 218 deletions sandstorm-pkgdef.capnp.template

This file was deleted.

Loading

0 comments on commit 8b15975

Please sign in to comment.