-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move most of init implementation out into go.sandstorm.
- Loading branch information
Showing
4 changed files
with
5 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.