You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gpg_key_import.go 1.4KB

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