From a683ab55245aa44ada5059f8e9816adbd94198ff Mon Sep 17 00:00:00 2001 From: Joe Richey Date: Thu, 2 Mar 2017 10:38:33 -0800 Subject: metadata: get and set policies from go This commit adds in the ability to get and set policy data from go using the GetPolicy and SetPolicy functions. This is done via a patch of the x/sys/unix package that exposes the filesystem encryption structures. Note that not all the fields of the PolicyData protocol buffer are needed to get and set policies. The wrapped_policy_keys are not used and will be written and read by other components of fscrypt. To run the policy tests, the environment variable BASE_TEST_DIR must be set to a directory for testing on a filesystem that supports encryption. Change-Id: I13b1d983356845f3ffc1945cedf53234218f32e5 --- util/errors.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'util/errors.go') diff --git a/util/errors.go b/util/errors.go index aafeadd..bd63ac8 100644 --- a/util/errors.go +++ b/util/errors.go @@ -22,6 +22,7 @@ package util import ( "fmt" "log" + "os" ) // InvalidInputF creates an error that should indicate either bad input from a @@ -48,3 +49,17 @@ func NeverError(err error) { log.Panicf("NeverError() check failed: %v", err) } } + +// UnderlyingError returns the underlying error for known os error types. +// From: src/os/error.go +func UnderlyingError(err error) error { + switch err := err.(type) { + case *os.PathError: + return err.Err + case *os.LinkError: + return err.Err + case *os.SyscallError: + return err.Err + } + return err +} -- cgit v1.2.3