Skip to content

Commit 76ec0a5

Browse files
committed
func_thidcard: remove space from thidc data
1 parent 59fb625 commit 76ec0a5

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

func_thidcard.go

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ func ThIDCardCID(card Transmitter, opt ...OptThIDCard) (string, error) {
3737
o(&cfg)
3838
}
3939

40-
cid, err := APDUGetRsp(card, APDUThaiIDCardCID)
40+
resp, err := APDUGetRsp(card, APDUThaiIDCardCID)
41+
resp = []byte(strings.Replace(string(resp), " ", "", -1))
42+
resp = bytes.Replace(resp, []byte("\000"), nil, -1)
4143
if err != nil {
4244
return "", err
4345
}
46+
cid := resp
4447

4548
return thIDCardMutateString(string(cid), cfg)
4649
}
@@ -52,10 +55,13 @@ func ThIDCardFullnameEn(card Transmitter, opt ...OptThIDCard) (string, error) {
5255
o(&cfg)
5356
}
5457

55-
fullnameEN, err := APDUGetRsp(card, APDUThaiIDCardFullnameEn)
58+
resp, err := APDUGetRsp(card, APDUThaiIDCardFullnameEn)
59+
resp = []byte(strings.Replace(string(resp), " ", "", -1))
60+
resp = bytes.Replace(resp, []byte("\000"), nil, -1)
5661
if err != nil {
5762
return "", err
5863
}
64+
fullnameEN := resp
5965

6066
return thIDCardMutateString(string(fullnameEN), cfg)
6167
}
@@ -67,10 +73,13 @@ func ThIDCardFullnameTh(card Transmitter, opt ...OptThIDCard) (string, error) {
6773
o(&cfg)
6874
}
6975

70-
fullnameTH, err := APDUGetRsp(card, APDUThaiIDCardFullnameTh)
76+
resp, err := APDUGetRsp(card, APDUThaiIDCardFullnameTh)
77+
resp = []byte(strings.Replace(string(resp), " ", "", -1))
78+
resp = bytes.Replace(resp, []byte("\000"), nil, -1)
7179
if err != nil {
7280
return "", err
7381
}
82+
fullnameTH := resp
7483

7584
return thIDCardMutateString(string(fullnameTH), cfg)
7685
}
@@ -82,10 +91,13 @@ func ThIDCardBirth(card Transmitter, opt ...OptThIDCard) (string, error) {
8291
o(&cfg)
8392
}
8493

85-
birth, err := APDUGetRsp(card, APDUThaiIDCardBirth)
94+
resp, err := APDUGetRsp(card, APDUThaiIDCardBirth)
95+
resp = []byte(strings.Replace(string(resp), " ", "", -1))
96+
resp = bytes.Replace(resp, []byte("\000"), nil, -1)
8697
if err != nil {
8798
return "", err
8899
}
100+
birth := resp
89101

90102
return thIDCardMutateString(string(birth), cfg)
91103
}
@@ -97,10 +109,13 @@ func ThIDCardGender(card Transmitter, opt ...OptThIDCard) (string, error) {
97109
o(&cfg)
98110
}
99111

100-
gender, err := APDUGetRsp(card, APDUThaiIDCardGender)
112+
resp, err := APDUGetRsp(card, APDUThaiIDCardGender)
113+
resp = []byte(strings.Replace(string(resp), " ", "", -1))
114+
resp = bytes.Replace(resp, []byte("\000"), nil, -1)
101115
if err != nil {
102116
return "", err
103117
}
118+
gender := resp
104119

105120
return thIDCardMutateString(string(gender), cfg)
106121
}
@@ -131,12 +146,15 @@ func ThIDCardIssueDate(card Transmitter, opt ...OptThIDCard) (string, error) {
131146
o(&cfg)
132147
}
133148

134-
issuer, err := APDUGetRsp(card, APDUThaiIDCardIssuedate)
149+
resp, err := APDUGetRsp(card, APDUThaiIDCardIssuedate)
150+
resp = []byte(strings.Replace(string(resp), " ", "", -1))
151+
resp = bytes.Replace(resp, []byte("\000"), nil, -1)
135152
if err != nil {
136153
return "", err
137154
}
155+
issuerDate := resp
138156

139-
return thIDCardMutateString(string(issuer), cfg)
157+
return thIDCardMutateString(string(issuerDate), cfg)
140158
}
141159

142160
//ThIDCardExpireDate get expire date from Thai national ID smart card.
@@ -146,12 +164,15 @@ func ThIDCardExpireDate(card Transmitter, opt ...OptThIDCard) (string, error) {
146164
o(&cfg)
147165
}
148166

149-
expire, err := APDUGetRsp(card, APDUThaiIDCardExpiredate)
167+
resp, err := APDUGetRsp(card, APDUThaiIDCardExpiredate)
168+
resp = []byte(strings.Replace(string(resp), " ", "", -1))
169+
resp = bytes.Replace(resp, []byte("\000"), nil, -1)
150170
if err != nil {
151171
return "", err
152172
}
173+
expireDate := resp
153174

154-
return thIDCardMutateString(string(expire), cfg)
175+
return thIDCardMutateString(string(expireDate), cfg)
155176
}
156177

157178
//ThIDCardAddress get address from Thai national ID smart card.
@@ -161,10 +182,13 @@ func ThIDCardAddress(card Transmitter, opt ...OptThIDCard) (string, error) {
161182
o(&cfg)
162183
}
163184

164-
address, err := APDUGetRsp(card, APDUThaiIDCardAddress)
185+
resp, err := APDUGetRsp(card, APDUThaiIDCardAddress)
186+
resp = []byte(strings.Replace(string(resp), " ", "", -1))
187+
resp = bytes.Replace(resp, []byte("\000"), nil, -1)
165188
if err != nil {
166189
return "", err
167190
}
191+
address := resp
168192

169193
return thIDCardMutateString(string(address), cfg)
170194
}

0 commit comments

Comments
 (0)