diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2018-12-21 17:09:10 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-12-21 17:09:10 -0800 |
commit | c1c01caf6b40343bd876e10961829e2b15a9c37c (patch) | |
tree | cb26627fe194cbd878ad9c5912dce2feef2c1c8d /rust/src/api_server.rs | |
parent | 86f37a5df6f94d7736be736d0a440ae65425d6c9 (diff) | |
download | fatcat-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.rs | 45 |
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()); } |