From 3d148a9b232c3b661f44e81797251f081eea2d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 5 Aug 2019 17:08:30 +0200 Subject: [PATCH 1/3] Restore the return value of pkg/keyctl/*.ID to be int32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... to preserve the API as released in v3.0.0. Signed-off-by: Miloslav Trmač --- pkg/keyctl/key.go | 4 ++-- pkg/keyctl/keyring.go | 10 +++++----- pkg/keyctl/perm.go | 2 +- pkg/keyctl/sys_linux.go | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/keyctl/key.go b/pkg/keyctl/key.go index 0d42a8f1c1..e4396a9df7 100644 --- a/pkg/keyctl/key.go +++ b/pkg/keyctl/key.go @@ -19,8 +19,8 @@ type Key struct { } // ID returns the 32-bit kernel identifier for a specific key -func (k *Key) ID() int { - return int(k.id) +func (k *Key) ID() int32 { + return int32(k.id) } // Get the key's value as a byte slice diff --git a/pkg/keyctl/keyring.go b/pkg/keyctl/keyring.go index dd037840a8..a25085c60f 100644 --- a/pkg/keyctl/keyring.go +++ b/pkg/keyctl/keyring.go @@ -24,7 +24,7 @@ type keyring struct { // ID is unique 32-bit serial number identifiers for all Keys and Keyrings have. type ID interface { - ID() int + ID() int32 } // Add a new key to a keyring. The key can be searched for later by name. @@ -49,8 +49,8 @@ func (kr *keyring) Search(name string) (*Key, error) { } // ID returns the 32-bit kernel identifier of a keyring -func (kr *keyring) ID() int { - return int(kr.id) +func (kr *keyring) ID() int32 { + return int32(kr.id) } // SessionKeyring returns the current login session keyring @@ -65,12 +65,12 @@ func UserKeyring() (Keyring, error) { // Unlink an object from a keyring func Unlink(parent Keyring, child ID) error { - _, err := unix.KeyctlInt(unix.KEYCTL_UNLINK, child.ID(), parent.ID(), 0, 0) + _, err := unix.KeyctlInt(unix.KEYCTL_UNLINK, int(child.ID()), int(parent.ID()), 0, 0) return err } // Link a key into a keyring func Link(parent Keyring, child ID) error { - _, err := unix.KeyctlInt(unix.KEYCTL_LINK, child.ID(), parent.ID(), 0, 0) + _, err := unix.KeyctlInt(unix.KEYCTL_LINK, int(child.ID()), int(parent.ID()), 0, 0) return err } diff --git a/pkg/keyctl/perm.go b/pkg/keyctl/perm.go index 152b740047..ae9697149d 100644 --- a/pkg/keyctl/perm.go +++ b/pkg/keyctl/perm.go @@ -28,6 +28,6 @@ const ( // SetPerm sets the permissions on a key or keyring. func SetPerm(k ID, p KeyPerm) error { - err := unix.KeyctlSetperm(k.ID(), uint32(p)) + err := unix.KeyctlSetperm(int(k.ID()), uint32(p)) return err } diff --git a/pkg/keyctl/sys_linux.go b/pkg/keyctl/sys_linux.go index 80e6d6a065..eb7b50d162 100644 --- a/pkg/keyctl/sys_linux.go +++ b/pkg/keyctl/sys_linux.go @@ -10,10 +10,10 @@ import ( "golang.org/x/sys/unix" ) -type keyID int +type keyID int32 -func (id keyID) ID() int { - return int(id) +func (id keyID) ID() int32 { + return int32(id) } func newKeyring(id keyID) (*keyring, error) { From 64b622c1bc07d43b722223816a341c4f355470af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 5 Aug 2019 17:09:29 +0200 Subject: [PATCH 2/3] Remove pkg/keyctl/keyID.ID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is never called inside the package, and the type is never made available to external callers, so no other callers can exist. Signed-off-by: Miloslav Trmač --- pkg/keyctl/sys_linux.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/keyctl/sys_linux.go b/pkg/keyctl/sys_linux.go index eb7b50d162..196c827607 100644 --- a/pkg/keyctl/sys_linux.go +++ b/pkg/keyctl/sys_linux.go @@ -12,10 +12,6 @@ import ( type keyID int32 -func (id keyID) ID() int32 { - return int32(id) -} - func newKeyring(id keyID) (*keyring, error) { r1, err := unix.KeyctlGetKeyringID(int(id), true) if err != nil { From a0ed68ea6d33b1da99e47480943f32559dfbc31d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 5 Aug 2019 17:12:28 +0200 Subject: [PATCH 3/3] Add a deprecation notice to pkg/keyctl. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We neither need nor want to expose and maintain the keyring as an independent public API. Signed-off-by: Miloslav Trmač --- pkg/keyctl/keyring.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/keyctl/keyring.go b/pkg/keyctl/keyring.go index a25085c60f..6e029c9235 100644 --- a/pkg/keyctl/keyring.go +++ b/pkg/keyctl/keyring.go @@ -5,6 +5,9 @@ // +build linux // Package keyctl is a Go interface to linux kernel keyrings (keyctl interface) +// +// Deprecated: Most callers should use either golang.org/x/sys/unix directly, +// or the original (and more extensive) github.com/jsipprell/keyctl . package keyctl import (