encrypt.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package apis
  15. import (
  16. "yunion.io/x/onecloud/pkg/util/seclib2"
  17. )
  18. type SEncryptInfo struct {
  19. Id string `json:"id"`
  20. Name string `json:"name"`
  21. Key string `json:"key"`
  22. Alg seclib2.TSymEncAlg `json:"alg"`
  23. }
  24. type EncryptedResourceCreateInput struct {
  25. // 是否新建密钥
  26. EncryptKeyNew *bool `json:"encrypt_key_new"`
  27. // 新建密钥算法
  28. EncryptKeyAlg *string `json:"encrypt_key_alg"`
  29. // 加密密钥的ID
  30. EncryptKeyId *string `json:"encrypt_key_id"`
  31. // 加密密钥的用户ID
  32. EncryptKeyUserId *string `json:"encrypt_key_user_id"`
  33. }
  34. func (input EncryptedResourceCreateInput) NeedEncrypt() bool {
  35. return (input.EncryptKeyId != nil && len(*input.EncryptKeyId) > 0) || (input.EncryptKeyNew != nil && *input.EncryptKeyNew)
  36. }
  37. type EncryptedResourceDetails struct {
  38. // 秘钥名称
  39. EncryptKey string `json:"encrypt_key"`
  40. // 加密算法,aes-256 or sm4
  41. EncryptAlg string `json:"encrypt_alg"`
  42. // 密钥用户
  43. EncryptKeyUser string `json:"encrypt_key_user"`
  44. // 密钥用户ID
  45. EncryptKeyUserId string `json:"encrypt_key_user_id"`
  46. // 密钥用户域
  47. EncryptKeyUserDomain string `json:"encrypt_key_user_domain"`
  48. // 密钥用户域ID
  49. EncryptKeyUserDomainId string `json:"encrypt_key_user_domain_id"`
  50. }