libapt 1.3.0

Rust library for interfacing with Debian apt repositories.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
//! Implementation of the source types and parsing.
//!
#[cfg(not(test))]
use log::error;

#[cfg(test)]
use std::println as error;

use serde::{Deserialize, Serialize};
use std::{cmp::Ordering, collections::HashMap};

use crate::util::{parse_package_relation, parse_stanza};
use crate::{
    Architecture, Distro, Error, ErrorType, Link, LinkHash, PackageVersion, Priority, Result,
    Version,
};

/// A PackageReference is a Debian source package package-list entry.
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
pub struct PackageReference {
    pub name: String,
    pub package_type: String,
    pub section: String,
    pub priority: Priority,
    pub architecture: Vec<Architecture>,
}

/// The Source struct groups all data about a source package.
///
/// When the source package index file is parsed, all specified values from
/// [Debian Wiki Package Indices specification](https://wiki.debian.org/DebianRepository/Format#A.22Sources.22_Indices)
/// are considered.
/// For parsing the single entries the
/// [Debian Policy Source Package specification](https://www.debian.org/doc/debian-policy/ch-controlfields.html#debian-source-package-control-files-dsc)
/// is used as a base.
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
pub struct Source {
    // fields from apt source package index
    pub format: String,
    pub package: String,
    pub binary: Vec<String>,
    pub architecture: Vec<Architecture>,
    pub version: Version,
    pub maintainer: String,
    pub uploaders: Vec<String>,
    pub homepage: Option<String>,
    pub vcs_arch: Option<String>,
    pub vcs_bzr: Option<String>,
    pub vcs_cvs: Option<String>,
    pub vcs_darcs: Option<String>,
    pub vcs_git: Option<String>,
    pub vcs_hg: Option<String>,
    pub vcs_mtn: Option<String>,
    pub vcs_svn: Option<String>,
    pub vcs_browser: Option<String>,
    pub testsuite: Vec<String>,
    pub dgit: Option<String>,
    pub standards_version: Option<String>,
    pub build_depends: Vec<PackageVersion>,
    pub build_depends_indep: Vec<PackageVersion>,
    pub build_depends_arch: Vec<PackageVersion>,
    pub build_conflicts: Vec<PackageVersion>,
    pub build_conflicts_indep: Vec<PackageVersion>,
    pub build_conflicts_arch: Vec<PackageVersion>,
    pub package_list: Vec<PackageReference>,
    // The links group the checksums with the size and the hash,
    // for all checksums and files.
    pub links: HashMap<String, Link>,
    pub directory: String,
    pub priority: Option<Priority>,
    // list of sections is unstable, not using type.
    pub section: Option<String>,
    pub issues: Vec<Error>,
}

impl Source {
    /// New struct with default values.
    pub fn new(
        format: &str,
        package: &str,
        version: Version,
        maintainer: &str,
        directory: &str,
    ) -> Source {
        Source {
            // fields from apt source package index
            format: format.to_string(),
            package: package.to_string(),
            binary: Vec::new(),
            architecture: Vec::new(),
            version: version,
            maintainer: maintainer.to_string(),
            uploaders: Vec::new(),
            homepage: None,
            vcs_arch: None,
            vcs_bzr: None,
            vcs_cvs: None,
            vcs_darcs: None,
            vcs_git: None,
            vcs_hg: None,
            vcs_mtn: None,
            vcs_svn: None,
            vcs_browser: None,
            testsuite: Vec::new(),
            dgit: None,
            standards_version: None,
            build_depends: Vec::new(),
            build_depends_indep: Vec::new(),
            build_depends_arch: Vec::new(),
            build_conflicts: Vec::new(),
            build_conflicts_indep: Vec::new(),
            build_conflicts_arch: Vec::new(),
            package_list: Vec::new(),
            // The links group the checksums with the size and the hash,
            // for all checksums and files.
            links: HashMap::new(),
            directory: directory.to_string(),
            priority: None,
            // list of sections is unstable, not using type.
            section: None,
            issues: Vec::new(),
        }
    }

    /// Parse a Package from its stanza.
    pub fn from_stanza(stanza: &str, distro: &Distro) -> Result<Source> {
        let kv = parse_stanza(stanza);

        let format = match kv.get("format") {
            Some(name) => name,
            None => {
                let message = format!("Invalid source stanza, format missing!\n{stanza}");
                error!("{}", &message);
                return Err(Error::new(&message, ErrorType::SourceFormat));
            }
        };

        let package = match kv.get("package") {
            Some(package) => package,
            None => {
                let message = format!("Invalid source stanza, package missing!\n{stanza}");
                error!("{}", &message);
                return Err(Error::new(&message, ErrorType::SourceFormat));
            }
        };

        let version = match kv.get("version") {
            Some(version) => Version::from_str(version)?,
            None => {
                let message = format!("Invalid stanza, version missing!\n{stanza}");
                error!("{}", &message);
                return Err(Error::new(&message, ErrorType::SourceFormat));
            }
        };

        let maintainer = match kv.get("maintainer") {
            Some(maintainer) => maintainer,
            None => {
                let message = format!("Invalid source stanza, maintainer missing!\n{stanza}");
                error!("{}", &message);
                return Err(Error::new(&message, ErrorType::SourceFormat));
            }
        };

        let directory = match kv.get("directory") {
            Some(directory) => directory,
            None => {
                let message = format!("Invalid source stanza, directory missing!\n{stanza}");
                error!("{}", &message);
                return Err(Error::new(&message, ErrorType::SourceFormat));
            }
        };

        let mut source = Source::new(format, package, version, maintainer, directory);

        match kv.get("binary") {
            Some(binary) => {
                source.binary = binary
                    .split(",")
                    .map(|b| b.trim())
                    .map(|b| b.to_string())
                    .collect();
            }
            None => {}
        }

        match kv.get("section") {
            Some(section) => {
                source.section = Some(section.clone());
            }
            None => {}
        }

        match kv.get("architecture") {
            Some(architecture) => {
                let architectures: Result<Vec<Architecture>> = architecture
                    .trim()
                    .split(" ")
                    .map(|a| Architecture::from_str(a.trim()))
                    .collect();
                source.architecture = architectures?;
            }
            None => {}
        }

        match kv.get("priority") {
            Some(priority) => match Priority::from_str(priority) {
                Ok(priority) => {
                    source.priority = Some(priority);
                }
                Err(e) => {
                    source.issues.push(e);
                }
            },
            None => {}
        }

        match kv.get("homepage") {
            Some(homepage) => {
                source.homepage = Some(homepage.clone());
            }
            None => {}
        }

        match kv.get("build-depends") {
            Some(build_depends) => match parse_package_relation(build_depends) {
                Ok(build_depends) => {
                    source.build_depends = build_depends;
                }
                Err(e) => {
                    source.issues.push(e);
                }
            },
            None => {}
        };

        match kv.get("build-depends-indep") {
            Some(build_depends_indep) => match parse_package_relation(build_depends_indep) {
                Ok(build_depends_indep) => {
                    source.build_depends_indep = build_depends_indep;
                }
                Err(e) => {
                    source.issues.push(e);
                }
            },
            None => {}
        };

        match kv.get("build-depends-arch") {
            Some(build_depends_arch) => match parse_package_relation(build_depends_arch) {
                Ok(build_depends_arch) => {
                    source.build_depends_arch = build_depends_arch;
                }
                Err(e) => {
                    source.issues.push(e);
                }
            },
            None => {}
        };

        match kv.get("build-conflicts") {
            Some(build_conflicts) => match parse_package_relation(build_conflicts) {
                Ok(build_conflicts) => {
                    source.build_conflicts = build_conflicts;
                }
                Err(e) => {
                    source.issues.push(e);
                }
            },
            None => {}
        };

        match kv.get("build-conflicts-indep") {
            Some(build_conflicts_indep) => match parse_package_relation(build_conflicts_indep) {
                Ok(build_conflicts_indep) => {
                    source.build_conflicts_indep = build_conflicts_indep;
                }
                Err(e) => {
                    source.issues.push(e);
                }
            },
            None => {}
        };

        match kv.get("build-conflicts-arch") {
            Some(build_conflicts_arch) => match parse_package_relation(build_conflicts_arch) {
                Ok(build_conflicts_arch) => {
                    source.build_conflicts_arch = build_conflicts_arch;
                }
                Err(e) => {
                    source.issues.push(e);
                }
            },
            None => {}
        };

        match kv.get("uploaders") {
            Some(uploaders) => {
                source.uploaders = uploaders
                    .split(",")
                    .map(|b| b.trim())
                    .map(|b| b.to_string())
                    .collect();
            }
            None => {}
        }

        match kv.get("vcs-arch") {
            Some(vcs_arch) => {
                source.vcs_arch = Some(vcs_arch.clone());
            }
            None => {}
        }

        match kv.get("vcs-bzr") {
            Some(vcs_bzr) => {
                source.vcs_bzr = Some(vcs_bzr.clone());
            }
            None => {}
        }

        match kv.get("vcs-cvs") {
            Some(vcs_cvs) => {
                source.vcs_cvs = Some(vcs_cvs.clone());
            }
            None => {}
        }

        match kv.get("vcs-darcs") {
            Some(vcs_darcs) => {
                source.vcs_darcs = Some(vcs_darcs.clone());
            }
            None => {}
        }

        match kv.get("vcs-git") {
            Some(vcs_git) => {
                source.vcs_git = Some(vcs_git.clone());
            }
            None => {}
        }

        match kv.get("vcs-hg") {
            Some(vcs_hg) => {
                source.vcs_hg = Some(vcs_hg.clone());
            }
            None => {}
        }

        match kv.get("vcs-mtn") {
            Some(vcs_mtn) => {
                source.vcs_mtn = Some(vcs_mtn.clone());
            }
            None => {}
        }

        match kv.get("vcs-svn") {
            Some(vcs_svn) => {
                source.vcs_svn = Some(vcs_svn.clone());
            }
            None => {}
        }

        match kv.get("vcs-browser") {
            Some(vcs_browser) => {
                source.vcs_browser = Some(vcs_browser.clone());
            }
            None => {}
        }

        match kv.get("testsuite") {
            Some(testsuite) => {
                source.testsuite = testsuite
                    .split(",")
                    .map(|b| b.trim())
                    .map(|b| b.to_string())
                    .collect();
            }
            None => {}
        }

        match kv.get("dgit") {
            Some(dgit) => {
                source.dgit = Some(dgit.clone());
            }
            None => {}
        }

        match kv.get("standards-version") {
            Some(standards_version) => {
                source.standards_version = Some(standards_version.clone());
            }
            None => {}
        }

        match kv.get("package-list") {
            Some(package_list) => {
                let list: Vec<&str> = package_list
                    .split("\n")
                    .filter(|l| !l.trim().is_empty())
                    .collect();

                for line in list {
                    let parts: Vec<&str> = line
                        .trim()
                        .split(" ")
                        .map(|p| p.trim())
                        .filter(|l| !l.is_empty())
                        .collect();

                    // Additional values are ignored.
                    if parts.len() < 4 {
                        return Err(Error::new(
                            &format!("Invalid Package-List line: {line}"),
                            ErrorType::SourceFormat,
                        ));
                    }

                    let name = parts[0].to_string();
                    let package_type = parts[1].to_string();
                    let section = parts[2].to_string();
                    let priority = match Priority::from_str(parts[3]) {
                        Ok(priority) => priority,
                        Err(e) => {
                            source.issues.push(e);
                            continue;
                        }
                    };

                    let architecture: Vec<Architecture> = if parts.len() > 4 {
                        let architecture: Result<Vec<Architecture>> = parts[4]
                            .split(",")
                            .map(|a| a.trim())
                            .map(|a| {
                                if a.starts_with("arch=") {
                                    &a[5..].trim()
                                } else {
                                    a
                                }
                            })
                            .map(|a| Architecture::from_str(a.trim()))
                            .collect();
                        architecture?
                    } else {
                        Vec::new()
                    };

                    let pr = PackageReference {
                        name: name,
                        package_type: package_type,
                        section: section,
                        priority: priority,
                        architecture: architecture,
                    };

                    source.package_list.push(pr);
                }
            }
            None => {}
        }

        match source.parse_files(kv.get("files"), distro, LinkHash::Md5, true, stanza) {
            Ok(_) => {}
            Err(e) => {
                source.issues.push(e);
            }
        }

        match source.parse_files(
            kv.get("checksums-sha256"),
            distro,
            LinkHash::Sha256,
            true,
            stanza,
        ) {
            Ok(_) => {}
            Err(e) => {
                source.issues.push(e);
            }
        }

        match source.parse_files(
            kv.get("checksums-sha512"),
            distro,
            LinkHash::Sha512,
            false,
            stanza,
        ) {
            Ok(_) => {}
            Err(e) => {
                source.issues.push(e);
            }
        }

        match source.parse_files(
            kv.get("checksums-sha1"),
            distro,
            LinkHash::Sha1,
            false,
            stanza,
        ) {
            Ok(_) => {}
            Err(e) => {
                source.issues.push(e);
            }
        }

        Ok(source)
    }

    fn parse_files(
        &mut self,
        files: Option<&String>,
        distro: &Distro,
        hash_type: LinkHash,
        required: bool,
        stanza: &str,
    ) -> Result<()> {
        match files {
            Some(files) => {
                let files: Vec<&str> = files
                    .split("\n")
                    .filter(|l| !l.trim().is_empty())
                    .map(|p| p.trim())
                    .collect();

                for file in files {
                    let mut link = Link::form_source(file, distro, self)?;

                    match self.links.get_mut(&link.url) {
                        Some(link) => {
                            link.add_hash(file, hash_type.clone())?;
                        }
                        None => {
                            link.add_hash(file, hash_type.clone())?;
                            self.links.insert(link.url.clone(), link);
                        }
                    }
                }
            }
            None => {
                if required {
                    let message = format!("Invalid stanza, files missing!\n{stanza}");
                    error!("{}", &message);
                    return Err(Error::new(&message, ErrorType::SourceFormat));
                }
            }
        };

        Ok(())
    }
}

impl PartialOrd for Source {
    fn partial_cmp(&self, other: &Source) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for Source {
    fn cmp(&self, other: &Source) -> Ordering {
        self.version.cmp(&other.version)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{Key, VersionRelation};

    #[test]
    fn parse_source() {
        let distro = Distro::repo(
            "http://archive.ubuntu.com/ubuntu",
            "jammy",
            Key::NoSignatureCheck,
        );

        let stanza = r#"
Package: constantly
Format: 3.0 (quilt)
Binary: python3-constantly
Architecture: all
Version: 15.1.0-2
Priority: optional
Section: misc
Maintainer: Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>
Uploaders: Free Ekanayaka <freee@debian.org>
Standards-Version: 3.9.8
Build-Depends: debhelper-compat (= 9), dh-python, python3-all, python3-setuptools (>= 0.6b3)
Homepage: https://github.com/twisted/constantly
Vcs-Browser: https://salsa.debian.org/python-team/modules/constantly
Vcs-Git: https://salsa.debian.org/python-team/modules/constantly.git
Directory: pool/main/c/constantly
Package-List:
 python3-constantly deb python optional arch=all
Files:
 807a24c0019e9b1c8e3b6a0654a3b040 2032 constantly_15.1.0-2.dsc
 f0762f083d83039758e53f8cf0086eef 21465 constantly_15.1.0.orig.tar.gz
 4c52076736ca1c069f436be9308b42aa 2612 constantly_15.1.0-2.debian.tar.xz
Checksums-Sha1:
 30834594e62c0cbd8a8fa05168b877f77164f9e3 2032 constantly_15.1.0-2.dsc
 02e60c17889d029e48a52a74259462e087a3dcdd 21465 constantly_15.1.0.orig.tar.gz
 b905b08c9be3c6e1a308c0b62e1a56305fc291f8 2612 constantly_15.1.0-2.debian.tar.xz
Checksums-Sha256:
 af28fa59bb101ff6469a7d3e709e75658163e523df52a4f00b596ed2cfa5c45b 2032 constantly_15.1.0-2.dsc
 586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35 21465 constantly_15.1.0.orig.tar.gz
 40e5a20cd6a157de997b71cc1a95393cacd23d9a6ff9bc2bd021cb983f785835 2612 constantly_15.1.0-2.debian.tar.xz
Checksums-Sha512:
 043542750e6d37dd994c468775dc442581d6c7dec42446ed4ef46a75e1e2ad3b4ee7ea48bc3a5dff67576d382d76d12e95289025db952de52c95da232c7fcbf7 2032 constantly_15.1.0-2.dsc
 ccc6f41b0bd552d2bb5346cc9d64cd7b91a59dd30e0cf66b01e82f7e0e079c01c34bc6c66b69c5fee9d2eed35ae5455258d309e66278d708d5f576ddf2e00ac3 21465 constantly_15.1.0.orig.tar.gz
 4795112fc25d74214a89df6ecdb935fd107f3b8cce79c49cd0c1b57354f914e10b90857eec3c78dd10c8234ff69d4825c8ab7c06cf317a6d11a8f40a98e62aeb 2612 constantly_15.1.0-2.debian.tar.xz
"#;

        let source = Source::from_stanza(stanza, &distro).unwrap();
        assert_eq!(source.package, "constantly");
        assert_eq!(source.format, "3.0 (quilt)".to_string());
        assert_eq!(source.binary, vec!["python3-constantly"]);
        assert_eq!(source.architecture, vec![Architecture::All]);
        assert_eq!(source.version.epoch, None);
        assert_eq!(source.version.version, "15.1.0");
        assert_eq!(source.version.revision, Some("2".to_string()));
        assert_eq!(source.priority, Some(Priority::Optional));
        assert_eq!(source.section, Some("misc".to_string()));
        assert_eq!(
            source.maintainer,
            "Debian Python Modules Team <python-modules-team@lists.alioth.debian.org>"
        );
        assert_eq!(source.uploaders, vec!["Free Ekanayaka <freee@debian.org>"]);
        assert_eq!(source.standards_version, Some("3.9.8".to_string()));

        assert_eq!(source.build_depends.len(), 4);

        assert_eq!(source.build_depends[0].name, "debhelper-compat");
        assert_eq!(
            source.build_depends[0].version,
            Some(Version::from_str("9").unwrap())
        );
        assert_eq!(
            source.build_depends[0].relation,
            Some(VersionRelation::from_str("=").unwrap())
        );

        assert_eq!(source.build_depends[1].name, "dh-python");
        assert_eq!(source.build_depends[1].version, None);
        assert_eq!(source.build_depends[1].relation, None);

        assert_eq!(source.build_depends[2].name, "python3-all");
        assert_eq!(source.build_depends[2].version, None);
        assert_eq!(source.build_depends[2].relation, None);

        assert_eq!(source.build_depends[3].name, "python3-setuptools");
        assert_eq!(
            source.build_depends[3].version,
            Some(Version::from_str("0.6b3").unwrap())
        );
        assert_eq!(
            source.build_depends[3].relation,
            Some(VersionRelation::from_str(">=").unwrap())
        );

        assert_eq!(
            source.homepage,
            Some("https://github.com/twisted/constantly".to_string())
        );
        assert_eq!(
            source.vcs_browser,
            Some("https://salsa.debian.org/python-team/modules/constantly".to_string())
        );
        assert_eq!(
            source.vcs_git,
            Some("https://salsa.debian.org/python-team/modules/constantly.git".to_string())
        );
        assert_eq!(source.directory, "pool/main/c/constantly".to_string());

        assert_eq!(source.package_list.len(), 1);

        println!("{:?}", source.package_list);

        assert_eq!(source.package_list[0].name, "python3-constantly");
        assert_eq!(source.package_list[0].package_type, "deb");
        assert_eq!(source.package_list[0].section, "python");
        assert_eq!(source.package_list[0].priority, Priority::Optional);
        assert_eq!(source.package_list[0].architecture, vec![Architecture::All]);

        assert_eq!(source.links.len(), 3);

        let url = "http://archive.ubuntu.com/ubuntu/pool/main/c/constantly/constantly_15.1.0-2.dsc";
        let link = source.links.get(url).unwrap();
        assert_eq!(link.url, url);
        assert_eq!(link.size, 2032);
        assert_eq!(
            link.hashes.get(&LinkHash::Md5).unwrap(),
            "807a24c0019e9b1c8e3b6a0654a3b040"
        );
        assert_eq!(
            link.hashes.get(&LinkHash::Sha1).unwrap(),
            "30834594e62c0cbd8a8fa05168b877f77164f9e3"
        );
        assert_eq!(
            link.hashes.get(&LinkHash::Sha256).unwrap(),
            "af28fa59bb101ff6469a7d3e709e75658163e523df52a4f00b596ed2cfa5c45b"
        );
        assert_eq!(link.hashes.get(&LinkHash::Sha512).unwrap(), "043542750e6d37dd994c468775dc442581d6c7dec42446ed4ef46a75e1e2ad3b4ee7ea48bc3a5dff67576d382d76d12e95289025db952de52c95da232c7fcbf7");

        let url =
            "http://archive.ubuntu.com/ubuntu/pool/main/c/constantly/constantly_15.1.0.orig.tar.gz";
        let link = source.links.get(url).unwrap();
        assert_eq!(link.url, url);
        assert_eq!(link.size, 21465);
        assert_eq!(
            link.hashes.get(&LinkHash::Md5).unwrap(),
            "f0762f083d83039758e53f8cf0086eef"
        );
        assert_eq!(
            link.hashes.get(&LinkHash::Sha1).unwrap(),
            "02e60c17889d029e48a52a74259462e087a3dcdd"
        );
        assert_eq!(
            link.hashes.get(&LinkHash::Sha256).unwrap(),
            "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
        );
        assert_eq!(link.hashes.get(&LinkHash::Sha512).unwrap(), "ccc6f41b0bd552d2bb5346cc9d64cd7b91a59dd30e0cf66b01e82f7e0e079c01c34bc6c66b69c5fee9d2eed35ae5455258d309e66278d708d5f576ddf2e00ac3");

        let url = "http://archive.ubuntu.com/ubuntu/pool/main/c/constantly/constantly_15.1.0-2.debian.tar.xz";
        let link = source.links.get(url).unwrap();
        assert_eq!(link.url, url);
        assert_eq!(link.size, 2612);
        assert_eq!(
            link.hashes.get(&LinkHash::Md5).unwrap(),
            "4c52076736ca1c069f436be9308b42aa"
        );
        assert_eq!(
            link.hashes.get(&LinkHash::Sha1).unwrap(),
            "b905b08c9be3c6e1a308c0b62e1a56305fc291f8"
        );
        assert_eq!(
            link.hashes.get(&LinkHash::Sha256).unwrap(),
            "40e5a20cd6a157de997b71cc1a95393cacd23d9a6ff9bc2bd021cb983f785835"
        );
        assert_eq!(link.hashes.get(&LinkHash::Sha512).unwrap(), "4795112fc25d74214a89df6ecdb935fd107f3b8cce79c49cd0c1b57354f914e10b90857eec3c78dd10c8234ff69d4825c8ab7c06cf317a6d11a8f40a98e62aeb");
    }
}