Commit 2ed2387b authored by Loïck Bonniot's avatar Loïck Bonniot

Rename package to autHority and fix lint

parent c5015c9d
Pipeline #152 failed with stage
......@@ -16,9 +16,10 @@ Unit tests:
script:
- "ln -s $(pwd) $GOPATH/src/dfss"
- "./build/deps.sh"
- "go test -coverprofile auth.part -v ./auth"
- "go test -coverprofile mgdb.part -v ./mgdb"
- "go test -coverprofile mails.part -v ./mails"
- "go test -coverprofile auth.part -v dfss/auth"
- "go test -coverprofile mgdb.part -v dfss/mgdb"
- "go test -coverprofile mails.part -v dfss/mails"
- "go test -coverprofile authority.part -v dfss/dfssp/authority"
- "echo 'mode: set' *part > c.out"
- "grep -h -v 'mode: set' *part >> c.out"
- "go tool cover -html=c.out -o coverage.html"
......@@ -31,6 +32,7 @@ ARM tests:
- "./build/deps.sh"
- "go test -cover -short -v ./auth"
- "go test -cover -short -v ./mgdb"
- "go test -cover -short -v ./dfssp/..."
Code lint:
stage: test
......
package autority
package authority
import (
"crypto/rsa"
......@@ -12,10 +12,13 @@ import (
)
const (
PkeyFileName = "dffsp_pkey.pem"
// PkeyFileName is the private key file default name
PkeyFileName = "dffsp_pkey.pem"
// RootCAFileName is the root certificate file default name
RootCAFileName = "dffsp_rootCA.pem"
)
// PlatformID contains platform private key and root certificate
type PlatformID struct {
pkey *rsa.PrivateKey
rootCA *x509.Certificate
......@@ -88,7 +91,7 @@ func Initialize(bits, days int, country, organization, unit, cn, path string) er
return nil
}
// Fetch the platform's private rsa key and root certificate, and create a PlatformID accordingly.
// Start fetches the platform's private rsa key and root certificate, and create a PlatformID accordingly.
//
// The specified path should not end by a separator.
//
......
package autority
package authority
import (
"crypto/rsa"
......@@ -50,13 +50,13 @@ func TestInitialize(t *testing.T) {
if _, err = os.Stat(keyPath); os.IsNotExist(err) {
t.Fatal("Private key file couldn't be found")
} else {
os.Remove(keyPath)
_ = os.Remove(keyPath)
}
if _, err = os.Stat(certPath); os.IsNotExist(err) {
t.Fatal("Root certificate file couldn't be found")
} else {
os.Remove(certPath)
_ = os.Remove(certPath)
}
}
......@@ -71,29 +71,8 @@ func ExampleInitialize() {
fmt.Println(err)
}
if _, err = os.Stat(keyPath); os.IsNotExist(err) {
fmt.Println("Private key file couldn't be found")
} else {
fmt.Println("Private key file has been found")
err2 := os.Remove(keyPath)
if err2 != nil {
fmt.Println(err2)
} else {
fmt.Println("Private key file has been deleted")
}
}
if _, err = os.Stat(certPath); os.IsNotExist(err) {
fmt.Println("Certificate file couldn't be found")
} else {
fmt.Println("Certificate file has been found")
err2 := os.Remove(certPath)
if err2 != nil {
fmt.Println(err2)
} else {
fmt.Println("Certificate file has been deleted")
}
}
checkFile(keyPath, "Private key")
checkFile(certPath, "Certificate")
// Output:
// Private key file has been found
......@@ -102,6 +81,20 @@ func ExampleInitialize() {
// Certificate file has been deleted
}
func checkFile(path, name string) {
if _, err := os.Stat(path); os.IsNotExist(err) {
fmt.Println(name + " file couldn't be found")
} else {
fmt.Println(name + " file has been found")
err = os.Remove(path)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(name + " file has been deleted")
}
}
}
func TestStart(t *testing.T) {
path := os.TempDir()
keyPath := filepath.Join(path, PkeyFileName)
......@@ -118,6 +111,6 @@ func TestStart(t *testing.T) {
t.Fatal("Data was not recovered from saved files")
}
os.Remove(keyPath)
os.Remove(certPath)
_ = os.Remove(keyPath)
_ = os.Remove(certPath)
}
......@@ -2,7 +2,7 @@ package main
import (
"dfss"
"dfss/dfssp/autority"
"dfss/dfssp/authority"
"flag"
"fmt"
"runtime"
......@@ -12,14 +12,14 @@ var (
verbose bool
path, country, org, unit, cn string
keySize, validity int
pid *autority.PlatformID
pid *authority.PlatformID
)
func init() {
flag.BoolVar(&verbose, "v", false, "Print verbose messages")
flag.StringVar(&path, "path", autority.GetHomeDir(), "Path for the platform's private key and root certificate")
flag.StringVar(&path, "path", authority.GetHomeDir(), "Path for the platform's private key and root certificate")
flag.StringVar(&country, "country", "France", "Country for the root certificate")
flag.StringVar(&org, "org", "DFSS", "Organization for the root certificate")
flag.StringVar(&unit, "unit", "INSA Rennes", "Organizational unit for the root certificate")
......@@ -58,14 +58,14 @@ func main() {
case "version":
fmt.Println("v"+dfss.Version, runtime.GOOS, runtime.GOARCH)
case "init":
err := autority.Initialize(keySize, validity, country, org, unit, cn, path)
err := authority.Initialize(keySize, validity, country, org, unit, cn, path)
if err != nil {
fmt.Println("An error occured during the initialization operation")
fmt.Println(err)
panic(err)
}
case "start":
pid, err := autority.Start(path)
pid, err := authority.Start(path)
if err != nil {
fmt.Println("An error occured during the start operation")
fmt.Println(err)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment