Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
51a09ebd
I
iSulad
项目概览
openeuler
/
iSulad
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
iSulad
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
51a09ebd
编写于
7月 20, 2020
作者:
L
lifeng68
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean code: remove unused sha256 functions
Signed-off-by:
N
lifeng68
<
lifeng68@huawei.com
>
上级
7820bb62
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
0 addition
and
221 deletion
+0
-221
src/utils/sha256/sha256.c
src/utils/sha256/sha256.c
+0
-205
src/utils/sha256/sha256.h
src/utils/sha256/sha256.h
+0
-16
未找到文件。
src/utils/sha256/sha256.c
浏览文件 @
51a09ebd
...
...
@@ -59,210 +59,6 @@ static bool stream_check_error(void *stream, bool isgzip)
return
false
;
}
int
stream_read
(
void
*
stream
,
int
fd
,
bool
isgzip
)
{
size_t
n
=
0
;
char
*
buffer
=
NULL
;
buffer
=
util_common_calloc_s
(
BLKSIZE
+
72
);
if
(
buffer
==
NULL
)
{
ERROR
(
"Malloc BLKSIZE memory error"
);
return
-
1
;
}
/* Read block. Take care for partial reads. */
while
(
1
)
{
if
(
isgzip
)
{
n
=
(
size_t
)
gzread
((
gzFile
)
stream
,
buffer
,
BLKSIZE
);
}
else
{
n
=
fread
(
buffer
,
1
,
BLKSIZE
,
(
FILE
*
)
stream
);
}
if
(
n
==
BLKSIZE
)
{
if
(
write
(
fd
,
buffer
,
BLKSIZE
)
==
-
1
)
{
ERROR
(
"Write pipe failed: %s"
,
strerror
(
errno
));
goto
free_out
;
}
n
=
0
;
continue
;
}
if
(
n
==
0
)
{
if
(
stream_check_error
(
stream
,
isgzip
))
{
goto
free_out
;
}
goto
end_send
;
}
if
(
stream_check_eof
(
stream
,
isgzip
))
{
goto
end_send
;
}
}
end_send:
/* Process any remaining bytes. */
if
(
n
>
0
)
{
if
(
write
(
fd
,
buffer
,
n
)
==
-
1
)
{
ERROR
(
"Write pipe_for_write failed: %s"
,
strerror
(
errno
));
goto
free_out
;
}
}
free
(
buffer
);
return
0
;
free_out:
free
(
buffer
);
return
-
1
;
}
static
int
sha256sum_calculate_parent_handle
(
pid_t
pid
,
int
pipe_for_read
[],
int
pipe_for_write
[],
bool
isfile
,
bool
isgzip
,
void
*
stream
,
char
*
buffer_out
,
size_t
len
)
{
ssize_t
size_pipe_read
;
close
(
pipe_for_read
[
1
]);
pipe_for_read
[
1
]
=
-
1
;
close
(
pipe_for_write
[
0
]);
pipe_for_write
[
0
]
=
-
1
;
if
(
isfile
)
{
int
ret
=
stream_read
((
gzFile
)
stream
,
pipe_for_write
[
1
],
isgzip
);
if
(
ret
!=
0
)
{
close
(
pipe_for_read
[
0
]);
pipe_for_read
[
0
]
=
-
1
;
close
(
pipe_for_write
[
1
]);
pipe_for_write
[
1
]
=
-
1
;
ERROR
(
"Read buffer error"
);
return
-
1
;
}
}
else
if
(
write
(
pipe_for_write
[
1
],
(
char
*
)
stream
,
len
)
==
-
1
)
{
close
(
pipe_for_read
[
0
]);
pipe_for_read
[
0
]
=
-
1
;
close
(
pipe_for_write
[
1
]);
pipe_for_write
[
1
]
=
-
1
;
ERROR
(
"Write pipe_for_write failed: %s"
,
strerror
(
errno
));
return
-
1
;
}
close
(
pipe_for_write
[
1
]);
pipe_for_write
[
1
]
=
-
1
;
if
(
wait_for_pid
(
pid
))
{
char
buffer_errmsg
[
BUFSIZ
]
=
{
0
};
size_t
size_read
=
(
size_t
)
read
(
pipe_for_read
[
0
],
buffer_errmsg
,
BUFSIZ
);
if
(
size_read
!=
0
)
{
ERROR
(
"Sha256sum run error: %s"
,
buffer_errmsg
);
}
close
(
pipe_for_read
[
0
]);
pipe_for_read
[
0
]
=
-
1
;
return
-
1
;
}
size_pipe_read
=
read
(
pipe_for_read
[
0
],
buffer_out
,
SHA256_SIZE
);
close
(
pipe_for_read
[
0
]);
pipe_for_read
[
0
]
=
-
1
;
if
(
size_pipe_read
<=
0
)
{
ERROR
(
"Read sha256 buffer failed"
);
return
-
1
;
}
buffer_out
[
SHA256_SIZE
]
=
'\0'
;
return
0
;
}
int
sha256sum_calculate
(
void
*
stream
,
char
*
buffer_out
,
size_t
len
,
bool
isfile
,
bool
isgzip
)
{
int
ret
=
0
;
pid_t
pid
;
int
pipe_for_read
[
2
]
=
{
-
1
,
-
1
};
int
pipe_for_write
[
2
]
=
{
-
1
,
-
1
};
if
(
!
stream
||
!
buffer_out
)
{
ERROR
(
"Param Error"
);
ret
=
-
1
;
goto
out
;
}
if
(
pipe2
(
pipe_for_read
,
O_CLOEXEC
)
!=
0
)
{
ERROR
(
"Failed to create pipe"
);
ret
=
-
1
;
goto
out
;
}
if
(
pipe2
(
pipe_for_write
,
O_CLOEXEC
)
!=
0
)
{
ERROR
(
"Failed to create pipe"
);
ret
=
-
1
;
goto
out
;
}
pid
=
fork
();
if
(
pid
==
(
pid_t
)
-
1
)
{
ERROR
(
"Failed to fork()"
);
ret
=
-
1
;
close
(
pipe_for_read
[
0
]);
close
(
pipe_for_read
[
1
]);
close
(
pipe_for_write
[
0
]);
close
(
pipe_for_write
[
1
]);
goto
out
;
}
if
(
pid
==
(
pid_t
)
0
)
{
// child process, dup2 pipe_for_read[1] to stdout,
// pipe_for_write[1] to stdin
close
(
pipe_for_read
[
0
]);
close
(
pipe_for_write
[
1
]);
if
(
dup2
(
pipe_for_read
[
1
],
1
)
<
0
)
{
fprintf
(
stdout
,
"Dup fd error: %s"
,
strerror
(
errno
));
exit
(
EXIT_FAILURE
);
}
if
(
dup2
(
pipe_for_write
[
0
],
0
))
{
fprintf
(
stdout
,
"Dup fd error: %s"
,
strerror
(
errno
));
exit
(
EXIT_FAILURE
);
}
if
(
util_check_inherited
(
true
,
-
1
))
{
fprintf
(
stdout
,
"Failed to close fds."
);
exit
(
EXIT_FAILURE
);
}
execlp
(
"sha256sum"
,
"sha256sum"
,
NULL
);
fprintf
(
stdout
,
"Failed to exec sha256sum program"
);
exit
(
EXIT_FAILURE
);
}
ret
=
sha256sum_calculate_parent_handle
(
pid
,
pipe_for_read
,
pipe_for_write
,
isfile
,
isgzip
,
stream
,
buffer_out
,
len
);
out:
return
ret
;
}
char
*
sha256_digest
(
void
*
stream
,
bool
isgzip
)
{
int
ret
=
0
;
int
cnt
;
char
buffer_out
[
SHA256_SIZE
+
1
];
char
*
digest
=
NULL
;
if
(
stream
==
NULL
)
{
return
NULL
;
}
ret
=
sha256sum_calculate
(
stream
,
buffer_out
,
0
,
true
,
isgzip
);
if
(
ret
!=
0
)
{
return
NULL
;
}
digest
=
(
char
*
)
util_common_calloc_s
(
SHA256_SIZE
+
1
);
if
(
digest
==
NULL
)
{
return
NULL
;
}
digest
[
SHA256_SIZE
]
=
0
;
/* translate from binary to hex string */
for
(
cnt
=
0
;
cnt
<
SHA256_SIZE
;
++
cnt
)
{
digest
[
cnt
]
=
buffer_out
[
cnt
];
}
return
digest
;
}
char
*
sha256_digest_str
(
const
char
*
val
)
{
SHA256_CTX
ctx
;
...
...
@@ -521,4 +317,3 @@ char *without_sha256_prefix(char *digest)
return
digest
+
strlen
(
SHA256_PREFIX
);
}
src/utils/sha256/sha256.h
浏览文件 @
51a09ebd
...
...
@@ -24,22 +24,6 @@
extern
"C"
{
#endif
enum
{
SHA224_SIZE
=
224
/
8
};
enum
{
SHA224_ALIGN
=
4
};
enum
{
SHA256_SIZE
=
256
/
4
};
enum
{
SHA256_ALIGN
=
4
};
/* read file stream buffer */
extern
int
fstream_read
(
FILE
*
stream
,
int
fd
);
/* read gzfile stream buffer. */
extern
int
gzstream_read
(
gzFile
gzstream
,
int
fd
);
extern
int
sha256sum_calculate
(
void
*
stream
,
char
*
buffer_out
,
size_t
len
,
bool
isfile
,
bool
isgzip
);
/* Compute SHA256 (SHA224) message digest for bytes read from STREAM.
The result is a 64 characters string without prefix "sha256:" */
char
*
sha256_digest
(
void
*
stream
,
bool
isgzip
);
char
*
sha256_digest_file
(
const
char
*
filename
,
bool
isgzip
);
char
*
sha256_digest_str
(
const
char
*
val
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录