aboutsummaryrefslogtreecommitdiff
path: root/info.go
blob: bbc5a10e49e54c4037b62a7b7b46e57cf8bd3c94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"os"
	"strings"

	"github.com/rfjakob/gocryptfs/internal/configfile"
	"github.com/rfjakob/gocryptfs/internal/contentenc"
	"github.com/rfjakob/gocryptfs/internal/exitcodes"
	"github.com/rfjakob/gocryptfs/internal/tlog"
)

// info pretty-prints the contents of the config file at "filename" for human
// consumption, stripping out sensitive data.
// This is called when you pass the "-info" option.
func info(filename string) {
	// Read from disk
	js, err := ioutil.ReadFile(filename)
	if err != nil {
		tlog.Fatal.Printf("Reading config file failed: %v", err)
		os.Exit(exitcodes.LoadConf)
	}
	// Unmarshal
	var cf configfile.ConfFile
	err = json.Unmarshal(js, &cf)
	if err != nil {
		tlog.Fatal.Printf("Failed to unmarshal config file")
		os.Exit(exitcodes.LoadConf)
	}
	if cf.Version != contentenc.CurrentVersion {
		tlog.Fatal.Printf("Unsupported on-disk format %d", cf.Version)
		os.Exit(exitcodes.LoadConf)
	}
	// Pretty-print
	fmt.Printf("Creator:      %s\n", cf.Creator)
	fmt.Printf("FeatureFlags: %s\n", strings.Join(cf.FeatureFlags, " "))
	fmt.Printf("EncryptedKey: %dB\n", len(cf.EncryptedKey))
	s := cf.ScryptObject
	fmt.Printf("ScryptObject: Salt=%dB N=%d R=%d P=%d KeyLen=%d\n",
		len(s.Salt), s.N, s.R, s.P, s.KeyLen)
}