secret_domain.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. from flask_marshmallow import Marshmallow
  2. from marshmallow import fields, post_load
  3. ma = Marshmallow()
  4. class GenLabelForm:
  5. """
  6. 生成密码标签请求体
  7. """
  8. def __init__(self, info):
  9. self.info = info
  10. class GenLabelResp:
  11. """
  12. 生成密码标签响应体
  13. """
  14. def __init__(self, code, msg, label, cert):
  15. self.code = code
  16. self.msg = msg
  17. self.label = label
  18. self.cert = cert
  19. class VerifyLabelForm:
  20. """
  21. 验证密码标签请求体
  22. """
  23. def __init__(self, label, info, cert):
  24. self.label = label
  25. self.info = info
  26. self.cert = cert
  27. class VerifyLabelResp:
  28. """
  29. 验证密码标签响应体
  30. """
  31. def __init__(self, code, msg):
  32. self.msg = msg
  33. self.code = code
  34. # 定义 Owner 类
  35. class Owner:
  36. def __init__(self, name, id):
  37. self.name = name
  38. self.id = id
  39. # 定义 Info 类
  40. class Info:
  41. def __init__(self, owner, model):
  42. self.owner = owner
  43. self.model = model
  44. # 定义 Model 类
  45. class Model:
  46. def __init__(self, name, id, version, date):
  47. self.name = name
  48. self.id = id
  49. self.version = version
  50. self.date = date
  51. class VerifySignatureForm:
  52. """
  53. 验签功能请求体
  54. """
  55. def __init__(self, original, signature, cert):
  56. self.original = original
  57. self.signature = signature
  58. self.cert = cert
  59. # 定义 OwnerSchema
  60. class OwnerSchema(ma.Schema):
  61. name = fields.String()
  62. id = fields.String()
  63. @post_load
  64. def make_owner(self, object, **kwargs):
  65. return Owner(**object)
  66. # 定义 ModelSchema
  67. class ModelSchema(ma.Schema):
  68. name = fields.String()
  69. id = fields.String()
  70. version = fields.String()
  71. date = fields.String()
  72. @post_load
  73. def make_model(self, object, **kwargs):
  74. return Model(**object)
  75. # 定义 InfoSchema
  76. class InfoSchema(ma.Schema):
  77. owner = fields.Nested(OwnerSchema)
  78. model = fields.Nested(ModelSchema)
  79. @post_load
  80. def make_info(self, object, **kwargs):
  81. return Info(**object)
  82. class GenLabelFormSchema(ma.Schema):
  83. info = fields.Nested(InfoSchema)
  84. @post_load
  85. def make_label(self, object, **kwargs):
  86. return GenLabelForm(**object)
  87. class GenLabelRespSchema(ma.Schema):
  88. code = fields.Integer()
  89. msg = fields.String()
  90. label = fields.String()
  91. cert = fields.String()
  92. @post_load
  93. def make_label_resp(self, object, **kwargs):
  94. return GenLabelResp(**object)
  95. class VerifyLabelFormSchema(ma.Schema):
  96. label = fields.String()
  97. info = fields.String()
  98. cert = fields.String()
  99. @post_load
  100. def make_verify_label(self, object, **kwargs):
  101. return VerifyLabelForm(**object)
  102. class VerifyLabelRespSchema(ma.Schema):
  103. code = fields.Integer()
  104. msg = fields.String()
  105. @post_load
  106. def make_verify_label_resp(self, object, **kwargs):
  107. return VerifyLabelResp(**object)
  108. class VerifySignatureFormSchema(ma.Schema):
  109. original = fields.String()
  110. signature = fields.String()
  111. cert = fields.String()
  112. @post_load
  113. def make_verify_signature(self, object, **kwargs):
  114. return VerifySignatureForm(**object)