From 8fde918d981e9229b43fc6045b259a1db31cf1f4 Mon Sep 17 00:00:00 2001 From: xuri Date: Tue, 31 May 2022 11:05:10 +0800 Subject: This update docs and tests for workbook encryption --- crypt.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'crypt.go') diff --git a/crypt.go b/crypt.go index 65d5dae..239208d 100644 --- a/crypt.go +++ b/crypt.go @@ -143,15 +143,10 @@ func Decrypt(raw []byte, opt *Options) (packageBuf []byte, err error) { if err != nil || mechanism == "extensible" { return } - switch mechanism { - case "agile": + if mechanism == "agile" { return agileDecrypt(encryptionInfoBuf, encryptedPackageBuf, opt) - case "standard": - return standardDecrypt(encryptionInfoBuf, encryptedPackageBuf, opt) - default: - err = ErrUnsupportedEncryptMechanism } - return + return standardDecrypt(encryptionInfoBuf, encryptedPackageBuf, opt) } // Encrypt API encrypt data with the password. @@ -1112,7 +1107,7 @@ func (c *cfb) writeDirectoryEntry(propertyCount, customSectID, size int) []byte return storage.stream } -// writeMSAT provides a function to write compound file sector allocation +// writeMSAT provides a function to write compound file master sector allocation // table. func (c *cfb) writeMSAT(MSATBlocks, SATBlocks int, MSAT []int) []int { if MSATBlocks > 0 { @@ -1129,19 +1124,19 @@ func (c *cfb) writeMSAT(MSATBlocks, SATBlocks int, MSAT []int) []int { } MSAT = append(MSAT, -1) } - } else { - for i := 0; i < 109; i++ { - if i < SATBlocks { - MSAT = append(MSAT, i) - continue - } - MSAT = append(MSAT, -1) + return MSAT + } + for i := 0; i < 109; i++ { + if i < SATBlocks { + MSAT = append(MSAT, i) + continue } + MSAT = append(MSAT, -1) } return MSAT } -// writeSAT provides a function to write compound file master sector allocation +// writeSAT provides a function to write compound file sector allocation // table. func (c *cfb) writeSAT(MSATBlocks, SATBlocks, SSATBlocks, directoryBlocks, fileBlocks, streamBlocks int, SAT []int) (int, []int) { var blocks int -- cgit v1.2.1