1
/* Copyright (C) 2015 Canonical Ltd.
3
* This file is part of go-trust-store.
5
* go-trust-store is free software: you can redistribute it and/or modify it
6
* under the terms of the GNU Lesser General Public License version 3, as
7
* published by the Free Software Foundation.
9
* go-trust-store is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with go-trust-store. If not, see <http://www.gnu.org/licenses/>.
17
* Authored by: Kyle Fazzari <kyle@canonical.com>
22
// #include <stdlib.h>
23
// #include <sys/types.h>
24
// #include "request_shim.h"
33
// Feature represents a trusted-helper-specific feature to which access is
34
// requested via the trust store.
37
// Request represents a timestamped permission request and answer to be stored
38
// in the trust store.
46
// FromShim converts a shim request into a Request.
47
func (request *Request) FromShim(shimPointer unsafe.Pointer) {
48
shim := (*C.Request)(shimPointer)
50
request.Answer = AnswerFromShim(int(shim.answer))
51
request.From = C.GoString(shim.from)
52
request.Feature = Feature(shim.feature)
53
request.When = time.Unix(int64(shim.when.seconds),
54
int64(shim.when.nanoseconds))
57
// ToShim converts a Request into a shim request.
58
func (request Request) ToShim() unsafe.Pointer {
59
shim := new(C.Request)
61
shim.answer = C.Answer(request.Answer.ToShim())
62
shim.from = C.CString(request.From)
63
shim.feature = C.uint64_t(request.Feature)
64
shim.when.seconds = C.int64_t(request.When.Unix())
65
shim.when.nanoseconds = C.int32_t(request.When.Nanosecond())
67
runtime.SetFinalizer(shim, destroyRequestShim)
69
return unsafe.Pointer(shim)
72
// destroyRequestShim frees the resources of a shim request.
73
func destroyRequestShim(shim *C.Request) {
74
C.free(unsafe.Pointer(shim.from))