func (s *KeyStore) OpenKeyRing(path string) (api.KeyRing, error) {
	ring := newKeyRing(s, path)
	err := s.readKeyRing(ring)
	if err != nil {
		return nil, err
	}
	return ring, nil
}
OpenKeyRing opens an existing key ring at given path.
package filesystem
import (
	"errors"
	"runtime"
	"strings"
	"time"
	keystoreV1 "github.com/cossacklabs/acra/keystore"
	"github.com/cossacklabs/acra/keystore/v2/keystore/api"
	"github.com/cossacklabs/acra/keystore/v2/keystore/asn1"
	"github.com/cossacklabs/acra/keystore/v2/keystore/crypto"
	"github.com/cossacklabs/acra/keystore/v2/keystore/filesystem/backend"
	"github.com/cossacklabs/acra/keystore/v2/keystore/signature"
	log "github.com/sirupsen/logrus"
)
const serviceName = "keystore"
var (
	ErrNotImplemented = errors.New("not implemented")
)
type KeyStore struct {
	encryptor crypto.KeyEncryptor
	notary    *signature.Notary
	log       *log.Entry
	fs        backend.Backend
}
func OpenDirectory(rootDir string, cryptosuite *crypto.KeyStoreSuite) (api.KeyStore, error) {
	backend, err := backend.OpenDirectoryBackend(rootDir)
	if err != nil {
		return nil, err
	}
	return CustomKeyStore(backend, cryptosuite)
}
func OpenDirectoryRW(rootDir string, cryptosuite *crypto.KeyStoreSuite) (api.MutableKeyStore, error) {
	backend, err := backend.CreateDirectoryBackend(rootDir)
	if err != nil {
		return nil, err
	}
	return CustomKeyStore(backend, cryptosuite)
}
func IsKeyDirectory(rootDir string) bool {
	return backend.CheckDirectoryVersion(rootDir) == nil
}
func NewInMemory(cryptosuite *crypto.KeyStoreSuite) (api.MutableKeyStore, error) {
	return CustomKeyStore(backend.NewInMemory(), cryptosuite)
}
func CustomKeyStore(backend backend.Backend, cryptosuite *crypto.KeyStoreSuite) (api.MutableKeyStore, error) {
	notary, err := signature.NewNotary(cryptosuite.SignatureAlgorithms)
	if err != nil {
		return nil, err
	}
	keystore := &KeyStore{
		encryptor: cryptosuite.KeyEncryptor,
		notary:    notary,
		fs:        backend,
		log: log.WithFields(log.Fields{
			"service": serviceName,
		}),
	}
	runtime.SetFinalizer(keystore, (*KeyStore).finalize)
	return keystore, nil
}
func (s *KeyStore) finalize() {
	s.log.Warn("Close() has not been called for a KeyStore")
	err := s.Close()
	if err != nil {
		s.log.WithError(err).Warn("finalizer failed to close KeyStore")
	}
}
func (s *KeyStore) Close() error {
	err := s.fs.Close()
	runtime.SetFinalizer(s, nil)
	return err
}