gitea源码

gpg_key_import.go 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2021 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package asymkey
  4. import (
  5. "context"
  6. "code.gitea.io/gitea/models/db"
  7. )
  8. // __________________ ________ ____ __.
  9. // / _____/\______ \/ _____/ | |/ _|____ ___.__.
  10. // / \ ___ | ___/ \ ___ | <_/ __ < | |
  11. // \ \_\ \| | \ \_\ \ | | \ ___/\___ |
  12. // \______ /|____| \______ / |____|__ \___ > ____|
  13. // \/ \/ \/ \/\/
  14. // .___ __
  15. // | | _____ ______ ____________/ |_
  16. // | |/ \\____ \ / _ \_ __ \ __\
  17. // | | Y Y \ |_> > <_> ) | \/| |
  18. // |___|__|_| / __/ \____/|__| |__|
  19. // \/|__|
  20. // This file contains functions related to the original import of a key
  21. // GPGKeyImport the original import of key
  22. type GPGKeyImport struct {
  23. KeyID string `xorm:"pk CHAR(16) NOT NULL"`
  24. Content string `xorm:"MEDIUMTEXT NOT NULL"`
  25. }
  26. func init() {
  27. db.RegisterModel(new(GPGKeyImport))
  28. }
  29. // GetGPGImportByKeyID returns the import public armored key by given KeyID.
  30. func GetGPGImportByKeyID(ctx context.Context, keyID string) (*GPGKeyImport, error) {
  31. key := new(GPGKeyImport)
  32. has, err := db.GetEngine(ctx).ID(keyID).Get(key)
  33. if err != nil {
  34. return nil, err
  35. } else if !has {
  36. return nil, ErrGPGKeyImportNotExist{keyID}
  37. }
  38. return key, nil
  39. }