Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xuri
excelize
提交
8fde918d
excelize
项目概览
xuri
/
excelize
通知
13
Star
2
Fork
4
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
excelize
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
已验证
提交
8fde918d
编写于
5月 31, 2022
作者:
xurime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
This update docs and tests for workbook encryption
上级
7a6d5f5e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
28 addition
and
17 deletion
+28
-17
.gitignore
.gitignore
+1
-1
crypt.go
crypt.go
+11
-16
crypt_test.go
crypt_test.go
+13
-0
excelize.go
excelize.go
+1
-0
stream_test.go
stream_test.go
+2
-0
未找到文件。
.gitignore
浏览文件 @
8fde918d
...
...
@@ -5,7 +5,7 @@ test/Test*.xlsx
test/Test*.xltm
test/Test*.xltx
# generated files
test/
BadEncrypt
.xlsx
test/
Encryption*
.xlsx
test/BadWorkbook.SaveAsEmptyStruct.xlsx
test/*.png
test/excelize-*
...
...
crypt.go
浏览文件 @
8fde918d
...
...
@@ -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
...
...
crypt_test.go
浏览文件 @
8fde918d
...
...
@@ -12,6 +12,7 @@
package
excelize
import
(
"io/ioutil"
"path/filepath"
"strings"
"testing"
...
...
@@ -30,6 +31,13 @@ func TestEncrypt(t *testing.T) {
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
"SECRET"
,
cell
)
assert
.
NoError
(
t
,
f
.
Close
())
// Test decrypt spreadsheet with unsupported encrypt mechanism
raw
,
err
:=
ioutil
.
ReadFile
(
filepath
.
Join
(
"test"
,
"encryptAES.xlsx"
))
assert
.
NoError
(
t
,
err
)
raw
[
2050
]
=
3
_
,
err
=
Decrypt
(
raw
,
&
Options
{
Password
:
"password"
})
assert
.
EqualError
(
t
,
err
,
ErrUnsupportedEncryptMechanism
.
Error
())
// Test encrypt spreadsheet with invalid password
assert
.
EqualError
(
t
,
f
.
SaveAs
(
filepath
.
Join
(
"test"
,
"Encryption.xlsx"
),
Options
{
Password
:
strings
.
Repeat
(
"*"
,
MaxFieldLength
+
1
)}),
ErrPasswordLengthInvalid
.
Error
())
// Test encrypt spreadsheet with new password
...
...
@@ -51,6 +59,11 @@ func TestEncryptionMechanism(t *testing.T) {
assert
.
EqualError
(
t
,
err
,
ErrUnknownEncryptMechanism
.
Error
())
}
func
TestEncryptionWriteDirectoryEntry
(
t
*
testing
.
T
)
{
cfb
:=
cfb
{}
assert
.
Equal
(
t
,
1536
,
len
(
cfb
.
writeDirectoryEntry
(
0
,
0
,
-
1
)))
}
func
TestHashing
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
hashing
(
"unsupportedHashAlgorithm"
,
[]
byte
{}),
[]
byte
(
nil
))
}
...
...
excelize.go
浏览文件 @
8fde918d
...
...
@@ -93,6 +93,7 @@ type Options struct {
// return
// }
//
// Close the file by Close function after opening the spreadsheet.
func
OpenFile
(
filename
string
,
opt
...
Options
)
(
*
File
,
error
)
{
file
,
err
:=
os
.
Open
(
filepath
.
Clean
(
filename
))
if
err
!=
nil
{
...
...
stream_test.go
浏览文件 @
8fde918d
...
...
@@ -129,6 +129,8 @@ func TestStreamWriter(t *testing.T) {
}
assert
.
NoError
(
t
,
rows
.
Close
())
assert
.
Equal
(
t
,
2559558
,
cells
)
// Save spreadsheet with password.
assert
.
NoError
(
t
,
file
.
SaveAs
(
filepath
.
Join
(
"test"
,
"EncryptionTestStreamWriter.xlsx"
),
Options
{
Password
:
"password"
}))
assert
.
NoError
(
t
,
file
.
Close
())
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录