From eeaef585e29eb585f816389035cd3371b32bf956 Mon Sep 17 00:00:00 2001 From: Junjie Gao Date: Mon, 8 Jan 2024 16:34:25 +0800 Subject: [PATCH] Squashed commit of the following: commit 7698ae3008a84a9cd5f7c5a2ede0658a805b7e4b Author: Junjie Gao Date: Mon Jan 8 16:33:40 2024 +0800 test: add error case for encodeLength() Signed-off-by: Junjie Gao commit 0ff9d3ca746ae309a98a26631085b0a3e339a1de Author: Junjie Gao Date: Mon Jan 8 16:18:37 2024 +0800 test: add unit test Signed-off-by: Junjie Gao commit 43f94bb4ad4b0224af9c67ad508c158448b6e694 Author: Junjie Gao Date: Tue Jan 2 10:10:22 2024 +0800 fix: test Signed-off-by: Junjie Gao commit 1b83aa0663f670ee64230b1b7fef128c5878a3e6 Author: Junjie Gao Date: Tue Jan 2 10:08:55 2024 +0800 fix: resolve comment Signed-off-by: Junjie Gao commit 58545004fa4c1f66aead8292b66a8aa5b5de554b Author: Junjie Gao Date: Tue Dec 26 16:03:54 2023 +0800 fix: remove cms Signed-off-by: Junjie Gao commit 5614972e883512af6836a83d5ab6f28cd5bb4167 Author: Junjie Gao Date: Tue Dec 26 09:29:22 2023 +0800 feat: added cms Signed-off-by: Junjie Gao commit 548c4481e261832b642a494bca8c8116ae040c53 Author: Junjie Gao Date: Mon Dec 25 09:56:57 2023 +0800 fix: remove common errors Signed-off-by: Junjie Gao commit 9e8a32e34836447dbda3981b2b6681c2e2771517 Author: Junjie Gao Date: Mon Dec 25 09:55:36 2023 +0800 fix: update Signed-off-by: Junjie Gao commit bc72eb6c07c644829f58478006362d680f60d213 Author: Junjie Gao Date: Mon Dec 25 09:54:16 2023 +0800 fix: update Signed-off-by: Junjie Gao commit aee8248137b6605b69a0b24a24943239bc5b81b5 Author: Junjie Gao Date: Mon Dec 25 09:51:59 2023 +0800 fix: resolve comments Signed-off-by: Junjie Gao commit 49dd7a66d6d6c2e5abe88f67209dc1e5d94905a4 Author: Junjie Gao Date: Wed Dec 20 17:38:31 2023 +0800 fix: resolve comments Signed-off-by: Junjie Gao commit 148e0a940762024c08acf20b3d3e7d321f511ec6 Author: Junjie Gao Date: Thu Dec 7 16:53:24 2023 +0800 fix: update comment Signed-off-by: Junjie Gao commit 9f6e6b0acef27874d61e4759d03cd27cf6f2ee0b Author: Junjie Gao Date: Thu Dec 7 16:47:10 2023 +0800 fix: update test Signed-off-by: Junjie Gao commit 65bc051c1cc76885cd1c32f550a646fc658a3398 Author: Junjie Gao Date: Thu Dec 7 16:45:16 2023 +0800 fix: optimize test Signed-off-by: Junjie Gao commit afe0aec9eee2831e72e89ec4e37869a0fa7e93a3 Author: Junjie Gao Date: Thu Dec 7 16:03:10 2023 +0800 fix: add license Signed-off-by: Junjie Gao commit aebb36d8be3d3fc7a71b0521c65dfa23faad199d Author: Junjie Gao Date: Thu Dec 7 15:41:07 2023 +0800 test: add unit test Signed-off-by: Junjie Gao commit 69d5c49283e162321354d760717714cd4aa2626d Author: Junjie Gao Date: Wed Nov 29 16:52:49 2023 +0800 Squashed commit of the following: commit 92406502fb0483cbeae370fb9095fb44067ed8a2 Merge: 0c1ec3b 4198690 Author: Junjie Gao Date: Wed Aug 9 17:07:34 2023 +0800 Merge pull request #1 from JeyJeyGao/feat/ans1 feat: convert BER to DER commit 419869027fb86f673f7c6d1c3c0031756aab1c6a Author: Junjie Gao Date: Wed Aug 9 09:14:29 2023 +0800 fix: simplify code Signed-off-by: Junjie Gao commit 75ce02d759d624645982c7fff493e672b7206ed5 Author: Junjie Gao Date: Mon Aug 7 20:33:08 2023 +0800 fix: added Conetent method for value interface Signed-off-by: Junjie Gao commit 7b823a9065a262ccc8c3226b139a1570f9d4cedf Author: Junjie Gao Date: Mon Aug 7 08:54:37 2023 +0800 fix: update code Signed-off-by: Junjie Gao commit 41ecec67b96772ff8db4e3378c953c64e83e8880 Author: Junjie Gao Date: Sun Aug 6 17:33:19 2023 +0800 fix: remove recusive call for encode() Signed-off-by: Junjie Gao commit 8f1a2af3c061df99f10edba3625569d788638261 Author: Junjie Gao Date: Fri Aug 4 13:40:09 2023 +0800 fix: remove unused value Signed-off-by: Junjie Gao commit 9b6a0c526189ea04d42a42da07e9c2349ec4c33a Author: Junjie Gao Date: Thu Aug 3 20:25:22 2023 +0800 fix: update code Signed-off-by: Junjie Gao commit 91a369137df03d255cf25894839c787ce9ce7785 Author: Junjie Gao Date: Thu Aug 3 20:11:28 2023 +0800 fix: create pointer instead of value to improve performance Signed-off-by: Junjie Gao commit 1465e3e1bb07a4de9f25c9b9fc89debdad34abe4 Author: Junjie Gao Date: Thu Aug 3 20:04:44 2023 +0800 fix: update code Signed-off-by: Junjie Gao commit 6524a9ce6f7363edcb001322815dd2e760fd361e Author: Junjie Gao Date: Thu Aug 3 19:53:27 2023 +0800 fix: update variable naming Signed-off-by: Junjie Gao commit 6cfbd9c03583d35fa8821f647d36c3d63f462d31 Author: Junjie Gao Date: Thu Aug 3 19:47:39 2023 +0800 fix: update code Signed-off-by: Junjie Gao commit b9c73bd63f4237480a299056df168d3099fd04d0 Author: Junjie Gao Date: Thu Aug 3 17:56:52 2023 +0800 fix: update to use rawContent instead of expectedLen Signed-off-by: Junjie Gao commit 3c994028abfb250a3eaa87b295548af7c21b902b Author: Junjie Gao Date: Thu Aug 3 16:45:09 2023 +0800 fix: update comment Signed-off-by: Junjie Gao commit f4dc95f6a97ca31a2ebe963a7844a2c0b6ef87c8 Author: Junjie Gao Date: Thu Aug 3 16:41:57 2023 +0800 fix: resolve comment Signed-off-by: Junjie Gao commit f91631640843e1dd48a3ce13bb7b06e73a16429b Author: Junjie Gao Date: Thu Aug 3 16:40:37 2023 +0800 fix: update code Signed-off-by: Junjie Gao commit 22afdf81b95eb45e4767d61b35e6fe1218d8d248 Author: Junjie Gao Date: Thu Aug 3 16:34:34 2023 +0800 fix: resolve comment Signed-off-by: Junjie Gao commit edb729cb1628ba2c514abfeebd02cd002fa618a0 Author: Junjie Gao Date: Thu Aug 3 16:32:47 2023 +0800 fix: resolve comment Signed-off-by: Junjie Gao commit a8ba0ff99ce35a252af4e30c9b64927d27d11354 Author: Junjie Gao Date: Thu Aug 3 16:26:29 2023 +0800 fix: update code Signed-off-by: Junjie Gao commit bc18cae59daa3700b49503c46bd6555634c599e5 Author: Junjie Gao Date: Thu Aug 3 16:14:57 2023 +0800 fix: resolve comments Signed-off-by: Junjie Gao commit 643f3886ebfb1f75af4b3572d4dc93bbdc151f3c Author: Junjie Gao Date: Thu Aug 3 09:17:39 2023 +0800 fix: update comment Signed-off-by: Junjie Gao commit b5d5131b5ebf32b6901d41546b7dac75d09f9b5b Author: Junjie Gao Date: Thu Aug 3 09:15:23 2023 +0800 fix: expectedLen == 0 should continue Signed-off-by: Junjie Gao commit 234574046999798f70cdead8232446b71bb23ff1 Author: Junjie Gao Date: Wed Aug 2 13:01:38 2023 +0800 fix: added copyright Signed-off-by: Junjie Gao commit 936ba2bc9a578b8ace72b4976e561f05213860e1 Author: Junjie Gao Date: Wed Aug 2 11:36:02 2023 +0800 fix: remove recusive decoding Signed-off-by: Junjie Gao commit 4fd944a74330254fc3e9805cd349e40b3afebc86 Author: Junjie Gao Date: Tue Aug 1 21:50:10 2023 +0800 fix: remove readOnlySlice Signed-off-by: Junjie Gao commit efa75756326adcf8b1bb2cfedd2b31c4d7a9f5e6 Author: Junjie Gao Date: Tue Aug 1 09:38:57 2023 +0800 fix: update decodeIdentifier function name Signed-off-by: Junjie Gao commit cbce4c135f14caa3ca73ea7ba5680208c62ef9e7 Author: Junjie Gao Date: Tue Aug 1 09:25:34 2023 +0800 fix: update code Signed-off-by: Junjie Gao commit 45480e5e93508e433fffe6b23ee3a6685277b3aa Author: Junjie Gao Date: Mon Jul 31 21:22:20 2023 +0800 fix: update code Signed-off-by: Junjie Gao commit b3de155b8866f3ceb0a0e6b8ff258ef036efee73 Author: Junjie Gao Date: Mon Jul 31 20:51:48 2023 +0800 fix: set non-exportable type Signed-off-by: Junjie Gao commit 5dea9e5d1c3e44b8837928c164833df4c6a9a464 Author: Junjie Gao Date: Mon Jul 31 20:44:50 2023 +0800 feat: asn.1 first version Signed-off-by: Junjie Gao Signed-off-by: Junjie Gao Signed-off-by: Junjie Gao --- .../crypto/cms/encoding/ber/common_test.go | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/internal/crypto/cms/encoding/ber/common_test.go b/internal/crypto/cms/encoding/ber/common_test.go index 424a4da9..7331a107 100644 --- a/internal/crypto/cms/encoding/ber/common_test.go +++ b/internal/crypto/cms/encoding/ber/common_test.go @@ -15,6 +15,7 @@ package ber import ( "bytes" + "errors" "testing" ) @@ -91,3 +92,35 @@ func TestEncodedLengthSize(t *testing.T) { }) } } + +type secondErrorWriter struct { + count int +} + +func (ew *secondErrorWriter) WriteByte(p byte) (err error) { + ew.count += 1 + if ew.count == 2 { + return errors.New("write error") + } + return nil +} + +func TestEncodeLengthFailed(t *testing.T) { + t.Run("byte write error 1", func(t *testing.T) { + buf := &errorWriter{} + err := encodeLength(buf, 128) + if err == nil { + t.Error("encodeLength() error = nil, want Error") + return + } + }) + + t.Run("byte write error 2", func(t *testing.T) { + buf := &secondErrorWriter{} + err := encodeLength(buf, 128) + if err == nil { + t.Error("encodeLength() error = nil, want Error") + return + } + }) +}