Skip to content

Commit

Permalink
Merge pull request #676 from mtrmac/keyctl-followup
Browse files Browse the repository at this point in the history
Follow-up to #675
  • Loading branch information
vrothberg authored Aug 5, 2019
2 parents dd01136 + a0ed68e commit 04d8b0f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkg/keyctl/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions pkg/keyctl/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -24,7 +27,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.
Expand All @@ -49,8 +52,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
Expand All @@ -65,12 +68,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
}
2 changes: 1 addition & 1 deletion pkg/keyctl/perm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 1 addition & 5 deletions pkg/keyctl/sys_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import (
"golang.org/x/sys/unix"
)

type keyID int

func (id keyID) ID() int {
return int(id)
}
type keyID int32

func newKeyring(id keyID) (*keyring, error) {
r1, err := unix.KeyctlGetKeyringID(int(id), true)
Expand Down

0 comments on commit 04d8b0f

Please sign in to comment.