from flask_marshmallow import Marshmallow from marshmallow import fields, post_load ma = Marshmallow() class GenLabelForm: """ 生成密码标签请求体 """ def __init__(self, info): self.info = info class GenLabelResp: """ 生成密码标签响应体 """ def __init__(self, code, msg, label, cert): self.code = code self.msg = msg self.label = label self.cert = cert class VerifyLabelForm: """ 验证密码标签请求体 """ def __init__(self, label, info, cert): self.label = label self.info = info self.cert = cert class VerifyLabelResp: """ 验证密码标签响应体 """ def __init__(self, code, msg): self.msg = msg self.code = code # 定义 Owner 类 class Owner: def __init__(self, name, id): self.name = name self.id = id # 定义 Info 类 class Info: def __init__(self, owner, model): self.owner = owner self.model = model # 定义 Model 类 class Model: def __init__(self, name, id, version, date): self.name = name self.id = id self.version = version self.date = date class VerifySignatureForm: """ 验签功能请求体 """ def __init__(self, original, signature, cert): self.original = original self.signature = signature self.cert = cert # 定义 OwnerSchema class OwnerSchema(ma.Schema): name = fields.String() id = fields.String() @post_load def make_owner(self, object, **kwargs): return Owner(**object) # 定义 ModelSchema class ModelSchema(ma.Schema): name = fields.String() id = fields.String() version = fields.String() date = fields.String() @post_load def make_model(self, object, **kwargs): return Model(**object) # 定义 InfoSchema class InfoSchema(ma.Schema): owner = fields.Nested(OwnerSchema) model = fields.Nested(ModelSchema) @post_load def make_info(self, object, **kwargs): return Info(**object) class GenLabelFormSchema(ma.Schema): info = fields.Nested(InfoSchema) @post_load def make_label(self, object, **kwargs): return GenLabelForm(**object) class GenLabelRespSchema(ma.Schema): code = fields.Integer() msg = fields.String() label = fields.String() cert = fields.String() @post_load def make_label_resp(self, object, **kwargs): return GenLabelResp(**object) class VerifyLabelFormSchema(ma.Schema): label = fields.String() info = fields.String() cert = fields.String() @post_load def make_verify_label(self, object, **kwargs): return VerifyLabelForm(**object) class VerifyLabelRespSchema(ma.Schema): code = fields.Integer() msg = fields.String() @post_load def make_verify_label_resp(self, object, **kwargs): return VerifyLabelResp(**object) class VerifySignatureFormSchema(ma.Schema): original = fields.String() signature = fields.String() cert = fields.String() @post_load def make_verify_signature(self, object, **kwargs): return VerifySignatureForm(**object)