Skip to content

Commit 978c99e

Browse files
committed
chang to property
1 parent a319df2 commit 978c99e

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/gmalglib/coremodule.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ static PyObject* PySM2_generate_keypair(PySM2Object* self, PyObject* Py_UNUSED(a
699699
return Py_BuildValue("y#y#", (char*)sk, (Py_ssize_t)SM2_SK_LENGTH, pk, (Py_ssize_t)SM2_GET_PK_LENGTH(self->sm2.pc_mode));
700700
}
701701

702-
static PyObject* PySM2_get_entity_info(PySM2Object* self, PyObject* Py_UNUSED(args))
702+
static PyObject* PySM2_entity_info_getter(PySM2Object* self, PyObject* Py_UNUSED(args))
703703
{
704704
uint8_t entity_info[SM2_ENTITYINFO_LENGTH] = { 0 };
705705
if (SM2_GetEntityInfo(&self->sm2, entity_info) != 0)
@@ -1023,14 +1023,18 @@ static PyObject* PySM2_end_key_exchange(PySM2Object* self, PyObject* args, PyObj
10231023
return ret;
10241024
}
10251025

1026+
static PyGetSetDef py_getset_def_SM2[] = {
1027+
{"entity_info", (getter)PySM2_entity_info_getter, NULL, PyDoc_STR("Entity info."), NULL},
1028+
{NULL}
1029+
};
1030+
10261031
static PyMethodDef py_methods_def_SM2[] = {
10271032
{"is_sk_valid", (PyCFunction)PySM2_is_sk_valid, METH_VARARGS | METH_KEYWORDS | METH_STATIC, PyDoc_STR("Check sk is valid.")},
10281033
{"is_pk_valid", (PyCFunction)PySM2_is_pk_valid, METH_VARARGS | METH_KEYWORDS | METH_STATIC, PyDoc_STR("Check pk is valid.")},
10291034
{"is_keypair", (PyCFunction)PySM2_is_keypair, METH_VARARGS | METH_KEYWORDS | METH_STATIC, PyDoc_STR("Check if a valid keypair.")},
10301035
{"get_pk", (PyCFunction)PySM2_get_pk, METH_VARARGS | METH_KEYWORDS | METH_STATIC, PyDoc_STR("Get public key bytes.")},
10311036
{"convert_pk", (PyCFunction)PySM2_convert_pk, METH_VARARGS | METH_KEYWORDS | METH_STATIC, PyDoc_STR("Convert public key bytes to other pc_mode.")},
10321037
{"generate_keypair", (PyCFunction)PySM2_generate_keypair, METH_NOARGS, PyDoc_STR("Generate key pair.")},
1033-
{"get_entity_info", (PyCFunction)PySM2_get_entity_info, METH_NOARGS, PyDoc_STR("Get entity info.")},
10341038
{"sign_digest", (PyCFunction)PySM2_sign_digest, METH_VARARGS | METH_KEYWORDS, PyDoc_STR("Sign on digest.")},
10351039
{"verify_digest", (PyCFunction)PySM2_verify_digest, METH_VARARGS | METH_KEYWORDS, PyDoc_STR("Verify on digest.")},
10361040
{"sign", (PyCFunction)PySM2_sign, METH_VARARGS | METH_KEYWORDS, PyDoc_STR("Sign on full message.")},
@@ -1055,6 +1059,7 @@ static PyTypeObject py_type_SM2 = {
10551059
.tp_clear = (inquiry)PySM2_clear,
10561060
.tp_init = (initproc)PySM2_init,
10571061
.tp_methods = py_methods_def_SM2,
1062+
.tp_getset = py_getset_def_SM2
10581063
};
10591064

10601065
static int PyModule_AddSM2(PyObject* py_module)

src/gmalglib/sm2.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ class SM2:
106106
rnd_fn: 可选的用于产生指定长度随机字节函数.
107107
"""
108108

109+
@property
110+
def entity_info(self) -> Optional[bytes]:
111+
"""获取实体信息."""
112+
109113
def generate_keypair(self) -> Tuple[bytes, bytes]:
110114
"""生成密钥对.
111115
@@ -114,9 +118,6 @@ class SM2:
114118
pk: 公钥.
115119
"""
116120

117-
def get_entity_info(self) -> bytes:
118-
"""获取实体信息."""
119-
120121
def sign_digest(self, digest: bytes) -> bytes:
121122
"""对摘要进行签名."""
122123

src/gmalglib/wrapped.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def sm2_generate_keypair(pc_mode: __T.Literal["raw", "compress", "mix"] = "raw")
9797
def sm2_get_entity_info(pk: bytes, uid: bytes = __sm2.SM2_DEFAULT_UID) -> bytes:
9898
"""获取实体信息."""
9999

100-
return __sm2.SM2(pk=pk, uid=uid).get_entity_info()
100+
return __sm2.SM2(pk=pk, uid=uid).entity_info
101101

102102

103103
def sm2_sign_digest(sk: bytes, digest: bytes, uid: bytes = __sm2.SM2_DEFAULT_UID) -> bytes:

0 commit comments

Comments
 (0)