key: Factor out some code.
key: Factor out some code.

This will make this little snippet of code more easily re-usable in my
next commit.

Change-Id: I0eabd16229f15049bb7dbc2e7541ef5dfe974b8c

aristanetworks/goarista,aristanetworks/goarista