summaryrefslogtreecommitdiffstats
path: root/rust/src/api_server.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-12-21 17:09:10 -0800
committerBryan Newbold <bnewbold@robocracy.org>2018-12-21 17:09:10 -0800
commitc1c01caf6b40343bd876e10961829e2b15a9c37c (patch)
treecb26627fe194cbd878ad9c5912dce2feef2c1c8d /rust/src/api_server.rs
parent86f37a5df6f94d7736be736d0a440ae65425d6c9 (diff)
downloadfatcat-c1c01caf6b40343bd876e10961829e2b15a9c37c.tar.gz
fatcat-c1c01caf6b40343bd876e10961829e2b15a9c37c.zip
verify checksum against regexes
Diffstat (limited to 'rust/src/api_server.rs')
-rw-r--r--rust/src/api_server.rs45
1 files changed, 27 insertions, 18 deletions
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index d03fce07..adc6ab11 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -178,24 +178,33 @@ impl Server {
conn: &DbConn,
) -> Result<FileEntity> {
let (ident, rev): (FileIdentRow, FileRevRow) = match (md5, sha1, sha256) {
- (Some(md5), None, None) => file_ident::table
- .inner_join(file_rev::table)
- .filter(file_rev::md5.eq(md5))
- .filter(file_ident::is_live.eq(true))
- .filter(file_ident::redirect_id.is_null())
- .first(conn)?,
- (None, Some(sha1), None) => file_ident::table
- .inner_join(file_rev::table)
- .filter(file_rev::sha1.eq(sha1))
- .filter(file_ident::is_live.eq(true))
- .filter(file_ident::redirect_id.is_null())
- .first(conn)?,
- (None, None, Some(sha256)) => file_ident::table
- .inner_join(file_rev::table)
- .filter(file_rev::sha256.eq(sha256))
- .filter(file_ident::is_live.eq(true))
- .filter(file_ident::redirect_id.is_null())
- .first(conn)?,
+ (Some(md5), None, None) => {
+ check_md5(md5)?;
+ file_ident::table
+ .inner_join(file_rev::table)
+ .filter(file_rev::md5.eq(md5))
+ .filter(file_ident::is_live.eq(true))
+ .filter(file_ident::redirect_id.is_null())
+ .first(conn)?
+ },
+ (None, Some(sha1), None) => {
+ check_sha1(sha1)?;
+ file_ident::table
+ .inner_join(file_rev::table)
+ .filter(file_rev::sha1.eq(sha1))
+ .filter(file_ident::is_live.eq(true))
+ .filter(file_ident::redirect_id.is_null())
+ .first(conn)?
+ },
+ (None, None, Some(sha256)) => {
+ check_sha256(sha256)?;
+ file_ident::table
+ .inner_join(file_rev::table)
+ .filter(file_rev::sha256.eq(sha256))
+ .filter(file_ident::is_live.eq(true))
+ .filter(file_ident::redirect_id.is_null())
+ .first(conn)?
+ },
_ => {
return Err(ErrorKind::MissingOrMultipleExternalId("in lookup".to_string()).into());
}