This file is indexed.

/usr/share/doc/libghc-hackage-security-doc/html/hackage-security.txt is in libghc-hackage-security-doc 0.5.2.2-8build8.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Hackage security library
--   
--   The hackage security library provides both server and client utilities
--   for securing the Hackage package server
--   (<a>http://hackage.haskell.org/</a>). It is based on The Update
--   Framework (<a>http://theupdateframework.com/</a>), a set of
--   recommendations developed by security researchers at various
--   universities in the US as well as developers on the Tor project
--   (<a>https://www.torproject.org/</a>).
--   
--   The current implementation supports only index signing, thereby
--   enabling untrusted mirrors. It does not yet provide facilities for
--   author package signing.
--   
--   The library has two main entry points: <a>Hackage.Security.Client</a>
--   is the main entry point for clients (the typical example being
--   <tt>cabal</tt>), and <a>Hackage.Security.Server</a> is the main entry
--   point for servers (the typical example being <tt>hackage-server</tt>).
@package hackage-security
@version 0.5.2.2


-- | Minimal implementation of Canonical JSON.
--   
--   <a>http://wiki.laptop.org/go/Canonical_JSON</a>
--   
--   A "canonical JSON" format is provided in order to provide meaningful
--   and repeatable hashes of JSON-encoded data. Canonical JSON is parsable
--   with any full JSON parser, but security-conscious applications will
--   want to verify that input is in canonical form before authenticating
--   any hash or signature on that input.
--   
--   This implementation is derived from the json parser from the json
--   package, with simplifications to meet the Canonical JSON grammar.
--   
--   TODO: Known bugs/limitations:
--   
--   <ul>
--   <li>Decoding/encoding Unicode code-points beyond <tt>U+00ff</tt> is
--   currently broken</li>
--   </ul>
module Text.JSON.Canonical
data JSValue
JSNull :: JSValue
JSBool :: !Bool -> JSValue
JSNum :: !Int54 -> JSValue
JSString :: String -> JSValue
JSArray :: [JSValue] -> JSValue
JSObject :: [(String, JSValue)] -> JSValue

-- | 54-bit integer values
--   
--   JavaScript can only safely represent numbers between <tt>-(2^53 -
--   1)</tt> and <tt>2^53 - 1</tt>.
--   
--   TODO: Although we introduce the type here, we don't actually do any
--   bounds checking and just inherit all type class instance from Int64.
--   We should probably define <a>fromInteger</a> to do bounds checking,
--   give different instances for type classes such as <a>Bounded</a> and
--   <a>FiniteBits</a>, etc.
data Int54

-- | Parse a canonical JSON format string as a JSON value. The input string
--   does not have to be in canonical form, just in the "canonical JSON"
--   format.
--   
--   Use <a>renderCanonicalJSON</a> to convert into canonical form.
parseCanonicalJSON :: ByteString -> Either String JSValue

-- | Render a JSON value in canonical form. This rendered form is canonical
--   and so allows repeatable hashes.
--   
--   For pretty printing, see prettyCanonicalJSON.
--   
--   NB: Canonical JSON's string escaping rules deviate from RFC 7159 JSON
--   which requires
--   
--   "All Unicode characters may be placed within the quotation marks,
--   except for the characters that must be escaped: quotation mark,
--   reverse solidus, and the control characters (<tt>U+0000</tt> through
--   <tt>U+001F</tt>)."
--   
--   Whereas the current specification of Canonical JSON explicitly
--   requires to violate this by only escaping the quotation mark and the
--   reverse solidus. This, however, contradicts Canonical JSON's statement
--   that "Canonical JSON is parsable with any full JSON parser"
--   
--   Consequently, Canonical JSON is not a proper subset of RFC 7159.
renderCanonicalJSON :: JSValue -> ByteString

-- | Render a JSON value in a reasonable human-readable form. This rendered
--   form is <i>not the canonical form</i> used for repeatable hashes, use
--   <a>renderCanonicalJSON</a> for that.
prettyCanonicalJSON :: JSValue -> String
instance GHC.Classes.Ord Text.JSON.Canonical.JSValue
instance GHC.Classes.Eq Text.JSON.Canonical.JSValue
instance GHC.Read.Read Text.JSON.Canonical.JSValue
instance GHC.Show.Show Text.JSON.Canonical.JSValue
instance Text.Printf.PrintfArg Text.JSON.Canonical.Int54
instance Foreign.Storable.Storable Text.JSON.Canonical.Int54
instance Data.Bits.Bits Text.JSON.Canonical.Int54
instance Data.Bits.FiniteBits Text.JSON.Canonical.Int54
instance GHC.Arr.Ix Text.JSON.Canonical.Int54
instance GHC.Real.Real Text.JSON.Canonical.Int54
instance GHC.Classes.Ord Text.JSON.Canonical.Int54
instance GHC.Num.Num Text.JSON.Canonical.Int54
instance Data.Data.Data Text.JSON.Canonical.Int54
instance GHC.Real.Integral Text.JSON.Canonical.Int54
instance GHC.Classes.Eq Text.JSON.Canonical.Int54
instance GHC.Enum.Enum Text.JSON.Canonical.Int54
instance GHC.Enum.Bounded Text.JSON.Canonical.Int54
instance GHC.Show.Show Text.JSON.Canonical.Int54
instance GHC.Read.Read Text.JSON.Canonical.Int54


-- | Producing human-reaadable strings
module Hackage.Security.Util.Pretty

-- | Produce a human-readable string
class Pretty a
pretty :: Pretty a => a -> String


-- | Hiding existentials
module Hackage.Security.Util.Some
data Some f
Some :: (f a) -> Some f
data DictEq a
[DictEq] :: Eq a => DictEq a

-- | Type <tt>f</tt> satisfies <tt>SomeEq f</tt> if <tt>f a</tt> satisfies
--   <tt>Eq</tt> independent of <tt>a</tt>
class SomeEq f
someEq :: SomeEq f => DictEq (f a)
data DictShow a
[DictShow] :: Show a => DictShow a

-- | Type <tt>f</tt> satisfies <tt>SomeShow f</tt> if <tt>f a</tt>
--   satisfies <tt>Show</tt> independent of <tt>a</tt>
class SomeShow f
someShow :: SomeShow f => DictShow (f a)
data DictPretty a
[DictPretty] :: Pretty a => DictPretty a

-- | Type <tt>f</tt> satisfies <tt>SomeShow f</tt> if <tt>f a</tt>
--   satisfies <tt>Show</tt> independent of <tt>a</tt>
class SomePretty f
somePretty :: SomePretty f => DictPretty (f a)
typecheckSome :: Typed f => Some f -> Some (TypeOf f) -> Bool
instance (Hackage.Security.Util.TypedEmbedded.Typed f, Hackage.Security.Util.Some.SomeEq f) => GHC.Classes.Eq (Hackage.Security.Util.Some.Some f)
instance Hackage.Security.Util.Some.SomeShow f => GHC.Show.Show (Hackage.Security.Util.Some.Some f)
instance Hackage.Security.Util.Some.SomePretty f => Hackage.Security.Util.Pretty.Pretty (Hackage.Security.Util.Some.Some f)


-- | A more type-safe version of file paths
--   
--   This module is intended to replace imports of System.FilePath, and
--   additionally exports thin wrappers around common IO functions. To
--   facilitate importing this module unqualified we also re-export some
--   definitions from System.IO (importing both would likely lead to name
--   clashes).
--   
--   Note that his module does not import any other modules from
--   Hackage.Security; everywhere else we use Path instead of FilePath
--   directly.
module Hackage.Security.Util.Path

-- | Paths
--   
--   A <a>Path</a> is simply a <a>FilePath</a> with a type-level tag
--   indicating where this path is rooted (relative to the current
--   directory, absolute path, relative to a web domain, whatever). Most
--   operations on <a>Path</a> are just lifted versions of the operations
--   on the underlying <a>FilePath</a>. The tag however allows us to give a
--   lot of operations a more meaningful type. For instance, it does not
--   make sense to append two absolute paths together; instead, we can only
--   append an unrooted path to another path. It also means we avoid bugs
--   where we use one kind of path where we expect another.
newtype Path a
Path :: FilePath -> Path a

-- | Reinterpret the root of a path
--   
--   This literally just changes the type-level tag; use with caution!
castRoot :: Path root -> Path root'
takeDirectory :: Path a -> Path a
takeFileName :: Path a -> String
(<.>) :: Path a -> String -> Path a
splitExtension :: Path a -> (Path a, String)
takeExtension :: Path a -> String

-- | Type-level tag for unrooted paths
--   
--   Unrooted paths need a root before they can be interpreted.
data Unrooted
(</>) :: Path a -> Path Unrooted -> Path a

-- | Reinterpret an unrooted path
--   
--   This is an alias for <a>castRoot</a>; see comments there.
rootPath :: Path Unrooted -> Path root

-- | Forget a path's root
--   
--   This is an alias for <a>castRoot</a>; see comments there.
unrootPath :: Path root -> Path Unrooted

-- | Convert a relative/unrooted Path to a FilePath (using POSIX style
--   directory separators).
--   
--   See also <a>toAbsoluteFilePath</a>
toUnrootedFilePath :: Path Unrooted -> FilePath

-- | Convert from a relative/unrooted FilePath (using POSIX style directory
--   separators).
fromUnrootedFilePath :: FilePath -> Path Unrooted

-- | A path fragment (like a single directory or filename)
fragment :: String -> Path Unrooted
joinFragments :: [String] -> Path Unrooted
splitFragments :: Path Unrooted -> [String]
isPathPrefixOf :: Path Unrooted -> Path Unrooted -> Bool
data Relative
data Absolute
data HomeDir

-- | A file system root can be interpreted as an (absolute) FilePath
class FsRoot root

-- | Convert a Path to an absolute FilePath (using native style directory
--   separators).
toAbsoluteFilePath :: FsRoot root => Path root -> IO FilePath

-- | Abstract over a file system root
--   
--   see <a>fromFilePath</a>
data FsPath
FsPath :: (Path root) -> FsPath
toFilePath :: Path Absolute -> FilePath
fromFilePath :: FilePath -> FsPath
makeAbsolute :: FsPath -> IO (Path Absolute)
fromAbsoluteFilePath :: FilePath -> Path Absolute

-- | Wrapper around <a>withFile</a>
withFile :: FsRoot root => Path root -> IOMode -> (Handle -> IO r) -> IO r

-- | Wrapper around <tt>openBinaryTempFileWithDefaultPermissions</tt>
--   
--   NOTE: The caller is responsible for cleaning up the temporary file.
openTempFile' :: FsRoot root => Path root -> String -> IO (Path Absolute, Handle)
readLazyByteString :: FsRoot root => Path root -> IO ByteString
readStrictByteString :: FsRoot root => Path root -> IO ByteString
writeLazyByteString :: FsRoot root => Path root -> ByteString -> IO ()
writeStrictByteString :: FsRoot root => Path root -> ByteString -> IO ()
copyFile :: (FsRoot root, FsRoot root') => Path root -> Path root' -> IO ()
createDirectory :: FsRoot root => Path root -> IO ()
createDirectoryIfMissing :: FsRoot root => Bool -> Path root -> IO ()
removeDirectory :: FsRoot root => Path root -> IO ()
doesFileExist :: FsRoot root => Path root -> IO Bool
doesDirectoryExist :: FsRoot root => Path root -> IO Bool
getModificationTime :: FsRoot root => Path root -> IO UTCTime
removeFile :: FsRoot root => Path root -> IO ()
getTemporaryDirectory :: IO (Path Absolute)

-- | Return the immediate children of a directory
--   
--   Filters out <tt>"."</tt> and <tt>".."</tt>.
getDirectoryContents :: FsRoot root => Path root -> IO [Path Unrooted]

-- | Recursive traverse a directory structure
--   
--   Returns a set of paths relative to the directory specified. The list
--   is lazily constructed, so that directories are only read when
--   required. (This is also essential to ensure that this function does
--   not build the entire result in memory before returning, potentially
--   running out of heap.)
getRecursiveContents :: FsRoot root => Path root -> IO [Path Unrooted]
renameFile :: (FsRoot root, FsRoot root') => Path root -> Path root' -> IO ()
getCurrentDirectory :: IO (Path Absolute)
data Tar
tarIndexLookup :: TarIndex -> Path Tar -> Maybe TarIndexEntry
tarAppend :: (FsRoot root, FsRoot root') => Path root -> Path root' -> [Path Tar] -> IO ()
data Web
toURIPath :: FilePath -> Path Web
fromURIPath :: Path Web -> FilePath
uriPath :: URI -> Path Web
modifyUriPath :: URI -> (Path Web -> Path Web) -> URI

-- | See <a>openFile</a>
data IOMode :: *
ReadMode :: IOMode
WriteMode :: IOMode
AppendMode :: IOMode
ReadWriteMode :: IOMode

-- | Three kinds of buffering are supported: line-buffering,
--   block-buffering or no-buffering. These modes have the following
--   effects. For output, items are written out, or <i>flushed</i>, from
--   the internal buffer according to the buffer mode:
--   
--   <ul>
--   <li><i>line-buffering</i>: the entire output buffer is flushed
--   whenever a newline is output, the buffer overflows, a <a>hFlush</a> is
--   issued, or the handle is closed.</li>
--   <li><i>block-buffering</i>: the entire buffer is written out whenever
--   it overflows, a <a>hFlush</a> is issued, or the handle is closed.</li>
--   <li><i>no-buffering</i>: output is written immediately, and never
--   stored in the buffer.</li>
--   </ul>
--   
--   An implementation is free to flush the buffer more frequently, but not
--   less frequently, than specified above. The output buffer is emptied as
--   soon as it has been written out.
--   
--   Similarly, input occurs according to the buffer mode for the handle:
--   
--   <ul>
--   <li><i>line-buffering</i>: when the buffer for the handle is not
--   empty, the next item is obtained from the buffer; otherwise, when the
--   buffer is empty, characters up to and including the next newline
--   character are read into the buffer. No characters are available until
--   the newline character is available or the buffer is full.</li>
--   <li><i>block-buffering</i>: when the buffer for the handle becomes
--   empty, the next block of data is read into the buffer.</li>
--   <li><i>no-buffering</i>: the next input item is read and returned. The
--   <a>hLookAhead</a> operation implies that even a no-buffered handle may
--   require a one-character buffer.</li>
--   </ul>
--   
--   The default buffering mode when a handle is opened is
--   implementation-dependent and may depend on the file system object
--   which is attached to that handle. For most implementations, physical
--   files will normally be block-buffered and terminals will normally be
--   line-buffered.
data BufferMode :: *

-- | buffering is disabled if possible.
NoBuffering :: BufferMode

-- | line-buffering should be enabled if possible.
LineBuffering :: BufferMode

-- | block-buffering should be enabled if possible. The size of the buffer
--   is <tt>n</tt> items if the argument is <a>Just</a> <tt>n</tt> and is
--   otherwise implementation-dependent.
BlockBuffering :: Maybe Int -> BufferMode

-- | Haskell defines operations to read and write characters from and to
--   files, represented by values of type <tt>Handle</tt>. Each value of
--   this type is a <i>handle</i>: a record used by the Haskell run-time
--   system to <i>manage</i> I/O with file system objects. A handle has at
--   least the following properties:
--   
--   <ul>
--   <li>whether it manages input or output or both;</li>
--   <li>whether it is <i>open</i>, <i>closed</i> or
--   <i>semi-closed</i>;</li>
--   <li>whether the object is seekable;</li>
--   <li>whether buffering is disabled, or enabled on a line or block
--   basis;</li>
--   <li>a buffer (whose length may be zero).</li>
--   </ul>
--   
--   Most handles will also have a current I/O position indicating where
--   the next input or output operation will occur. A handle is
--   <i>readable</i> if it manages only input or both input and output;
--   likewise, it is <i>writable</i> if it manages only output or both
--   input and output. A handle is <i>open</i> when first allocated. Once
--   it is closed it can no longer be used for either input or output,
--   though an implementation cannot re-use its storage while references
--   remain to it. Handles are in the <a>Show</a> and <a>Eq</a> classes.
--   The string produced by showing a handle is system dependent; it should
--   include enough information to identify the handle for debugging. A
--   handle is equal according to <a>==</a> only to itself; no attempt is
--   made to compare the internal state of different handles for equality.
data Handle :: *

-- | A mode that determines the effect of <tt>hSeek</tt> <tt>hdl mode
--   i</tt>.
data SeekMode :: *

-- | the position of <tt>hdl</tt> is set to <tt>i</tt>.
AbsoluteSeek :: SeekMode

-- | the position of <tt>hdl</tt> is set to offset <tt>i</tt> from the
--   current position.
RelativeSeek :: SeekMode

-- | the position of <tt>hdl</tt> is set to offset <tt>i</tt> from the end
--   of the file.
SeekFromEnd :: SeekMode

-- | Computation <a>hSetBuffering</a> <tt>hdl mode</tt> sets the mode of
--   buffering for handle <tt>hdl</tt> on subsequent reads and writes.
--   
--   If the buffer mode is changed from <a>BlockBuffering</a> or
--   <a>LineBuffering</a> to <a>NoBuffering</a>, then
--   
--   <ul>
--   <li>if <tt>hdl</tt> is writable, the buffer is flushed as for
--   <a>hFlush</a>;</li>
--   <li>if <tt>hdl</tt> is not writable, the contents of the buffer is
--   discarded.</li>
--   </ul>
--   
--   This operation may fail with:
--   
--   <ul>
--   <li><tt>isPermissionError</tt> if the handle has already been used for
--   reading or writing and the implementation does not allow the buffering
--   mode to be changed.</li>
--   </ul>
hSetBuffering :: Handle -> BufferMode -> IO ()

-- | Computation <a>hClose</a> <tt>hdl</tt> makes handle <tt>hdl</tt>
--   closed. Before the computation finishes, if <tt>hdl</tt> is writable
--   its buffer is flushed as for <a>hFlush</a>. Performing <a>hClose</a>
--   on a handle that has already been closed has no effect; doing so is
--   not an error. All other operations on a closed handle will fail. If
--   <a>hClose</a> fails for any reason, any further operations (apart from
--   <a>hClose</a>) on the handle will still fail as if <tt>hdl</tt> had
--   been successfully closed.
hClose :: Handle -> IO ()

-- | For a handle <tt>hdl</tt> which attached to a physical file,
--   <a>hFileSize</a> <tt>hdl</tt> returns the size of that file in 8-bit
--   bytes.
hFileSize :: Handle -> IO Integer

-- | Computation <a>hSeek</a> <tt>hdl mode i</tt> sets the position of
--   handle <tt>hdl</tt> depending on <tt>mode</tt>. The offset <tt>i</tt>
--   is given in terms of 8-bit bytes.
--   
--   If <tt>hdl</tt> is block- or line-buffered, then seeking to a position
--   which is not in the current buffer will first cause any items in the
--   output buffer to be written to the device, and then cause the input
--   buffer to be discarded. Some handles may not be seekable (see
--   <a>hIsSeekable</a>), or only support a subset of the possible
--   positioning operations (for instance, it may only be possible to seek
--   to the end of a tape, or to a positive offset from the beginning or
--   current position). It is not possible to set a negative I/O position,
--   or for a physical file, an I/O position beyond the current
--   end-of-file.
--   
--   This operation may fail with:
--   
--   <ul>
--   <li><tt>isIllegalOperationError</tt> if the Handle is not seekable, or
--   does not support the requested seek mode.</li>
--   <li><tt>isPermissionError</tt> if a system resource limit would be
--   exceeded.</li>
--   </ul>
hSeek :: Handle -> SeekMode -> Integer -> IO ()
instance GHC.Classes.Ord (Hackage.Security.Util.Path.Path a)
instance GHC.Classes.Eq (Hackage.Security.Util.Path.Path a)
instance GHC.Show.Show (Hackage.Security.Util.Path.Path a)
instance Hackage.Security.Util.Pretty.Pretty (Hackage.Security.Util.Path.Path Hackage.Security.Util.Path.Unrooted)
instance Hackage.Security.Util.Pretty.Pretty (Hackage.Security.Util.Path.Path Hackage.Security.Util.Path.Absolute)
instance Hackage.Security.Util.Pretty.Pretty (Hackage.Security.Util.Path.Path Hackage.Security.Util.Path.Relative)
instance Hackage.Security.Util.Pretty.Pretty (Hackage.Security.Util.Path.Path Hackage.Security.Util.Path.HomeDir)
instance Hackage.Security.Util.Path.FsRoot Hackage.Security.Util.Path.Relative
instance Hackage.Security.Util.Path.FsRoot Hackage.Security.Util.Path.Absolute
instance Hackage.Security.Util.Path.FsRoot Hackage.Security.Util.Path.HomeDir
instance Hackage.Security.Util.Pretty.Pretty (Hackage.Security.Util.Path.Path Hackage.Security.Util.Path.Tar)


-- | Some very simple lens definitions (to avoid further dependencies)
--   
--   Intended to be double-imported &gt; import Hackage.Security.Util.Lens
--   (Lens) &gt; import qualified Hackage.Security.Util.Lens as Lens
module Hackage.Security.Util.Lens

-- | Polymorphic lens
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t

-- | Monomorphic lens
type Lens' s a = Lens s s a a
get :: Lens' s a -> s -> a
modify :: Lens s t a b -> (a -> b) -> s -> t
set :: Lens s t a b -> b -> s -> t
lookupM :: forall a b. (Eq a, Monoid b) => a -> Lens' [(a, b)] b

module Hackage.Security.Util.IO
getFileSize :: (Num a, FsRoot root) => Path root -> IO a
handleDoesNotExist :: IO a -> IO (Maybe a)

-- | Attempt to create a filesystem lock in the specified directory
--   
--   Given a file <tt><i>path</i>to</tt>, we do this by attempting to
--   create the directory <tt>/<i>path</i>to/hackage-security-lock</tt>,
--   and deleting the directory again afterwards. Creating a directory that
--   already exists will throw an exception on most OSs (certainly Linux,
--   OSX and Windows) and is a reasonably common way to implement a lock
--   file.
withDirLock :: Path Absolute -> IO a -> IO a
timedIO :: String -> IO a -> IO a


-- | Checked exceptions
module Hackage.Security.Util.Checked

-- | Checked exceptions
class Throws e
unthrow :: forall a e proxy. proxy e -> (Throws e => a) -> a

-- | Throw a checked exception
throwChecked :: (Exception e, Throws e) => e -> IO a

-- | Catch a checked exception
catchChecked :: forall a e. Exception e => (Throws e => IO a) -> (e -> IO a) -> IO a

-- | <a>catchChecked</a> with the arguments reversed
handleChecked :: Exception e => (e -> IO a) -> (Throws e => IO a) -> IO a

-- | Like <tt>try</tt>, but for checked exceptions
tryChecked :: Exception e => (Throws e => IO a) -> IO (Either e a)

-- | Rethrow IO exceptions as checked exceptions
checkIO :: Throws IOException => IO a -> IO a

-- | Throw an unchecked exception
--   
--   This is just an alias for <tt>throw</tt>, but makes it evident that
--   this is a very intentional use of an unchecked exception.
throwUnchecked :: Exception e => e -> IO a

-- | Variation on <a>throwUnchecked</a> for internal errors
internalError :: String -> IO a
instance Hackage.Security.Util.Checked.Throws (Hackage.Security.Util.Checked.Catch e)

module Hackage.Security.Key.Env

-- | A key environment is a mapping from key IDs to the corresponding keys.
--   
--   It should satisfy the invariant that these key IDs actually match the
--   keys; see <a>checkKeyEnvInvariant</a>.
data KeyEnv
keyEnvMap :: KeyEnv -> Map KeyId (Some PublicKey)
fromPublicKeys :: [Some PublicKey] -> KeyEnv
fromKeys :: [Some Key] -> KeyEnv
empty :: KeyEnv
null :: KeyEnv -> Bool
insert :: Some PublicKey -> KeyEnv -> KeyEnv
lookup :: KeyId -> KeyEnv -> Maybe (Some PublicKey)
union :: KeyEnv -> KeyEnv -> KeyEnv
instance GHC.Show.Show Hackage.Security.Key.Env.KeyEnv
instance GHC.Base.Monad m => Hackage.Security.Util.JSON.ToJSON m Hackage.Security.Key.Env.KeyEnv
instance Hackage.Security.Util.JSON.ReportSchemaErrors m => Hackage.Security.Util.JSON.FromJSON m Hackage.Security.Key.Env.KeyEnv


-- | Hackage-specific wrappers around the Util.JSON module
module Hackage.Security.JSON
data DeserializationError

-- | Malformed JSON has syntax errors in the JSON itself (i.e., we cannot
--   even parse it to a JSValue)
DeserializationErrorMalformed :: String -> DeserializationError

-- | Invalid JSON has valid syntax but invalid structure
--   
--   The string gives a hint about what we expected instead
DeserializationErrorSchema :: String -> DeserializationError

-- | The JSON file contains a key ID of an unknown key
DeserializationErrorUnknownKey :: KeyId -> DeserializationError

-- | Some verification step failed
DeserializationErrorValidation :: String -> DeserializationError

-- | Wrong file type
--   
--   Records actual and expected types.
DeserializationErrorFileType :: String -> String -> DeserializationError
validate :: MonadError DeserializationError m => String -> Bool -> m ()
verifyType :: (ReportSchemaErrors m, MonadError DeserializationError m) => JSValue -> String -> m ()

-- | MonadReader-like monad, specialized to key environments
class (ReportSchemaErrors m, MonadError DeserializationError m) => MonadKeys m
localKeys :: MonadKeys m => (KeyEnv -> KeyEnv) -> m a -> m a
askKeys :: MonadKeys m => m KeyEnv
addKeys :: MonadKeys m => KeyEnv -> m a -> m a
withKeys :: MonadKeys m => KeyEnv -> m a -> m a
lookupKey :: MonadKeys m => KeyId -> m (Some PublicKey)
readKeyAsId :: MonadKeys m => JSValue -> m (Some PublicKey)
data ReadJSON_Keys_Layout a
data ReadJSON_Keys_NoLayout a
data ReadJSON_NoKeys_NoLayout a
runReadJSON_Keys_Layout :: KeyEnv -> RepoLayout -> ReadJSON_Keys_Layout a -> Either DeserializationError a
runReadJSON_Keys_NoLayout :: KeyEnv -> ReadJSON_Keys_NoLayout a -> Either DeserializationError a
runReadJSON_NoKeys_NoLayout :: ReadJSON_NoKeys_NoLayout a -> Either DeserializationError a
parseJSON_Keys_Layout :: FromJSON ReadJSON_Keys_Layout a => KeyEnv -> RepoLayout -> ByteString -> Either DeserializationError a
parseJSON_Keys_NoLayout :: FromJSON ReadJSON_Keys_NoLayout a => KeyEnv -> ByteString -> Either DeserializationError a
parseJSON_NoKeys_NoLayout :: FromJSON ReadJSON_NoKeys_NoLayout a => ByteString -> Either DeserializationError a
readJSON_Keys_Layout :: (FsRoot root, FromJSON ReadJSON_Keys_Layout a) => KeyEnv -> RepoLayout -> Path root -> IO (Either DeserializationError a)
readJSON_Keys_NoLayout :: (FsRoot root, FromJSON ReadJSON_Keys_NoLayout a) => KeyEnv -> Path root -> IO (Either DeserializationError a)
readJSON_NoKeys_NoLayout :: (FsRoot root, FromJSON ReadJSON_NoKeys_NoLayout a) => Path root -> IO (Either DeserializationError a)
data WriteJSON a
runWriteJSON :: RepoLayout -> WriteJSON a -> a

-- | Render to canonical JSON format
renderJSON :: ToJSON WriteJSON a => RepoLayout -> a -> ByteString

-- | Variation on <a>renderJSON</a> for files that don't require the repo
--   layout
renderJSON_NoLayout :: ToJSON Identity a => a -> ByteString
writeJSON :: ToJSON WriteJSON a => RepoLayout -> Path Absolute -> a -> IO ()
writeJSON_NoLayout :: ToJSON Identity a => Path Absolute -> a -> IO ()
writeKeyAsId :: Some PublicKey -> JSValue
class ToJSON m a
toJSON :: ToJSON m a => a -> m JSValue
class FromJSON m a
fromJSON :: FromJSON m a => JSValue -> m a

-- | Used in the <a>ToJSON</a> instance for <a>Map</a>
class ToObjectKey m a
toObjectKey :: ToObjectKey m a => a -> m String

-- | Used in the <a>FromJSON</a> instance for <a>Map</a>
class FromObjectKey m a
fromObjectKey :: FromObjectKey m a => String -> m (Maybe a)

-- | Monads in which we can report schema errors
class (Applicative m, Monad m) => ReportSchemaErrors m
expected :: ReportSchemaErrors m => Expected -> Maybe Got -> m a
type Expected = String
type Got = String
expected' :: ReportSchemaErrors m => Expected -> JSValue -> m a
fromJSObject :: ReportSchemaErrors m => JSValue -> m [(String, JSValue)]

-- | Extract a field from a JSON object
fromJSField :: (ReportSchemaErrors m, FromJSON m a) => JSValue -> String -> m a
fromJSOptField :: (ReportSchemaErrors m, FromJSON m a) => JSValue -> String -> m (Maybe a)
mkObject :: forall m. Monad m => [(String, m JSValue)] -> m JSValue
data JSValue
JSNull :: JSValue
JSBool :: !Bool -> JSValue
JSNum :: !Int54 -> JSValue
JSString :: String -> JSValue
JSArray :: [JSValue] -> JSValue
JSObject :: [(String, JSValue)] -> JSValue

-- | 54-bit integer values
--   
--   JavaScript can only safely represent numbers between <tt>-(2^53 -
--   1)</tt> and <tt>2^53 - 1</tt>.
--   
--   TODO: Although we introduce the type here, we don't actually do any
--   bounds checking and just inherit all type class instance from Int64.
--   We should probably define <a>fromInteger</a> to do bounds checking,
--   give different instances for type classes such as <a>Bounded</a> and
--   <a>FiniteBits</a>, etc.
data Int54
instance Control.Monad.Reader.Class.MonadReader Hackage.Security.TUF.Layout.Repo.RepoLayout Hackage.Security.JSON.WriteJSON
instance GHC.Base.Monad Hackage.Security.JSON.WriteJSON
instance GHC.Base.Applicative Hackage.Security.JSON.WriteJSON
instance GHC.Base.Functor Hackage.Security.JSON.WriteJSON
instance Control.Monad.Error.Class.MonadError Hackage.Security.JSON.DeserializationError Hackage.Security.JSON.ReadJSON_NoKeys_NoLayout
instance GHC.Base.Monad Hackage.Security.JSON.ReadJSON_NoKeys_NoLayout
instance GHC.Base.Applicative Hackage.Security.JSON.ReadJSON_NoKeys_NoLayout
instance GHC.Base.Functor Hackage.Security.JSON.ReadJSON_NoKeys_NoLayout
instance Control.Monad.Error.Class.MonadError Hackage.Security.JSON.DeserializationError Hackage.Security.JSON.ReadJSON_Keys_NoLayout
instance GHC.Base.Monad Hackage.Security.JSON.ReadJSON_Keys_NoLayout
instance GHC.Base.Applicative Hackage.Security.JSON.ReadJSON_Keys_NoLayout
instance GHC.Base.Functor Hackage.Security.JSON.ReadJSON_Keys_NoLayout
instance Control.Monad.Error.Class.MonadError Hackage.Security.JSON.DeserializationError Hackage.Security.JSON.ReadJSON_Keys_Layout
instance GHC.Base.Monad Hackage.Security.JSON.ReadJSON_Keys_Layout
instance GHC.Base.Applicative Hackage.Security.JSON.ReadJSON_Keys_Layout
instance GHC.Base.Functor Hackage.Security.JSON.ReadJSON_Keys_Layout
instance GHC.Show.Show Hackage.Security.JSON.DeserializationError
instance GHC.Exception.Exception Hackage.Security.JSON.DeserializationError
instance Hackage.Security.Util.Pretty.Pretty Hackage.Security.JSON.DeserializationError
instance Hackage.Security.Util.JSON.ReportSchemaErrors Hackage.Security.JSON.ReadJSON_Keys_Layout
instance Hackage.Security.Util.JSON.ReportSchemaErrors Hackage.Security.JSON.ReadJSON_Keys_NoLayout
instance Hackage.Security.Util.JSON.ReportSchemaErrors Hackage.Security.JSON.ReadJSON_NoKeys_NoLayout
instance Control.Monad.Reader.Class.MonadReader Hackage.Security.TUF.Layout.Repo.RepoLayout Hackage.Security.JSON.ReadJSON_Keys_Layout
instance Hackage.Security.JSON.MonadKeys Hackage.Security.JSON.ReadJSON_Keys_Layout
instance Hackage.Security.JSON.MonadKeys Hackage.Security.JSON.ReadJSON_Keys_NoLayout


-- | Information about files
--   
--   Intended to be double imported
--   
--   <pre>
--   import Hackage.Security.TUF.FileMap (FileMap)
--   import qualified Hackage.Security.TUF.FileMap as FileMap
--   </pre>
module Hackage.Security.TUF.FileMap

-- | Mapping from paths to file info
--   
--   File maps are used in target files; the paths are relative to the
--   location of the target files containing the file map.
data FileMap

-- | Entries in <a>FileMap</a> either talk about the repository or the
--   index
data TargetPath
TargetPathRepo :: RepoPath -> TargetPath
TargetPathIndex :: IndexPath -> TargetPath
empty :: FileMap
lookup :: TargetPath -> FileMap -> Maybe FileInfo
(!) :: FileMap -> TargetPath -> FileInfo
insert :: TargetPath -> FileInfo -> FileMap -> FileMap
fromList :: [(TargetPath, FileInfo)] -> FileMap
lookupM :: Monad m => FileMap -> TargetPath -> m FileInfo
data FileChange

-- | File got added or modified; we record the new file info
FileChanged :: FileInfo -> FileChange

-- | File got deleted
FileDeleted :: FileChange
fileMapChanges :: FileMap -> FileMap -> Map TargetPath FileChange
instance GHC.Show.Show Hackage.Security.TUF.FileMap.FileChange
instance GHC.Show.Show Hackage.Security.TUF.FileMap.FileMap
instance GHC.Classes.Ord Hackage.Security.TUF.FileMap.TargetPath
instance GHC.Classes.Eq Hackage.Security.TUF.FileMap.TargetPath
instance GHC.Show.Show Hackage.Security.TUF.FileMap.TargetPath
instance Hackage.Security.Util.Pretty.Pretty Hackage.Security.TUF.FileMap.TargetPath
instance GHC.Base.Monad m => Hackage.Security.Util.JSON.ToJSON m Hackage.Security.TUF.FileMap.FileMap
instance Hackage.Security.Util.JSON.ReportSchemaErrors m => Hackage.Security.Util.JSON.FromJSON m Hackage.Security.TUF.FileMap.FileMap
instance GHC.Base.Monad m => Hackage.Security.Util.JSON.ToObjectKey m Hackage.Security.TUF.FileMap.TargetPath
instance Hackage.Security.Util.JSON.ReportSchemaErrors m => Hackage.Security.Util.JSON.FromObjectKey m Hackage.Security.TUF.FileMap.TargetPath


-- | Main entry point into the Hackage Security framework for clients
module Hackage.Security.Server
data Ed25519
data Key a
[KeyEd25519] :: PublicKey -> SecretKey -> Key Ed25519
data PublicKey a
[PublicKeyEd25519] :: PublicKey -> PublicKey Ed25519
data PrivateKey a
[PrivateKeyEd25519] :: SecretKey -> PrivateKey Ed25519
data KeyType typ
[KeyTypeEd25519] :: KeyType Ed25519
somePublicKey :: Some Key -> Some PublicKey
somePublicKeyType :: Some PublicKey -> Some KeyType
someKeyId :: HasKeyId key => Some key -> KeyId
publicKey :: Key a -> PublicKey a
privateKey :: Key a -> PrivateKey a
createKey :: KeyType key -> IO (Key key)
createKey' :: KeyType key -> IO (Some Key)

-- | The key ID of a key, by definition, is the hexdigest of the SHA-256
--   hash of the canonical JSON form of the key where the private object
--   key is excluded.
--   
--   NOTE: The FromJSON and ToJSON instances for KeyId are ntentially
--   omitted. Use writeKeyAsId instead.
newtype KeyId
KeyId :: String -> KeyId
[keyIdString] :: KeyId -> String

-- | Compute the key ID of a key
class HasKeyId key
keyId :: HasKeyId key => key typ -> KeyId

-- | Sign a bytestring and return the signature
--   
--   TODO: It is unfortunate that we have to convert to a strict bytestring
--   for ed25519
sign :: PrivateKey typ -> ByteString -> ByteString
verify :: PublicKey typ -> ByteString -> ByteString -> Bool

-- | File length
--   
--   Having verified file length information means we can protect against
--   endless data attacks and similar.
newtype FileLength
FileLength :: Int54 -> FileLength
[fileLength] :: FileLength -> Int54

-- | File hash
newtype Hash
Hash :: String -> Hash

-- | Key threshold
--   
--   The key threshold is the minimum number of keys a document must be
--   signed with. Key thresholds are specified in <tt>RoleSpec</tt> or
--   <tt>DelegationsSpec</tt>.
newtype KeyThreshold
KeyThreshold :: Int54 -> KeyThreshold

-- | File information
--   
--   This intentionally does not have an <a>Eq</a> instance; see
--   <a>knownFileInfoEqual</a> and <tt>verifyFileInfo</tt> instead.
--   
--   NOTE: Throughout we compute file information always over the raw
--   bytes. For example, when <tt>timestamp.json</tt> lists the hash of
--   <tt>snapshot.json</tt>, this hash is computed over the actual
--   <tt>snapshot.json</tt> file (as opposed to the canonical form of the
--   embedded JSON). This brings it in line with the hash computed over
--   target files, where that is the only choice available.
data FileInfo
FileInfo :: FileLength -> Map HashFn Hash -> FileInfo
[fileInfoLength] :: FileInfo -> FileLength
[fileInfoHashes] :: FileInfo -> Map HashFn Hash
data HashFn
HashFnSHA256 :: HashFn
HashFnMD5 :: HashFn

-- | File hash
newtype Hash
Hash :: String -> Hash

-- | Compute <a>FileInfo</a>
--   
--   TODO: Currently this will load the entire input bytestring into
--   memory. We need to make this incremental, by computing the length and
--   all hashes in a single traversal over the input.
fileInfo :: ByteString -> FileInfo

-- | Compute <a>FileInfo</a>
computeFileInfo :: FsRoot root => Path root -> IO FileInfo

-- | Compare the expected trusted file info against the actual file info of
--   a target file.
--   
--   This should be used only when the <a>FileInfo</a> is already known. If
--   we want to compare known <a>FileInfo</a> against a file on disk we
--   should delay until we have confirmed that the file lengths match (see
--   <tt>downloadedVerify</tt>).
compareTrustedFileInfo :: FileInfo -> FileInfo -> Bool
knownFileInfoEqual :: FileInfo -> FileInfo -> Bool

-- | Extract SHA256 hash from <a>FileInfo</a> (if present)
fileInfoSHA256 :: FileInfo -> Maybe Hash

-- | 54-bit integer values
--   
--   JavaScript can only safely represent numbers between <tt>-(2^53 -
--   1)</tt> and <tt>2^53 - 1</tt>.
--   
--   TODO: Although we introduce the type here, we don't actually do any
--   bounds checking and just inherit all type class instance from Int64.
--   We should probably define <a>fromInteger</a> to do bounds checking,
--   give different instances for type classes such as <a>Bounded</a> and
--   <a>FiniteBits</a>, etc.
data Int54
class HasHeader a

-- | File expiry date
fileExpires :: HasHeader a => Lens' a FileExpires

-- | File version (monotonically increasing counter)
fileVersion :: HasHeader a => Lens' a FileVersion

-- | File version
--   
--   The file version is a flat integer which must monotonically increase
--   on every file update.
--   
--   <a>Show</a> and <a>Read</a> instance are defined in terms of the
--   underlying <a>Int</a> (this is use for example by hackage during the
--   backup process).
newtype FileVersion
FileVersion :: Int54 -> FileVersion

-- | File expiry date
--   
--   A <a>Nothing</a> value here means no expiry. That makes it possible to
--   set some files to never expire. (Note that not having the Maybe in the
--   type here still allows that, because you could set an expiry date 2000
--   years into the future. By having the Maybe here we avoid the _need_
--   for such encoding issues.)
newtype FileExpires
FileExpires :: (Maybe UTCTime) -> FileExpires

-- | Occassionally it is useful to read only a header from a file.
--   
--   <tt>HeaderOnly</tt> intentionally only has a <a>FromJSON</a> instance
--   (no <a>ToJSON</a>).
data Header
Header :: FileExpires -> FileVersion -> Header
[headerExpires] :: Header -> FileExpires
[headerVersion] :: Header -> FileVersion
expiresInDays :: UTCTime -> Integer -> FileExpires
expiresNever :: FileExpires
isExpired :: UTCTime -> FileExpires -> Bool
versionInitial :: FileVersion
versionIncrement :: FileVersion -> FileVersion

-- | Location of the various files we cache
--   
--   Although the generic TUF algorithms do not care how we organize the
--   cache, we nonetheless specity this here because as long as there are
--   tools which access files in the cache directly we need to define the
--   cache layout. See also comments for <tt>defaultCacheLayout</tt>.
data CacheLayout
CacheLayout :: CachePath -> CachePath -> CachePath -> CachePath -> CachePath -> CachePath -> CachePath -> CacheLayout

-- | TUF root metadata
[cacheLayoutRoot] :: CacheLayout -> CachePath

-- | TUF timestamp
[cacheLayoutTimestamp] :: CacheLayout -> CachePath

-- | TUF snapshot
[cacheLayoutSnapshot] :: CacheLayout -> CachePath

-- | TUF mirrors list
[cacheLayoutMirrors] :: CacheLayout -> CachePath

-- | Uncompressed index tarball
[cacheLayoutIndexTar] :: CacheLayout -> CachePath

-- | Index to the uncompressed index tarball
[cacheLayoutIndexIdx] :: CacheLayout -> CachePath

-- | Compressed index tarball
--   
--   We cache both the compressed and the uncompressed tarballs, because
--   incremental updates happen through the compressed tarball, but reads
--   happen through the uncompressed one (with the help of the tarball
--   index).
[cacheLayoutIndexTarGz] :: CacheLayout -> CachePath

-- | The cache layout cabal-install uses
--   
--   We cache the index as <tt><a>cache</a>/00-index.tar</tt>; this is
--   important because `cabal-install` expects to find it there (and does
--   not currently go through the hackage-security library to get files
--   from the index).
cabalCacheLayout :: CacheLayout

-- | Layout of the files within the index tarball
data IndexLayout
IndexLayout :: (forall dec. IndexFile dec -> IndexPath) -> (IndexPath -> Maybe (Some IndexFile)) -> IndexLayout

-- | Translate an <a>IndexFile</a> to a path
[indexFileToPath] :: IndexLayout -> forall dec. IndexFile dec -> IndexPath

-- | Parse an <a>FilePath</a>
[indexFileFromPath] :: IndexLayout -> IndexPath -> Maybe (Some IndexFile)

-- | Files that we might request from the index
--   
--   The type index tells us the type of the decoded file, if any. For
--   files for which the library does not support decoding this will be
--   <tt>()</tt>. NOTE: Clients should NOT rely on this type index being
--   <tt>()</tt>, or they might break if we add support for parsing
--   additional file formats in the future.
--   
--   TODO: If we wanted to support legacy Hackage, we should also have a
--   case for the global preferred-versions file. But supporting legacy
--   Hackage will probably require more work anyway..
data IndexFile :: * -> *
[IndexPkgMetadata] :: PackageIdentifier -> IndexFile (Signed Targets)
[IndexPkgCabal] :: PackageIdentifier -> IndexFile ()
[IndexPkgPrefs] :: PackageName -> IndexFile ()

-- | The layout of the index as maintained on Hackage
hackageIndexLayout :: IndexLayout
indexLayoutPkgMetadata :: IndexLayout -> PackageIdentifier -> IndexPath
indexLayoutPkgCabal :: IndexLayout -> PackageIdentifier -> IndexPath
indexLayoutPkgPrefs :: IndexLayout -> PackageName -> IndexPath

-- | Layout of a repository
data RepoLayout
RepoLayout :: RepoPath -> RepoPath -> RepoPath -> RepoPath -> RepoPath -> RepoPath -> (PackageIdentifier -> RepoPath) -> RepoLayout

-- | TUF root metadata
[repoLayoutRoot] :: RepoLayout -> RepoPath

-- | TUF timestamp
[repoLayoutTimestamp] :: RepoLayout -> RepoPath

-- | TUF snapshot
[repoLayoutSnapshot] :: RepoLayout -> RepoPath

-- | TUF mirrors list
[repoLayoutMirrors] :: RepoLayout -> RepoPath

-- | Compressed index tarball
[repoLayoutIndexTarGz] :: RepoLayout -> RepoPath

-- | Uncompressed index tarball
[repoLayoutIndexTar] :: RepoLayout -> RepoPath

-- | Path to the package tarball
[repoLayoutPkgTarGz] :: RepoLayout -> PackageIdentifier -> RepoPath

-- | The layout used on Hackage
hackageRepoLayout :: RepoLayout

-- | Layout used by cabal for ("legacy") local repos
--   
--   Obviously, such repos do not normally contain any of the TUF files, so
--   their location is more or less arbitrary here.
cabalLocalRepoLayout :: RepoLayout
data Mirrors
Mirrors :: FileVersion -> FileExpires -> [Mirror] -> Mirrors
[mirrorsVersion] :: Mirrors -> FileVersion
[mirrorsExpires] :: Mirrors -> FileExpires
[mirrorsMirrors] :: Mirrors -> [Mirror]

-- | Definition of a mirror
--   
--   NOTE: Unlike the TUF specification, we require that all mirrors must
--   have the same format. That is, we omit <tt>metapath</tt> and
--   <tt>targetspath</tt>.
data Mirror
Mirror :: URI -> MirrorContent -> Mirror
[mirrorUrlBase] :: Mirror -> URI
[mirrorContent] :: Mirror -> MirrorContent

-- | Full versus partial mirrors
--   
--   The TUF spec explicitly allows for partial mirrors, with the mirrors
--   file specifying (through patterns) what is available from partial
--   mirrors.
--   
--   For now we only support full mirrors; if we wanted to add partial
--   mirrors, we would add a second <tt>MirrorPartial</tt> constructor here
--   with arguments corresponding to TUF's <tt>metacontent</tt> and
--   <tt>targetscontent</tt> fields.
data MirrorContent
MirrorFull :: MirrorContent
type MirrorDescription = String

-- | Give a human-readable description of a particular mirror
--   
--   (for use in error messages)
describeMirror :: Mirror -> MirrorDescription

-- | The root of the repository
--   
--   Repository roots can be anchored at a remote URL or a local directory.
--   
--   Note that even for remote repos <a>RepoRoot</a> is (potentially)
--   different from <a>Web</a> -- for a repository located at, say,
--   <tt><a>http://hackage.haskell.org</a></tt> they happen to coincide,
--   but for one location at
--   <tt><a>http://example.com/some/subdirectory</a></tt> they do not.
data RepoRoot

-- | Paths relative to the root of the repository
type RepoPath = Path RepoRoot
anchorRepoPathLocally :: Path root -> RepoPath -> Path root
anchorRepoPathRemotely :: Path Web -> RepoPath -> Path Web

-- | The root of the index tarball
data IndexRoot

-- | Paths relative to the root of the index tarball
type IndexPath = Path IndexRoot

-- | The cache directory
data CacheRoot
type CachePath = Path CacheRoot

-- | Anchor a cache path to the location of the cache
anchorCachePath :: Path root -> CachePath -> Path root

-- | The root metadata
--   
--   NOTE: We must have the invariant that ALL keys (apart from delegation
--   keys) must be listed in <a>rootKeys</a>. (Delegation keys satisfy a
--   similar invariant, see Targets.)
data Root
Root :: FileVersion -> FileExpires -> KeyEnv -> RootRoles -> Root
[rootVersion] :: Root -> FileVersion
[rootExpires] :: Root -> FileExpires
[rootKeys] :: Root -> KeyEnv
[rootRoles] :: Root -> RootRoles
data RootRoles
RootRoles :: RoleSpec Root -> RoleSpec Snapshot -> RoleSpec Targets -> RoleSpec Timestamp -> RoleSpec Mirrors -> RootRoles
[rootRolesRoot] :: RootRoles -> RoleSpec Root
[rootRolesSnapshot] :: RootRoles -> RoleSpec Snapshot
[rootRolesTargets] :: RootRoles -> RoleSpec Targets
[rootRolesTimestamp] :: RootRoles -> RoleSpec Timestamp
[rootRolesMirrors] :: RootRoles -> RoleSpec Mirrors

-- | Role specification
--   
--   The phantom type indicates what kind of type this role is meant to
--   verify.
data RoleSpec a
RoleSpec :: [Some PublicKey] -> KeyThreshold -> RoleSpec a
[roleSpecKeys] :: RoleSpec a -> [Some PublicKey]
[roleSpecThreshold] :: RoleSpec a -> KeyThreshold
data Signed a
Signed :: a -> Signatures -> Signed a
[signed] :: Signed a -> a
[signatures] :: Signed a -> Signatures

-- | A list of signatures
--   
--   Invariant: each signature must be made with a different key. We
--   enforce this invariant for incoming untrusted data
--   (<a>fromPreSignatures</a>) but not for lists of signatures that we
--   create in code.
newtype Signatures
Signatures :: [Signature] -> Signatures
data Signature
Signature :: ByteString -> Some PublicKey -> Signature
[signature] :: Signature -> ByteString
[signatureKey] :: Signature -> Some PublicKey

-- | Create a new document without any signatures
unsigned :: a -> Signed a

-- | Sign a document
withSignatures :: ToJSON WriteJSON a => RepoLayout -> [Some Key] -> a -> Signed a

-- | Variation on <a>withSignatures</a> that doesn't need the repo layout
withSignatures' :: ToJSON Identity a => [Some Key] -> a -> Signed a

-- | Construct signatures for already rendered value
signRendered :: [Some Key] -> ByteString -> Signatures
verifySignature :: ByteString -> Signature -> Bool

-- | General FromJSON instance for signed datatypes
--   
--   We don't give a general FromJSON instance for Signed because for some
--   datatypes we need to do something special (datatypes where we need to
--   read key environments); for instance, see the "Signed Root" instance.
signedFromJSON :: (MonadKeys m, FromJSON m a) => JSValue -> m (Signed a)

-- | Signature verification
--   
--   NOTES: 1. By definition, the signature must be verified against the
--   canonical JSON format. This means we _must_ parse and then pretty
--   print (as we do here) because the document as stored may or may not be
--   in canonical format. 2. However, it is important that we NOT translate
--   from the JSValue to whatever internal datatype we are using and then
--   back to JSValue, because that may not roundtrip: we must allow for
--   additional fields in the JSValue that we ignore (and would therefore
--   lose when we attempt to roundtrip). 3. We verify that all signatures
--   are valid, but we cannot verify (here) that these signatures are
--   signed with the right key, or that we have a sufficient number of
--   signatures. This will be the responsibility of the calling code.
verifySignatures :: JSValue -> Signatures -> Bool

-- | File with uninterpreted signatures
--   
--   Sometimes we want to be able to read a file without interpreting the
--   signatures (that is, resolving the key IDs) or doing any kind of
--   checks on them. One advantage of this is that this allows us to read
--   many file types without any key environment at all, which is sometimes
--   useful.
data UninterpretedSignatures a
UninterpretedSignatures :: a -> [PreSignature] -> UninterpretedSignatures a
[uninterpretedSigned] :: UninterpretedSignatures a -> a
[uninterpretedSignatures] :: UninterpretedSignatures a -> [PreSignature]

-- | A signature with a key ID (rather than an actual key)
--   
--   This corresponds precisely to the TUF representation of a signature.
data PreSignature
PreSignature :: ByteString -> Some KeyType -> KeyId -> PreSignature
[presignature] :: PreSignature -> ByteString
[presigMethod] :: PreSignature -> Some KeyType
[presigKeyId] :: PreSignature -> KeyId

-- | Convert a pre-signature to a signature
--   
--   Verifies that the key type matches the advertised method.
fromPreSignature :: MonadKeys m => PreSignature -> m Signature

-- | Convert a list of <a>PreSignature</a>s to a list of <a>Signature</a>s
--   
--   This verifies the invariant that all signatures are made with
--   different keys. We do this on the presignatures rather than the
--   signatures so that we can do the check on key IDs, rather than keys
--   (the latter don't have an Ord instance).
fromPreSignatures :: MonadKeys m => [PreSignature] -> m Signatures

-- | Convert signature to pre-signature
toPreSignature :: Signature -> PreSignature

-- | Convert list of pre-signatures to a list of signatures
toPreSignatures :: Signatures -> [PreSignature]
data Snapshot
Snapshot :: FileVersion -> FileExpires -> FileInfo -> FileInfo -> FileInfo -> Maybe FileInfo -> Snapshot
[snapshotVersion] :: Snapshot -> FileVersion
[snapshotExpires] :: Snapshot -> FileExpires

-- | File info for the root metadata
--   
--   We list this explicitly in the snapshot so that we can check if we
--   need to update the root metadata without first having to download the
--   entire index tarball.
[snapshotInfoRoot] :: Snapshot -> FileInfo

-- | File info for the mirror metadata
[snapshotInfoMirrors] :: Snapshot -> FileInfo

-- | Compressed index tarball
[snapshotInfoTarGz] :: Snapshot -> FileInfo

-- | Uncompressed index tarball
--   
--   Repositories are not required to provide this.
[snapshotInfoTar] :: Snapshot -> Maybe FileInfo

-- | Target metadata
--   
--   Most target files do not need expiry dates because they are not
--   subject to change (and hence attacks like freeze attacks are not a
--   concern).
data Targets
Targets :: FileVersion -> FileExpires -> FileMap -> Maybe Delegations -> Targets
[targetsVersion] :: Targets -> FileVersion
[targetsExpires] :: Targets -> FileExpires
[targetsTargets] :: Targets -> FileMap
[targetsDelegations] :: Targets -> Maybe Delegations

-- | Delegations
--   
--   Much like the Root datatype, this must have an invariant that ALL used
--   keys (apart from the global keys, which are in the root key
--   environment) must be listed in <a>delegationsKeys</a>.
data Delegations
Delegations :: KeyEnv -> [DelegationSpec] -> Delegations
[delegationsKeys] :: Delegations -> KeyEnv
[delegationsRoles] :: Delegations -> [DelegationSpec]

-- | Delegation specification
--   
--   NOTE: This is a close analogue of <tt>RoleSpec</tt>.
data DelegationSpec
DelegationSpec :: [Some PublicKey] -> KeyThreshold -> Delegation -> DelegationSpec
[delegationSpecKeys] :: DelegationSpec -> [Some PublicKey]
[delegationSpecThreshold] :: DelegationSpec -> KeyThreshold
[delegation] :: DelegationSpec -> Delegation

-- | A delegation
--   
--   A delegation is a pair of a pattern and a replacement.
--   
--   See <tt>match</tt> for an example.
data Delegation
Delegation :: (Pattern a) -> (Replacement a) -> Delegation
targetsLookup :: TargetPath -> Targets -> Maybe FileInfo
data Timestamp
Timestamp :: FileVersion -> FileExpires -> FileInfo -> Timestamp
[timestampVersion] :: Timestamp -> FileVersion
[timestampExpires] :: Timestamp -> FileExpires
[timestampInfoSnapshot] :: Timestamp -> FileInfo

module Hackage.Security.Trusted

-- | Trusted values
--   
--   Trusted values originate in only two ways:
--   
--   <ul>
--   <li>Anything that is statically known is trusted
--   (<a>trustStatic</a>)</li>
--   <li>If we have "dynamic" data we can trust it once we have verified
--   the the signatures (trustSigned).</li>
--   </ul>
--   
--   NOTE: Trusted is NOT a functor. If it was we could define
--   
--   <pre>
--   trustAnything :: a -&gt; Trusted a
--   trustAnything a = fmap (const a) (trustStatic (static ()))
--   </pre>
--   
--   Consequently, it is neither a monad nor a comonad. However, we _can_
--   apply trusted functions to trusted arguments (<a>trustApply</a>).
--   
--   The <a>DeclareTrusted</a> constructor is exported, but any use of it
--   should be verified.
newtype Trusted a
DeclareTrusted :: a -> Trusted a
[trusted] :: Trusted a -> a
trustStatic :: StaticPtr a -> Trusted a
trustVerified :: SignaturesVerified a -> Trusted a

-- | Equivalent of <a>&lt;*&gt;</a>
--   
--   Trusted isn't quite applicative (no pure, not a functor), but it is
--   somehow Applicative-like: we have the equivalent of <a>&lt;*&gt;</a>
trustApply :: Trusted (a -> b) -> Trusted a -> Trusted b

-- | Trust all elements of some trusted (traversable) container
--   
--   If we have, say, a trusted list of values, we should be able to get a
--   list of trusted values out of it.
--   
--   <pre>
--   trustElems :: Trusted [a] -&gt; [Trusted a]
--   </pre>
--   
--   NOTE. It might appear that the more natural primitive to offer is a
--   <a>sequenceA</a>-like operator such as
--   
--   <pre>
--   trustSeq :: Applicative f =&gt; Trusted (f a) -&gt; f (Trusted a)
--   </pre>
--   
--   However, this is unsound. To see this, consider that <tt>((-&gt;)
--   a)</tt> is <a>Applicative</a> (it's the reader monad); hence, we can
--   instantiate <tt>trustSeq</tt> at
--   
--   <pre>
--   trustSeq :: Trusted (a -&gt; a) -&gt; a -&gt; Trusted a
--   </pre>
--   
--   and by passing <tt>trustStatic (static id)</tt> make <a>Trusted</a> a
--   functor, which we certainly don't want to do (see comments for
--   <a>Trusted</a>).
--   
--   So why is it okay when we insist on <a>Traversable</a> rather than
--   <a>Applicative</a>? To see this, it's instructive to consider how we
--   might make a <tt>((-&gt;) a)</tt> an instance of <a>Traversable</a>.
--   If we define the domain of enumerable types as
--   
--   <pre>
--   class Eq a =&gt; Enumerable a where
--     enumerate :: [a]
--   </pre>
--   
--   then we can make <tt>((-&gt;) r)</tt> traversable by
--   
--   <pre>
--   instance Enumerable r =&gt; Traversable ((-&gt;) r) where
--     sequenceA f = rebuild &lt;$&gt; sequenceA ((\r -&gt; (r,) &lt;$&gt; f r) &lt;$&gt; enumerate)
--       where
--         rebuild :: [(r, a)] -&gt; r -&gt; a
--         rebuild fun arg = fromJust (lookup arg fun)
--   </pre>
--   
--   The idea is that if the domain of a function is enumerable, we can
--   apply the function to each possible input, collect the outputs, and
--   construct a new function by pairing the inputs with the outputs. I.e.,
--   if we had something of type
--   
--   <pre>
--   a -&gt; IO b
--   </pre>
--   
--   and <tt>a</tt> is enumerable, we just run the <tt>IO</tt> action on
--   each possible <tt>a</tt> and collect all <tt>b</tt>s to get a pure
--   function <tt>a -&gt; b</tt>. Of course, you probably don't want to be
--   doing that, but the point is that as far as the type system is
--   concerned you could.
--   
--   In the context of <a>Trusted</a>, this means that we can derive
--   
--   <pre>
--   enumPure :: Enumerable a =&gt; a -&gt; Trusted a
--   </pre>
--   
--   but in a way this this makes sense anyway. If a domain is enumerable,
--   it would not be unreasonable to change <tt>Enumerable</tt> to
--   
--   <pre>
--   class Eq a =&gt; Enumerable a where
--     enumerate :: [StaticPtr a]
--   </pre>
--   
--   so we could define <tt>enumPure</tt> as
--   
--   <pre>
--   enumPure :: Enumerable a =&gt; a -&gt; Trusted a
--   enumPure x = trustStatic
--              $ fromJust (find ((== x) . deRefStaticPtr) enumerate)
--   </pre>
--   
--   In other words, we just enumerate the entire domain as trusted values
--   (because we defined them locally) and then return the one that matched
--   the untrusted value.
--   
--   The conclusion from all of this is that the types of untrusted input
--   (like the types of the TUF files we download from the server) should
--   probably not be considered enumerable.
trustElems :: Traversable f => Trusted (f a) -> f (Trusted a)

-- | Errors thrown during role validation
data VerificationError

-- | Not enough signatures signed with the appropriate keys
VerificationErrorSignatures :: TargetPath -> VerificationError

-- | The file is expired
VerificationErrorExpired :: TargetPath -> VerificationError

-- | The file version is less than the previous version
VerificationErrorVersion :: TargetPath -> VerificationError

-- | File information mismatch
VerificationErrorFileInfo :: TargetPath -> VerificationError

-- | We tried to lookup file information about a particular target file,
--   but the information wasn't in the corresponding <tt>targets.json</tt>
--   file.
VerificationErrorUnknownTarget :: TargetPath -> VerificationError

-- | The metadata for the specified target is missing a SHA256
VerificationErrorMissingSHA256 :: TargetPath -> VerificationError

-- | Some verification errors materialize as deserialization errors
--   
--   For example: if we try to deserialize a timestamp file but the
--   timestamp key has been rolled over, deserialization of the file will
--   fail with <a>DeserializationErrorUnknownKey</a>.
VerificationErrorDeserialization :: TargetPath -> DeserializationError -> VerificationError

-- | The spec stipulates that if a verification error occurs during the
--   check for updates, we must download new root information and start
--   over. However, we limit how often we attempt this.
--   
--   We record all verification errors that occurred before we gave up.
VerificationErrorLoop :: VerificationHistory -> VerificationError

-- | Root metadata updated (as part of the normal update process)
data RootUpdated
RootUpdated :: RootUpdated
type VerificationHistory = [Either RootUpdated VerificationError]
data SignaturesVerified a
signaturesVerified :: SignaturesVerified a -> a

-- | Role verification
--   
--   NOTE: We throw an error when the version number _decreases_, but allow
--   it to be the same. This is sufficient: the file number is there so
--   that attackers cannot replay old files. It cannot protect against
--   freeze attacks (that's what the expiry date is for), so "replaying"
--   the same file is not a problem. If an attacker changes the contents of
--   the file but not the version number we have an inconsistent situation,
--   but this is not something we need to worry about: in this case the
--   attacker will need to resign the file or otherwise the signature won't
--   match, and if the attacker has compromised the key then he might just
--   as well increase the version number and resign.
--   
--   NOTE 2: We are not actually verifying the signatures _themselves_ here
--   (we did that when we parsed the JSON). We are merely verifying the
--   provenance of the keys.
verifyRole' :: forall a. HasHeader a => Trusted (RoleSpec a) -> TargetPath -> Maybe FileVersion -> Maybe UTCTime -> Signed a -> Either VerificationError (SignaturesVerified a)

-- | Variation on <tt>verifyRole</tt> that uses key IDs rather than keys
--   
--   This is used during the bootstrap process.
--   
--   See <a>http://en.wikipedia.org/wiki/Public_key_fingerprint</a>.
verifyFingerprints :: [KeyId] -> KeyThreshold -> TargetPath -> Signed Root -> Either VerificationError (SignaturesVerified Root)

-- | A reference to a value of type <tt>a</tt>.
data StaticPtr a :: * -> *

-- | Apply a static function to a trusted argument
(<$$>) :: StaticPtr (a -> b) -> Trusted a -> Trusted b
class VerifyRole a
verifyRole :: VerifyRole a => Trusted Root -> TargetPath -> Maybe FileVersion -> Maybe UTCTime -> Signed a -> Either VerificationError (SignaturesVerified a)

-- | Variation on <a>knownFileInfoEqual</a> for <a>Trusted</a>
--   <a>FileInfo</a>
trustedFileInfoEqual :: Trusted FileInfo -> Trusted FileInfo -> Bool
instance Hackage.Security.Trusted.VerifyRole Hackage.Security.TUF.Root.Root
instance Hackage.Security.Trusted.VerifyRole Hackage.Security.TUF.Timestamp.Timestamp
instance Hackage.Security.Trusted.VerifyRole Hackage.Security.TUF.Snapshot.Snapshot
instance Hackage.Security.Trusted.VerifyRole Hackage.Security.TUF.Mirrors.Mirrors

module Hackage.Security.Client.Verify

-- | Verification monad
--   
--   The verification monad is similar to <tt>ResourceT</tt> in intent, in
--   that we can register handlers to be run to release resources. Unlike
--   <tt>ResourceT</tt>, however, we maintain _two_ handlers: a cleanup
--   handler which is run whether or not verification succeeds, and a
--   finalisation handler which is run only if verification succeeds.
--   
--   <ul>
--   <li>Cleanup handlers are registered using <a>acquire</a>, and are
--   guaranteed to run just before the computation terminates (after the
--   finalisation handler).</li>
--   <li>The finalisation handlers are run only when verification succeeds,
--   and can be registered with <a>ifVerified</a>. Finalisation can be used
--   for instance to update the local cache (which should only happen if
--   verification is successful).</li>
--   </ul>
data Verify a

-- | Run an action in the <a>Verify</a> monad
runVerify :: (Finaliser -> Finaliser) -> Verify a -> IO a

-- | Acquire a resource and register the corresponding cleanup handler
--   
--   NOTE: Resource acquisition happens with exceptions masked. If it is
--   important that the resource acquistion can be timed out (or receive
--   other kinds of asynchronous exceptions), you will need to use an
--   interruptible operation. See
--   <a>http://www.well-typed.com/blog/2014/08/asynchronous-exceptions/</a>
--   for details.
acquire :: IO a -> (a -> IO ()) -> Verify a

-- | Register an action to be run only if verification succeeds
ifVerified :: IO () -> Verify ()

-- | Create a short-lived temporary file
--   
--   Creates the directory where the temp file should live if it does not
--   exist.
openTempFile :: FsRoot root => Path root -> String -> Verify (Path Absolute, Handle)

-- | Lift a computation from the <a>IO</a> monad.
liftIO :: MonadIO m => forall a. IO a -> m a
instance Control.Monad.IO.Class.MonadIO Hackage.Security.Client.Verify.Verify
instance GHC.Base.Monad Hackage.Security.Client.Verify.Verify
instance GHC.Base.Applicative Hackage.Security.Client.Verify.Verify
instance GHC.Base.Functor Hackage.Security.Client.Verify.Verify

module Hackage.Security.Client.Formats
data FormatUn
data FormatGz

-- | Format is a singleton type (reflection type to term level)
--   
--   NOTE: In the future we might add further compression formats.
data Format :: * -> *
[FUn] :: Format FormatUn
[FGz] :: Format FormatGz

-- | Available formats
--   
--   Rather than having a general list here, we enumerate all
--   possibilities. This means we are very precise about what we expect,
--   and we avoid any runtime errors about unexpect format definitions.
--   
--   NOTE: If we add additional cases here (for dealing with additional
--   formats) all calls to <tt>error "inaccessible"</tt> need to be
--   reevaluated.
data Formats :: * -> * -> *
[FsNone] :: Formats () a
[FsUn] :: a -> Formats (FormatUn :- ()) a
[FsGz] :: a -> Formats (FormatGz :- ()) a
[FsUnGz] :: a -> a -> Formats (FormatUn :- (FormatGz :- ())) a

-- | <tt>HasFormat fs f</tt> is a proof that <tt>f</tt> is a key in
--   <tt>fs</tt>.
--   
--   See <a>formatsMember</a> and <a>formatsLookup</a> for typical usage.
data HasFormat :: * -> * -> *
[HFZ] :: Format f -> HasFormat (f :- fs) f
[HFS] :: HasFormat fs f -> HasFormat (f' :- fs) f
hasFormatAbsurd :: HasFormat () f -> a
hasFormatGet :: HasFormat fs f -> Format f
formatsMap :: (forall f. Format f -> a -> b) -> Formats fs a -> Formats fs b
formatsMember :: Format f -> Formats fs a -> Maybe (HasFormat fs f)
formatsLookup :: HasFormat fs f -> Formats fs a -> a
instance GHC.Show.Show (Hackage.Security.Client.Formats.Format f)
instance GHC.Classes.Eq (Hackage.Security.Client.Formats.Format f)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Hackage.Security.Client.Formats.Formats fs a)
instance GHC.Show.Show a => GHC.Show.Show (Hackage.Security.Client.Formats.Formats fs a)
instance GHC.Classes.Eq (Hackage.Security.Client.Formats.HasFormat fs f)
instance GHC.Show.Show (Hackage.Security.Client.Formats.HasFormat fs f)
instance Hackage.Security.Util.TypedEmbedded.Unify Hackage.Security.Client.Formats.Format
instance GHC.Base.Functor (Hackage.Security.Client.Formats.Formats fs)


-- | Abstract definition of a Repository
--   
--   Most clients should only need to import this module if they wish to
--   define their own Repository implementations.
module Hackage.Security.Client.Repository
data Metadata
data Binary

-- | Abstract definition of files we might have to download
--   
--   <a>RemoteFile</a> is parametrized by the type of the formats that we
--   can accept from the remote repository, as well as with information on
--   whether this file is metadata actual binary content.
--   
--   NOTE: Haddock lacks GADT support so constructors have only regular
--   comments.
data RemoteFile :: * -> * -> *
[RemoteTimestamp] :: RemoteFile (FormatUn :- ()) Metadata
[RemoteRoot] :: Maybe (Trusted FileInfo) -> RemoteFile (FormatUn :- ()) Metadata
[RemoteSnapshot] :: Trusted FileInfo -> RemoteFile (FormatUn :- ()) Metadata
[RemoteMirrors] :: Trusted FileInfo -> RemoteFile (FormatUn :- ()) Metadata
[RemoteIndex] :: HasFormat fs FormatGz -> Formats fs (Trusted FileInfo) -> RemoteFile fs Binary
[RemotePkgTarGz] :: PackageIdentifier -> Trusted FileInfo -> RemoteFile (FormatGz :- ()) Binary

-- | Files that we might request from the local cache
data CachedFile

-- | Timestamp metadata (<tt>timestamp.json</tt>)
CachedTimestamp :: CachedFile

-- | Root metadata (<tt>root.json</tt>)
CachedRoot :: CachedFile

-- | Snapshot metadata (<tt>snapshot.json</tt>)
CachedSnapshot :: CachedFile

-- | Mirrors list (<tt>mirrors.json</tt>)
CachedMirrors :: CachedFile

-- | Files that we might request from the index
--   
--   The type index tells us the type of the decoded file, if any. For
--   files for which the library does not support decoding this will be
--   <tt>()</tt>. NOTE: Clients should NOT rely on this type index being
--   <tt>()</tt>, or they might break if we add support for parsing
--   additional file formats in the future.
--   
--   TODO: If we wanted to support legacy Hackage, we should also have a
--   case for the global preferred-versions file. But supporting legacy
--   Hackage will probably require more work anyway..
data IndexFile :: * -> *
[IndexPkgMetadata] :: PackageIdentifier -> IndexFile (Signed Targets)
[IndexPkgCabal] :: PackageIdentifier -> IndexFile ()
[IndexPkgPrefs] :: PackageName -> IndexFile ()

-- | Default format for each file type
--   
--   For most file types we don't have a choice; for the index the
--   repository is only required to offer the GZip-compressed format so
--   that is the default.
remoteFileDefaultFormat :: RemoteFile fs typ -> Some (HasFormat fs)

-- | Default file info (see also <a>remoteFileDefaultFormat</a>)
remoteFileDefaultInfo :: RemoteFile fs typ -> Maybe (Trusted FileInfo)

-- | Repository
--   
--   This is an abstract representation of a repository. It simply provides
--   a way to download metafiles and target files, without specifying how
--   this is done. For instance, for a local repository this could just be
--   doing a file read, whereas for remote repositories this could be using
--   any kind of HTTP client.
data Repository down
Repository :: (forall fs typ. Throws SomeRemoteError => AttemptNr -> RemoteFile fs typ -> Verify (Some (HasFormat fs), down typ)) -> (CachedFile -> IO (Maybe (Path Absolute))) -> IO (Path Absolute) -> IO () -> (forall a. (Handle -> IO a) -> IO a) -> IO TarIndex -> (IO () -> IO ()) -> (forall a. Maybe [Mirror] -> IO a -> IO a) -> (LogMessage -> IO ()) -> RepoLayout -> IndexLayout -> String -> Repository down

-- | Get a file from the server
--   
--   Responsibilies of <a>repGetRemote</a>:
--   
--   <ul>
--   <li>Download the file from the repository and make it available at a
--   temporary location</li>
--   <li>Use the provided file length to protect against endless data
--   attacks. (Repositories such as local repositories that are not
--   suspectible to endless data attacks can safely ignore this
--   argument.)</li>
--   <li>Move the file from its temporary location to its permanent
--   location if verification succeeds.</li>
--   </ul>
--   
--   NOTE: Calls to <a>repGetRemote</a> should _always_ be in the scope of
--   <a>repWithMirror</a>.
[repGetRemote] :: Repository down -> forall fs typ. Throws SomeRemoteError => AttemptNr -> RemoteFile fs typ -> Verify (Some (HasFormat fs), down typ)

-- | Get a cached file (if available)
[repGetCached] :: Repository down -> CachedFile -> IO (Maybe (Path Absolute))

-- | Get the cached root
--   
--   This is a separate method only because clients must ALWAYS have root
--   information available.
[repGetCachedRoot] :: Repository down -> IO (Path Absolute)

-- | Clear all cached data
--   
--   In particular, this should remove the snapshot and the timestamp. It
--   would also be okay, but not required, to delete the index.
[repClearCache] :: Repository down -> IO ()

-- | Open the tarball for reading
--   
--   This function has this shape so that:
--   
--   <ul>
--   <li>We can read multiple files from the tarball without having to open
--   and close the handle each time</li>
--   <li>We can close the handle immediately when done.</li>
--   </ul>
[repWithIndex] :: Repository down -> forall a. (Handle -> IO a) -> IO a

-- | Read the index index
[repGetIndexIdx] :: Repository down -> IO TarIndex

-- | Lock the cache (during updates)
[repLockCache] :: Repository down -> IO () -> IO ()

-- | Mirror selection
--   
--   The purpose of <a>repWithMirror</a> is to scope mirror selection. The
--   idea is that if we have
--   
--   <pre>
--   repWithMirror mirrorList $
--     someCallback
--   </pre>
--   
--   then the repository may pick a mirror before calling
--   <tt>someCallback</tt>, catch exceptions thrown by
--   <tt>someCallback</tt>, and potentially try the callback again with a
--   different mirror.
--   
--   The list of mirrors may be <tt>Nothing</tt> if we haven't yet
--   downloaded the list of mirrors from the repository, or when our cached
--   list of mirrors is invalid. Of course, if we did download it, then the
--   list of mirrors may still be empty. In this case the repository must
--   fall back to its primary download mechanism.
--   
--   Mirrors as currently defined (in terms of a "base URL") are inherently
--   a HTTP (or related) concept, so in repository implementations such as
--   the local-repo <tt>repWithMirrors</tt> is probably just an identity
--   operation (see <tt>ignoreMirrors</tt>). Conversely, HTTP
--   implementations of repositories may have other, out-of-band
--   information (for example, coming from a cabal config file) that they
--   may use to influence mirror selection.
[repWithMirror] :: Repository down -> forall a. Maybe [Mirror] -> IO a -> IO a

-- | Logging
[repLog] :: Repository down -> LogMessage -> IO ()

-- | Layout of this repository
[repLayout] :: Repository down -> RepoLayout

-- | Layout of the index
--   
--   Since the repository hosts the index, the layout of the index is not
--   independent of the layout of the repository.
[repIndexLayout] :: Repository down -> IndexLayout

-- | Description of the repository (used in the show instance)
[repDescription] :: Repository down -> String

-- | Are we requesting this information because of a previous validation
--   error?
--   
--   Clients can take advantage of this to tell caches to revalidate files.
newtype AttemptNr
AttemptNr :: Int -> AttemptNr

-- | Log messages
--   
--   We use a <a>RemoteFile</a> rather than a <a>RepoPath</a> here because
--   we might not have a <a>RepoPath</a> for the file that we were trying
--   to download (that is, for example if the server does not provide an
--   uncompressed tarball, it doesn't make much sense to list the path to
--   that non-existing uncompressed tarball).
data LogMessage

-- | Root information was updated
--   
--   This message is issued when the root information is updated as part of
--   the normal check for updates procedure. If the root information is
--   updated because of a verification error WarningVerificationError is
--   issued instead.
LogRootUpdated :: LogMessage

-- | A verification error
--   
--   Verification errors can be temporary, and may be resolved later; hence
--   these are just warnings. (Verification errors that cannot be resolved
--   are thrown as exceptions.)
LogVerificationError :: VerificationError -> LogMessage

-- | Download a file from a repository
LogDownloading :: (RemoteFile fs typ) -> LogMessage

-- | Incrementally updating a file from a repository
LogUpdating :: (RemoteFile fs Binary) -> LogMessage

-- | Selected a particular mirror
LogSelectedMirror :: MirrorDescription -> LogMessage

-- | Updating a file failed (we will instead download it whole)
LogCannotUpdate :: (RemoteFile fs Binary) -> UpdateFailure -> LogMessage

-- | We got an exception with a particular mirror (we will try with a
--   different mirror if any are available)
LogMirrorFailed :: MirrorDescription -> SomeException -> LogMessage

-- | Records why we are downloading a file rather than updating it.
data UpdateFailure

-- | Server does not support incremental downloads
UpdateImpossibleUnsupported :: UpdateFailure

-- | We don't have a local copy of the file to update
UpdateImpossibleNoLocalCopy :: UpdateFailure

-- | Update failed twice
--   
--   If we attempt an incremental update the first time, and it fails, we
--   let it go round the loop, update local security information, and try
--   again. But if an incremental update then fails _again_, we instead
--   attempt a regular download.
UpdateFailedTwice :: UpdateFailure

-- | Update failed (for example: perhaps the local file got corrupted)
UpdateFailed :: SomeException -> UpdateFailure

-- | Repository-specific exceptions
--   
--   For instance, for repositories using HTTP this might correspond to a
--   404; for local repositories this might correspond to file-not-found,
--   etc.
data SomeRemoteError :: *
[SomeRemoteError] :: Exception e => e -> SomeRemoteError
class DownloadedFile (down :: * -> *)

-- | Verify a download file
downloadedVerify :: DownloadedFile down => down a -> Trusted FileInfo -> IO Bool

-- | Read the file we just downloaded into memory
--   
--   We never read binary data, only metadata.
downloadedRead :: DownloadedFile down => down Metadata -> IO ByteString

-- | Copy a downloaded file to its destination
downloadedCopyTo :: DownloadedFile down => down a -> Path Absolute -> IO ()

-- | Helper function to implement <tt>repWithMirrors</tt>.
mirrorsUnsupported :: Maybe [Mirror] -> IO a -> IO a
remoteRepoPath :: RepoLayout -> RemoteFile fs typ -> Formats fs RepoPath
remoteRepoPath' :: RepoLayout -> RemoteFile fs typ -> HasFormat fs f -> RepoPath

-- | Is a particular remote file cached?
data IsCached :: * -> *
[CacheAs] :: CachedFile -> IsCached Metadata
[DontCache] :: IsCached Binary
[CacheIndex] :: IsCached Binary

-- | Which remote files should we cache locally?
mustCache :: RemoteFile fs typ -> IsCached typ
instance GHC.Num.Num Hackage.Security.Client.Repository.AttemptNr
instance GHC.Classes.Ord Hackage.Security.Client.Repository.AttemptNr
instance GHC.Classes.Eq Hackage.Security.Client.Repository.AttemptNr
instance GHC.Show.Show Hackage.Security.Client.Repository.CachedFile
instance GHC.Classes.Ord Hackage.Security.Client.Repository.CachedFile
instance GHC.Classes.Eq Hackage.Security.Client.Repository.CachedFile
instance GHC.Show.Show (Hackage.Security.Client.Repository.RemoteFile fs typ)
instance GHC.Show.Show Hackage.Security.Client.Repository.SomeRemoteError
instance GHC.Classes.Eq (Hackage.Security.Client.Repository.IsCached typ)
instance GHC.Show.Show (Hackage.Security.Client.Repository.IsCached typ)
instance Hackage.Security.Util.Pretty.Pretty (Hackage.Security.Client.Repository.RemoteFile fs typ)
instance Hackage.Security.Util.Pretty.Pretty Hackage.Security.Client.Repository.CachedFile
instance GHC.Show.Show (Hackage.Security.Client.Repository.Repository down)
instance GHC.Exception.Exception Hackage.Security.Client.Repository.SomeRemoteError
instance Hackage.Security.Util.Pretty.Pretty Hackage.Security.Client.Repository.SomeRemoteError
instance Hackage.Security.Util.Pretty.Pretty Hackage.Security.Client.Repository.LogMessage
instance Hackage.Security.Util.Pretty.Pretty Hackage.Security.Client.Repository.UpdateFailure


-- | Abstracting over HTTP libraries
module Hackage.Security.Client.Repository.HttpLib

-- | Abstraction over HTTP clients
--   
--   This avoids insisting on a particular implementation (such as the HTTP
--   package) and allows for other implementations (such as a conduit based
--   one).
--   
--   NOTE: Library-specific exceptions MUST be wrapped in
--   <a>SomeRemoteError</a>.
data HttpLib
HttpLib :: (forall a. Throws SomeRemoteError => [HttpRequestHeader] -> URI -> ([HttpResponseHeader] -> BodyReader -> IO a) -> IO a) -> (forall a. Throws SomeRemoteError => [HttpRequestHeader] -> URI -> (Int, Int) -> (HttpStatus -> [HttpResponseHeader] -> BodyReader -> IO a) -> IO a) -> HttpLib

-- | Download a file
[httpGet] :: HttpLib -> forall a. Throws SomeRemoteError => [HttpRequestHeader] -> URI -> ([HttpResponseHeader] -> BodyReader -> IO a) -> IO a

-- | Download a byte range
--   
--   Range is starting and (exclusive) end offset in bytes.
--   
--   HTTP servers are normally expected to respond to a range request with
--   a "206 Partial Content" response. However, servers can respond with a
--   "200 OK" response, sending the entire file instead (for instance, this
--   may happen for servers that don't actually support range rqeuests, but
--   for which we optimistically assumed they did). Implementations of
--   <a>HttpLib</a> may accept such a response and inform the
--   <tt>hackage-security</tt> library that the whole file is being
--   returned; the security library can then decide to execute the
--   <a>BodyReader</a> anyway (downloading the entire file) or abort the
--   request and try something else. For this reason the security library
--   must be informed whether the server returned the full file or the
--   requested range.
[httpGetRange] :: HttpLib -> forall a. Throws SomeRemoteError => [HttpRequestHeader] -> URI -> (Int, Int) -> (HttpStatus -> [HttpResponseHeader] -> BodyReader -> IO a) -> IO a

-- | Additional request headers
--   
--   Since different libraries represent headers differently, here we just
--   abstract over the few request headers that we might want to set
data HttpRequestHeader

-- | Set <tt>Cache-Control: max-age=0</tt>
HttpRequestMaxAge0 :: HttpRequestHeader

-- | Set <tt>Cache-Control: no-transform</tt>
HttpRequestNoTransform :: HttpRequestHeader

-- | Response headers
--   
--   Since different libraries represent headers differently, here we just
--   abstract over the few response headers that we might want to know
--   about.
data HttpResponseHeader

-- | Server accepts byte-range requests (<tt>Accept-Ranges: bytes</tt>)
HttpResponseAcceptRangesBytes :: HttpResponseHeader

-- | HTTP status code
data HttpStatus

-- | 200 OK
HttpStatus200OK :: HttpStatus

-- | 206 Partial Content
HttpStatus206PartialContent :: HttpStatus

-- | Proxy configuration
--   
--   Although actually setting the proxy is the purview of the
--   initialization function for individual <a>HttpLib</a> implementations
--   and therefore outside the scope of this module, we offer this
--   <tt>ProxyConfiguration</tt> type here as a way to uniformly configure
--   proxies across all <a>HttpLib</a>s.
data ProxyConfig a

-- | Don't use a proxy
ProxyConfigNone :: ProxyConfig a

-- | Use this specific proxy
--   
--   Individual HTTP backends use their own types for specifying proxies.
ProxyConfigUse :: a -> ProxyConfig a

-- | Use automatic proxy settings
--   
--   What precisely automatic means is <a>HttpLib</a> specific, though
--   typically it will involve looking at the <tt>HTTP_PROXY</tt>
--   environment variable or the (Windows) registry.
ProxyConfigAuto :: ProxyConfig a

-- | An <tt>IO</tt> action that represents an incoming response body coming
--   from the server.
--   
--   The action gets a single chunk of data from the response body, or an
--   empty bytestring if no more data is available.
--   
--   This definition is copied from the <tt>http-client</tt> package.
type BodyReader = IO ByteString

-- | Construct a <tt>Body</tt> reader from a lazy bytestring
--   
--   This is appropriate if the lazy bytestring is constructed, say, by
--   calling <tt>hGetContents</tt> on a network socket, and the chunks of
--   the bytestring correspond to the chunks as they are returned from the
--   OS network layer.
--   
--   If the lazy bytestring needs to be re-chunked this function is NOT
--   suitable.
bodyReaderFromBS :: ByteString -> IO BodyReader
instance GHC.Show.Show Hackage.Security.Client.Repository.HttpLib.HttpResponseHeader
instance GHC.Classes.Ord Hackage.Security.Client.Repository.HttpLib.HttpResponseHeader
instance GHC.Classes.Eq Hackage.Security.Client.Repository.HttpLib.HttpResponseHeader
instance GHC.Show.Show Hackage.Security.Client.Repository.HttpLib.HttpRequestHeader
instance GHC.Classes.Ord Hackage.Security.Client.Repository.HttpLib.HttpRequestHeader
instance GHC.Classes.Eq Hackage.Security.Client.Repository.HttpLib.HttpRequestHeader


-- | The files we cache from the repository
--   
--   Both the Local and the Remote repositories make use of this module.
module Hackage.Security.Client.Repository.Cache

-- | Location and layout of the local cache
data Cache
Cache :: Path Absolute -> CacheLayout -> Cache
[cacheRoot] :: Cache -> Path Absolute
[cacheLayout] :: Cache -> CacheLayout

-- | Get a cached file (if available)
getCached :: Cache -> CachedFile -> IO (Maybe (Path Absolute))

-- | Get the cached root
--   
--   Calling <a>getCachedRoot</a> without root info available is a
--   programmer error and will result in an unchecked exception. See
--   <tt>requiresBootstrap</tt>.
getCachedRoot :: Cache -> IO (Path Absolute)

-- | Get the cached index (if available)
getCachedIndex :: Cache -> Format f -> IO (Maybe (Path Absolute))

-- | Delete a previously downloaded remote file
clearCache :: Cache -> IO ()
withIndex :: Cache -> (Handle -> IO a) -> IO a
getIndexIdx :: Cache -> IO TarIndex

-- | Cache a previously downloaded remote file
cacheRemoteFile :: forall down typ f. DownloadedFile down => Cache -> down typ -> Format f -> IsCached typ -> IO ()

-- | Lock the cache
--   
--   This avoids two concurrent processes updating the cache at the same
--   time, provided they both take the lock.
lockCache :: Cache -> IO () -> IO ()


-- | Local repository
module Hackage.Security.Client.Repository.Local

-- | Location of the repository
--   
--   Note that we regard the local repository as immutable; we cache files
--   just like we do for remote repositories.
type LocalRepo = Path Absolute
data LocalFile a

-- | Initialize the repository (and cleanup resources afterwards)
--   
--   Like a remote repository, a local repository takes a RepoLayout as
--   argument; but where the remote repository interprets this RepoLayout
--   relative to a URL, the local repository interprets it relative to a
--   local directory.
--   
--   It uses the same cache as the remote repository.
withRepository :: LocalRepo -> Cache -> RepoLayout -> IndexLayout -> (LogMessage -> IO ()) -> (Repository LocalFile -> IO a) -> IO a
instance Hackage.Security.Client.Repository.DownloadedFile Hackage.Security.Client.Repository.Local.LocalFile


-- | An implementation of Repository that talks to repositories over HTTP.
--   
--   This implementation is itself parameterized over a
--   <tt>HttpClient</tt>, so that it it not tied to a specific library; for
--   instance, <tt>HttpClient</tt> can be implemented with the
--   <tt>HTTP</tt> library, the <tt>http-client</tt> libary, or others.
--   
--   It would also be possible to give _other_ Repository implementations
--   that talk to repositories over HTTP, if you want to make other design
--   decisions than we did here, in particular:
--   
--   <ul>
--   <li>We attempt to do incremental downloads of the index when
--   possible.</li>
--   <li>We reuse the <a>Repository.Local</a> to deal with the local
--   cache.</li>
--   <li>We download <tt>timestamp.json</tt> and <tt>snapshot.json</tt>
--   together. This is implemented here because:</li>
--   <li>One level down (HttpClient) we have no access to the local
--   cache</li>
--   <li>One level up (Repository API) would require _all_ Repositories to
--   implement this optimization.</li>
--   </ul>
module Hackage.Security.Client.Repository.Remote

-- | Initialize the repository (and cleanup resources afterwards)
--   
--   We allow to specify multiple mirrors to initialize the repository.
--   These are mirrors that can be found "out of band" (out of the scope of
--   the TUF protocol), for example in a <tt>cabal.config</tt> file. The
--   TUF protocol itself will specify that any of these mirrors can serve a
--   <tt>mirrors.json</tt> file that itself contains mirrors; we consider
--   these as _additional_ mirrors to the ones that are passed here.
--   
--   NOTE: The list of mirrors should be non-empty (and should typically
--   include the primary server).
--   
--   TODO: In the future we could allow finer control over precisely which
--   mirrors we use (which combination of the mirrors that are passed as
--   arguments here and the mirrors that we get from <tt>mirrors.json</tt>)
--   as well as indicating mirror preferences.
withRepository :: HttpLib -> [URI] -> RepoOpts -> Cache -> RepoLayout -> IndexLayout -> (LogMessage -> IO ()) -> (Repository RemoteTemp -> IO a) -> IO a

-- | Repository options with a reasonable default
--   
--   Clients should use <tt>defaultRepositoryOpts</tt> and override
--   required settings.
data RepoOpts
RepoOpts :: Bool -> RepoOpts

-- | Allow additional mirrors?
--   
--   If this is set to True (default), in addition to the (out-of-band)
--   specified mirrors we will also use mirrors reported by those
--   out-of-band mirrors (that is, <tt>mirrors.json</tt>).
[repoAllowAdditionalMirrors] :: RepoOpts -> Bool

-- | Default repository options
defaultRepoOpts :: RepoOpts
data RemoteTemp :: * -> *
data FileSize

-- | For most files we download we know the exact size beforehand (because
--   this information comes from the snapshot or delegated info)
FileSizeExact :: Int54 -> FileSize

-- | For some files we might not know the size beforehand, but we might be
--   able to provide an upper bound (timestamp, root info)
FileSizeBound :: Int54 -> FileSize
fileSizeWithinBounds :: Int54 -> FileSize -> Bool
instance GHC.Show.Show Hackage.Security.Client.Repository.Remote.FileSize
instance GHC.Show.Show Hackage.Security.Client.Repository.Remote.FileTooLarge
instance Hackage.Security.Util.Pretty.Pretty Hackage.Security.Client.Repository.Remote.FileTooLarge
instance GHC.Exception.Exception Hackage.Security.Client.Repository.Remote.FileTooLarge
instance Hackage.Security.Util.Pretty.Pretty (Hackage.Security.Client.Repository.Remote.RemoteTemp typ)
instance Hackage.Security.Client.Repository.DownloadedFile Hackage.Security.Client.Repository.Remote.RemoteTemp


-- | Main entry point into the Hackage Security framework for clients
module Hackage.Security.Client

-- | Generic logic for checking if there are updates
--   
--   This implements the logic described in Section 5.1, "The client
--   application", of the TUF spec. It checks which of the server metadata
--   has changed, and downloads all changed metadata to the local cache.
--   (Metadata here refers both to the TUF security metadata as well as the
--   Hackage packge index.)
--   
--   You should pass <tt>Nothing</tt> for the UTCTime _only_ under
--   exceptional circumstances (such as when the main server is down for
--   longer than the expiry dates used in the timestamp files on mirrors).
checkForUpdates :: (Throws VerificationError, Throws SomeRemoteError) => Repository down -> Maybe UTCTime -> IO HasUpdates
data HasUpdates
HasUpdates :: HasUpdates
NoUpdates :: HasUpdates

-- | Download a package
downloadPackage :: (Throws SomeRemoteError, Throws VerificationError, Throws InvalidPackageException) => Repository down -> PackageIdentifier -> Path Absolute -> IO ()

-- | Variation on <a>downloadPackage</a> that takes a FilePath instead.
downloadPackage' :: (Throws SomeRemoteError, Throws VerificationError, Throws InvalidPackageException) => Repository down -> PackageIdentifier -> FilePath -> IO ()

-- | Index directory
data Directory
Directory :: DirectoryEntry -> DirectoryEntry -> (forall dec. IndexFile dec -> Maybe DirectoryEntry) -> [(DirectoryEntry, IndexPath, Maybe (Some IndexFile))] -> Directory

-- | The first entry in the dictionary
[directoryFirst] :: Directory -> DirectoryEntry

-- | The next available (i.e., one after last) directory entry
[directoryNext] :: Directory -> DirectoryEntry

-- | Lookup an entry in the dictionary
--   
--   This is an efficient operation.
[directoryLookup] :: Directory -> forall dec. IndexFile dec -> Maybe DirectoryEntry

-- | An enumeration of all entries
--   
--   This field is lazily constructed, so if you don't need it, it does not
--   incur a performance overhead. Moreover, the <a>IndexFile</a> is also
--   created lazily so if you only need the raw <a>IndexPath</a> there is
--   no parsing overhead.
--   
--   The entries are ordered by <a>DirectoryEntry</a> so that the entries
--   can efficiently be read in sequence.
--   
--   NOTE: This means that there are two ways to enumerate all entries in
--   the tar file, since when lookup an entry using <a>indexLookupEntry</a>
--   the <a>DirectoryEntry</a> of the next entry is also returned. However,
--   this involves reading through the entire <tt>tar</tt> file. If you
--   only need to read <i>some</i> files, it is significantly more
--   efficient to enumerate the tar entries using <a>directoryEntries</a>
--   instead and only call <a>indexLookupEntry</a> when required.
[directoryEntries] :: Directory -> [(DirectoryEntry, IndexPath, Maybe (Some IndexFile))]

-- | Entry into the Hackage index.
newtype DirectoryEntry
DirectoryEntry :: TarEntryOffset -> DirectoryEntry

-- | (Low-level) block number of the tar index entry
--   
--   Exposed for the benefit of clients who read the <tt>.tar</tt> file
--   directly. For this reason also the <a>Show</a> and <a>Read</a>
--   instances for <a>DirectoryEntry</a> just print and parse the
--   underlying <tt>TarEntryOffset</tt>.
[directoryEntryBlockNo] :: DirectoryEntry -> TarEntryOffset

-- | Read the Hackage index directory
--   
--   Should only be called after <a>checkForUpdates</a>.
getDirectory :: Repository down -> IO Directory

-- | Files that we might request from the index
--   
--   The type index tells us the type of the decoded file, if any. For
--   files for which the library does not support decoding this will be
--   <tt>()</tt>. NOTE: Clients should NOT rely on this type index being
--   <tt>()</tt>, or they might break if we add support for parsing
--   additional file formats in the future.
--   
--   TODO: If we wanted to support legacy Hackage, we should also have a
--   case for the global preferred-versions file. But supporting legacy
--   Hackage will probably require more work anyway..
data IndexFile :: * -> *
[IndexPkgMetadata] :: PackageIdentifier -> IndexFile (Signed Targets)
[IndexPkgCabal] :: PackageIdentifier -> IndexFile ()
[IndexPkgPrefs] :: PackageName -> IndexFile ()

-- | Entry from the Hackage index; see <a>withIndex</a>.
data IndexEntry dec
IndexEntry :: IndexPath -> Maybe (IndexFile dec) -> ByteString -> Either SomeException dec -> EpochTime -> IndexEntry dec

-- | The raw path in the tarfile
[indexEntryPath] :: IndexEntry dec -> IndexPath

-- | The parsed file (if recognised)
[indexEntryPathParsed] :: IndexEntry dec -> Maybe (IndexFile dec)

-- | The raw contents
--   
--   Although this is a lazy bytestring, this is actually read into memory
--   strictly (i.e., it can safely be used outside the scope of withIndex
--   and friends).
[indexEntryContent] :: IndexEntry dec -> ByteString

-- | The parsed contents
--   
--   This field is lazily constructed; the parser is not unless you do a
--   pattern match on this value.
[indexEntryContentParsed] :: IndexEntry dec -> Either SomeException dec

-- | The time of the entry in the tarfile.
[indexEntryTime] :: IndexEntry dec -> EpochTime

-- | Various operations that we can perform on the index once its open
--   
--   Note that <a>IndexEntry</a> contains a fields both for the raw file
--   contents and the parsed file contents; clients can choose which to
--   use.
--   
--   In principle these callbacks will do verification (once we have
--   implemented author signing). Right now they don't need to do that,
--   because the index as a whole will have been verified.
data IndexCallbacks
IndexCallbacks :: (DirectoryEntry -> IO (Some IndexEntry, Maybe DirectoryEntry)) -> (forall dec. IndexFile dec -> IO (Maybe (IndexEntry dec))) -> (forall dec. DirectoryEntry -> IndexFile dec -> IO (IndexEntry dec)) -> (Throws InvalidPackageException => PackageIdentifier -> IO (Trusted ByteString)) -> (Throws InvalidPackageException => PackageIdentifier -> IO (Trusted Targets)) -> ((Throws InvalidPackageException, Throws VerificationError) => PackageIdentifier -> IO (Trusted FileInfo)) -> ((Throws InvalidPackageException, Throws VerificationError) => PackageIdentifier -> IO (Trusted Hash)) -> Directory -> IndexCallbacks

-- | Look up an entry by <a>DirectoryEntry</a>
--   
--   Since these <a>DirectoryEntry</a>s must come from somewhere (probably
--   from the <a>Directory</a>), it is assumed that they are valid; if they
--   are not, an (unchecked) exception will be thrown.
--   
--   This function also returns the <a>DirectoryEntry</a> of the
--   <i>next</i> file in the index (if any) for the benefit of clients who
--   wish to walk through the entire index.
[indexLookupEntry] :: IndexCallbacks -> DirectoryEntry -> IO (Some IndexEntry, Maybe DirectoryEntry)

-- | Look up an entry by <a>IndexFile</a>
--   
--   Returns <a>Nothing</a> if the <a>IndexFile</a> does not refer to an
--   existing file.
[indexLookupFile] :: IndexCallbacks -> forall dec. IndexFile dec -> IO (Maybe (IndexEntry dec))

-- | Variation if both the <a>DirectoryEntry</a> and the <a>IndexFile</a>
--   are known
--   
--   You might use this when scanning the index using
--   <a>directoryEntries</a>.
[indexLookupFileEntry] :: IndexCallbacks -> forall dec. DirectoryEntry -> IndexFile dec -> IO (IndexEntry dec)

-- | Get (raw) cabal file (wrapper around <a>indexLookupFile</a>)
[indexLookupCabal] :: IndexCallbacks -> Throws InvalidPackageException => PackageIdentifier -> IO (Trusted ByteString)

-- | Lookup package metadata (wrapper around <a>indexLookupFile</a>)
--   
--   This will throw an (unchecked) exception if the <tt>targets.json</tt>
--   file could not be parsed.
[indexLookupMetadata] :: IndexCallbacks -> Throws InvalidPackageException => PackageIdentifier -> IO (Trusted Targets)

-- | Get file info (including hash) (wrapper around <a>indexLookupFile</a>)
[indexLookupFileInfo] :: IndexCallbacks -> (Throws InvalidPackageException, Throws VerificationError) => PackageIdentifier -> IO (Trusted FileInfo)

-- | Get the SHA256 hash for a package (wrapper around
--   <tt>indexLookupInfo</tt>)
--   
--   In addition to the exceptions thrown by <tt>indexLookupInfo</tt>, this
--   will also throw an exception if the SHA256 is not listed in the
--   <a>FileMap</a> (again, this will not happen with a well-formed Hackage
--   index.)
[indexLookupHash] :: IndexCallbacks -> (Throws InvalidPackageException, Throws VerificationError) => PackageIdentifier -> IO (Trusted Hash)

-- | The <a>Directory</a> for the index
--   
--   We provide this here because <a>withIndex</a> will have read this
--   anyway.
[indexDirectory] :: IndexCallbacks -> Directory

-- | Look up entries in the Hackage index
--   
--   This is in <a>withFile</a> style so that clients can efficiently look
--   up multiple files from the index.
--   
--   Should only be called after <a>checkForUpdates</a>.
withIndex :: Repository down -> (IndexCallbacks -> IO a) -> IO a

-- | Check if we need to bootstrap (i.e., if we have root info)
requiresBootstrap :: Repository down -> IO Bool

-- | Bootstrap the chain of trust
--   
--   New clients might need to obtain a copy of the root metadata. This
--   however represents a chicken-and-egg problem: how can we verify the
--   root metadata we downloaded? The only possibility is to be provided
--   with a set of an out-of-band set of root keys and an appropriate
--   threshold.
--   
--   Clients who provide a threshold of 0 can do an initial "unsafe" update
--   of the root information, if they wish.
--   
--   The downloaded root information will _only_ be verified against the
--   provided keys, and _not_ against previously downloaded root info (if
--   any). It is the responsibility of the client to call <a>bootstrap</a>
--   only when this is the desired behaviour.
bootstrap :: (Throws SomeRemoteError, Throws VerificationError) => Repository down -> [KeyId] -> KeyThreshold -> IO ()

-- | File length
--   
--   Having verified file length information means we can protect against
--   endless data attacks and similar.
newtype FileLength
FileLength :: Int54 -> FileLength
[fileLength] :: FileLength -> Int54

-- | File hash
newtype Hash
Hash :: String -> Hash

-- | Key threshold
--   
--   The key threshold is the minimum number of keys a document must be
--   signed with. Key thresholds are specified in <tt>RoleSpec</tt> or
--   <tt>DelegationsSpec</tt>.
newtype KeyThreshold
KeyThreshold :: Int54 -> KeyThreshold

-- | File information
--   
--   This intentionally does not have an <a>Eq</a> instance; see
--   <a>knownFileInfoEqual</a> and <tt>verifyFileInfo</tt> instead.
--   
--   NOTE: Throughout we compute file information always over the raw
--   bytes. For example, when <tt>timestamp.json</tt> lists the hash of
--   <tt>snapshot.json</tt>, this hash is computed over the actual
--   <tt>snapshot.json</tt> file (as opposed to the canonical form of the
--   embedded JSON). This brings it in line with the hash computed over
--   target files, where that is the only choice available.
data FileInfo
FileInfo :: FileLength -> Map HashFn Hash -> FileInfo
[fileInfoLength] :: FileInfo -> FileLength
[fileInfoHashes] :: FileInfo -> Map HashFn Hash
data HashFn
HashFnSHA256 :: HashFn
HashFnMD5 :: HashFn

-- | File hash
newtype Hash
Hash :: String -> Hash

-- | Compute <a>FileInfo</a>
--   
--   TODO: Currently this will load the entire input bytestring into
--   memory. We need to make this incremental, by computing the length and
--   all hashes in a single traversal over the input.
fileInfo :: ByteString -> FileInfo

-- | Compute <a>FileInfo</a>
computeFileInfo :: FsRoot root => Path root -> IO FileInfo

-- | Compare the expected trusted file info against the actual file info of
--   a target file.
--   
--   This should be used only when the <a>FileInfo</a> is already known. If
--   we want to compare known <a>FileInfo</a> against a file on disk we
--   should delay until we have confirmed that the file lengths match (see
--   <tt>downloadedVerify</tt>).
compareTrustedFileInfo :: FileInfo -> FileInfo -> Bool
knownFileInfoEqual :: FileInfo -> FileInfo -> Bool

-- | Extract SHA256 hash from <a>FileInfo</a> (if present)
fileInfoSHA256 :: FileInfo -> Maybe Hash

-- | 54-bit integer values
--   
--   JavaScript can only safely represent numbers between <tt>-(2^53 -
--   1)</tt> and <tt>2^53 - 1</tt>.
--   
--   TODO: Although we introduce the type here, we don't actually do any
--   bounds checking and just inherit all type class instance from Int64.
--   We should probably define <a>fromInteger</a> to do bounds checking,
--   give different instances for type classes such as <a>Bounded</a> and
--   <a>FiniteBits</a>, etc.
data Int54
class HasHeader a

-- | File expiry date
fileExpires :: HasHeader a => Lens' a FileExpires

-- | File version (monotonically increasing counter)
fileVersion :: HasHeader a => Lens' a FileVersion

-- | File version
--   
--   The file version is a flat integer which must monotonically increase
--   on every file update.
--   
--   <a>Show</a> and <a>Read</a> instance are defined in terms of the
--   underlying <a>Int</a> (this is use for example by hackage during the
--   backup process).
newtype FileVersion
FileVersion :: Int54 -> FileVersion

-- | File expiry date
--   
--   A <a>Nothing</a> value here means no expiry. That makes it possible to
--   set some files to never expire. (Note that not having the Maybe in the
--   type here still allows that, because you could set an expiry date 2000
--   years into the future. By having the Maybe here we avoid the _need_
--   for such encoding issues.)
newtype FileExpires
FileExpires :: (Maybe UTCTime) -> FileExpires

-- | Occassionally it is useful to read only a header from a file.
--   
--   <tt>HeaderOnly</tt> intentionally only has a <a>FromJSON</a> instance
--   (no <a>ToJSON</a>).
data Header
Header :: FileExpires -> FileVersion -> Header
[headerExpires] :: Header -> FileExpires
[headerVersion] :: Header -> FileVersion
expiresInDays :: UTCTime -> Integer -> FileExpires
expiresNever :: FileExpires
isExpired :: UTCTime -> FileExpires -> Bool
versionInitial :: FileVersion
versionIncrement :: FileVersion -> FileVersion

-- | Location of the various files we cache
--   
--   Although the generic TUF algorithms do not care how we organize the
--   cache, we nonetheless specity this here because as long as there are
--   tools which access files in the cache directly we need to define the
--   cache layout. See also comments for <tt>defaultCacheLayout</tt>.
data CacheLayout
CacheLayout :: CachePath -> CachePath -> CachePath -> CachePath -> CachePath -> CachePath -> CachePath -> CacheLayout

-- | TUF root metadata
[cacheLayoutRoot] :: CacheLayout -> CachePath

-- | TUF timestamp
[cacheLayoutTimestamp] :: CacheLayout -> CachePath

-- | TUF snapshot
[cacheLayoutSnapshot] :: CacheLayout -> CachePath

-- | TUF mirrors list
[cacheLayoutMirrors] :: CacheLayout -> CachePath

-- | Uncompressed index tarball
[cacheLayoutIndexTar] :: CacheLayout -> CachePath

-- | Index to the uncompressed index tarball
[cacheLayoutIndexIdx] :: CacheLayout -> CachePath

-- | Compressed index tarball
--   
--   We cache both the compressed and the uncompressed tarballs, because
--   incremental updates happen through the compressed tarball, but reads
--   happen through the uncompressed one (with the help of the tarball
--   index).
[cacheLayoutIndexTarGz] :: CacheLayout -> CachePath

-- | The cache layout cabal-install uses
--   
--   We cache the index as <tt><a>cache</a>/00-index.tar</tt>; this is
--   important because `cabal-install` expects to find it there (and does
--   not currently go through the hackage-security library to get files
--   from the index).
cabalCacheLayout :: CacheLayout

-- | Layout of the files within the index tarball
data IndexLayout
IndexLayout :: (forall dec. IndexFile dec -> IndexPath) -> (IndexPath -> Maybe (Some IndexFile)) -> IndexLayout

-- | Translate an <a>IndexFile</a> to a path
[indexFileToPath] :: IndexLayout -> forall dec. IndexFile dec -> IndexPath

-- | Parse an <a>FilePath</a>
[indexFileFromPath] :: IndexLayout -> IndexPath -> Maybe (Some IndexFile)

-- | Files that we might request from the index
--   
--   The type index tells us the type of the decoded file, if any. For
--   files for which the library does not support decoding this will be
--   <tt>()</tt>. NOTE: Clients should NOT rely on this type index being
--   <tt>()</tt>, or they might break if we add support for parsing
--   additional file formats in the future.
--   
--   TODO: If we wanted to support legacy Hackage, we should also have a
--   case for the global preferred-versions file. But supporting legacy
--   Hackage will probably require more work anyway..
data IndexFile :: * -> *
[IndexPkgMetadata] :: PackageIdentifier -> IndexFile (Signed Targets)
[IndexPkgCabal] :: PackageIdentifier -> IndexFile ()
[IndexPkgPrefs] :: PackageName -> IndexFile ()

-- | The layout of the index as maintained on Hackage
hackageIndexLayout :: IndexLayout
indexLayoutPkgMetadata :: IndexLayout -> PackageIdentifier -> IndexPath
indexLayoutPkgCabal :: IndexLayout -> PackageIdentifier -> IndexPath
indexLayoutPkgPrefs :: IndexLayout -> PackageName -> IndexPath

-- | Layout of a repository
data RepoLayout
RepoLayout :: RepoPath -> RepoPath -> RepoPath -> RepoPath -> RepoPath -> RepoPath -> (PackageIdentifier -> RepoPath) -> RepoLayout

-- | TUF root metadata
[repoLayoutRoot] :: RepoLayout -> RepoPath

-- | TUF timestamp
[repoLayoutTimestamp] :: RepoLayout -> RepoPath

-- | TUF snapshot
[repoLayoutSnapshot] :: RepoLayout -> RepoPath

-- | TUF mirrors list
[repoLayoutMirrors] :: RepoLayout -> RepoPath

-- | Compressed index tarball
[repoLayoutIndexTarGz] :: RepoLayout -> RepoPath

-- | Uncompressed index tarball
[repoLayoutIndexTar] :: RepoLayout -> RepoPath

-- | Path to the package tarball
[repoLayoutPkgTarGz] :: RepoLayout -> PackageIdentifier -> RepoPath

-- | The layout used on Hackage
hackageRepoLayout :: RepoLayout

-- | Layout used by cabal for ("legacy") local repos
--   
--   Obviously, such repos do not normally contain any of the TUF files, so
--   their location is more or less arbitrary here.
cabalLocalRepoLayout :: RepoLayout
data Mirrors
Mirrors :: FileVersion -> FileExpires -> [Mirror] -> Mirrors
[mirrorsVersion] :: Mirrors -> FileVersion
[mirrorsExpires] :: Mirrors -> FileExpires
[mirrorsMirrors] :: Mirrors -> [Mirror]

-- | Definition of a mirror
--   
--   NOTE: Unlike the TUF specification, we require that all mirrors must
--   have the same format. That is, we omit <tt>metapath</tt> and
--   <tt>targetspath</tt>.
data Mirror
Mirror :: URI -> MirrorContent -> Mirror
[mirrorUrlBase] :: Mirror -> URI
[mirrorContent] :: Mirror -> MirrorContent

-- | Full versus partial mirrors
--   
--   The TUF spec explicitly allows for partial mirrors, with the mirrors
--   file specifying (through patterns) what is available from partial
--   mirrors.
--   
--   For now we only support full mirrors; if we wanted to add partial
--   mirrors, we would add a second <tt>MirrorPartial</tt> constructor here
--   with arguments corresponding to TUF's <tt>metacontent</tt> and
--   <tt>targetscontent</tt> fields.
data MirrorContent
MirrorFull :: MirrorContent
type MirrorDescription = String

-- | Give a human-readable description of a particular mirror
--   
--   (for use in error messages)
describeMirror :: Mirror -> MirrorDescription

-- | The root of the repository
--   
--   Repository roots can be anchored at a remote URL or a local directory.
--   
--   Note that even for remote repos <a>RepoRoot</a> is (potentially)
--   different from <a>Web</a> -- for a repository located at, say,
--   <tt><a>http://hackage.haskell.org</a></tt> they happen to coincide,
--   but for one location at
--   <tt><a>http://example.com/some/subdirectory</a></tt> they do not.
data RepoRoot

-- | Paths relative to the root of the repository
type RepoPath = Path RepoRoot
anchorRepoPathLocally :: Path root -> RepoPath -> Path root
anchorRepoPathRemotely :: Path Web -> RepoPath -> Path Web

-- | The root of the index tarball
data IndexRoot

-- | Paths relative to the root of the index tarball
type IndexPath = Path IndexRoot

-- | The cache directory
data CacheRoot
type CachePath = Path CacheRoot

-- | Anchor a cache path to the location of the cache
anchorCachePath :: Path root -> CachePath -> Path root

-- | The root metadata
--   
--   NOTE: We must have the invariant that ALL keys (apart from delegation
--   keys) must be listed in <a>rootKeys</a>. (Delegation keys satisfy a
--   similar invariant, see Targets.)
data Root
Root :: FileVersion -> FileExpires -> KeyEnv -> RootRoles -> Root
[rootVersion] :: Root -> FileVersion
[rootExpires] :: Root -> FileExpires
[rootKeys] :: Root -> KeyEnv
[rootRoles] :: Root -> RootRoles
data RootRoles
RootRoles :: RoleSpec Root -> RoleSpec Snapshot -> RoleSpec Targets -> RoleSpec Timestamp -> RoleSpec Mirrors -> RootRoles
[rootRolesRoot] :: RootRoles -> RoleSpec Root
[rootRolesSnapshot] :: RootRoles -> RoleSpec Snapshot
[rootRolesTargets] :: RootRoles -> RoleSpec Targets
[rootRolesTimestamp] :: RootRoles -> RoleSpec Timestamp
[rootRolesMirrors] :: RootRoles -> RoleSpec Mirrors

-- | Role specification
--   
--   The phantom type indicates what kind of type this role is meant to
--   verify.
data RoleSpec a
RoleSpec :: [Some PublicKey] -> KeyThreshold -> RoleSpec a
[roleSpecKeys] :: RoleSpec a -> [Some PublicKey]
[roleSpecThreshold] :: RoleSpec a -> KeyThreshold
data Signed a
Signed :: a -> Signatures -> Signed a
[signed] :: Signed a -> a
[signatures] :: Signed a -> Signatures

-- | A list of signatures
--   
--   Invariant: each signature must be made with a different key. We
--   enforce this invariant for incoming untrusted data
--   (<a>fromPreSignatures</a>) but not for lists of signatures that we
--   create in code.
newtype Signatures
Signatures :: [Signature] -> Signatures
data Signature
Signature :: ByteString -> Some PublicKey -> Signature
[signature] :: Signature -> ByteString
[signatureKey] :: Signature -> Some PublicKey

-- | Create a new document without any signatures
unsigned :: a -> Signed a

-- | Sign a document
withSignatures :: ToJSON WriteJSON a => RepoLayout -> [Some Key] -> a -> Signed a

-- | Variation on <a>withSignatures</a> that doesn't need the repo layout
withSignatures' :: ToJSON Identity a => [Some Key] -> a -> Signed a

-- | Construct signatures for already rendered value
signRendered :: [Some Key] -> ByteString -> Signatures
verifySignature :: ByteString -> Signature -> Bool

-- | General FromJSON instance for signed datatypes
--   
--   We don't give a general FromJSON instance for Signed because for some
--   datatypes we need to do something special (datatypes where we need to
--   read key environments); for instance, see the "Signed Root" instance.
signedFromJSON :: (MonadKeys m, FromJSON m a) => JSValue -> m (Signed a)

-- | Signature verification
--   
--   NOTES: 1. By definition, the signature must be verified against the
--   canonical JSON format. This means we _must_ parse and then pretty
--   print (as we do here) because the document as stored may or may not be
--   in canonical format. 2. However, it is important that we NOT translate
--   from the JSValue to whatever internal datatype we are using and then
--   back to JSValue, because that may not roundtrip: we must allow for
--   additional fields in the JSValue that we ignore (and would therefore
--   lose when we attempt to roundtrip). 3. We verify that all signatures
--   are valid, but we cannot verify (here) that these signatures are
--   signed with the right key, or that we have a sufficient number of
--   signatures. This will be the responsibility of the calling code.
verifySignatures :: JSValue -> Signatures -> Bool

-- | File with uninterpreted signatures
--   
--   Sometimes we want to be able to read a file without interpreting the
--   signatures (that is, resolving the key IDs) or doing any kind of
--   checks on them. One advantage of this is that this allows us to read
--   many file types without any key environment at all, which is sometimes
--   useful.
data UninterpretedSignatures a
UninterpretedSignatures :: a -> [PreSignature] -> UninterpretedSignatures a
[uninterpretedSigned] :: UninterpretedSignatures a -> a
[uninterpretedSignatures] :: UninterpretedSignatures a -> [PreSignature]

-- | A signature with a key ID (rather than an actual key)
--   
--   This corresponds precisely to the TUF representation of a signature.
data PreSignature
PreSignature :: ByteString -> Some KeyType -> KeyId -> PreSignature
[presignature] :: PreSignature -> ByteString
[presigMethod] :: PreSignature -> Some KeyType
[presigKeyId] :: PreSignature -> KeyId

-- | Convert a pre-signature to a signature
--   
--   Verifies that the key type matches the advertised method.
fromPreSignature :: MonadKeys m => PreSignature -> m Signature

-- | Convert a list of <a>PreSignature</a>s to a list of <a>Signature</a>s
--   
--   This verifies the invariant that all signatures are made with
--   different keys. We do this on the presignatures rather than the
--   signatures so that we can do the check on key IDs, rather than keys
--   (the latter don't have an Ord instance).
fromPreSignatures :: MonadKeys m => [PreSignature] -> m Signatures

-- | Convert signature to pre-signature
toPreSignature :: Signature -> PreSignature

-- | Convert list of pre-signatures to a list of signatures
toPreSignatures :: Signatures -> [PreSignature]
data Snapshot
Snapshot :: FileVersion -> FileExpires -> FileInfo -> FileInfo -> FileInfo -> Maybe FileInfo -> Snapshot
[snapshotVersion] :: Snapshot -> FileVersion
[snapshotExpires] :: Snapshot -> FileExpires

-- | File info for the root metadata
--   
--   We list this explicitly in the snapshot so that we can check if we
--   need to update the root metadata without first having to download the
--   entire index tarball.
[snapshotInfoRoot] :: Snapshot -> FileInfo

-- | File info for the mirror metadata
[snapshotInfoMirrors] :: Snapshot -> FileInfo

-- | Compressed index tarball
[snapshotInfoTarGz] :: Snapshot -> FileInfo

-- | Uncompressed index tarball
--   
--   Repositories are not required to provide this.
[snapshotInfoTar] :: Snapshot -> Maybe FileInfo

-- | Target metadata
--   
--   Most target files do not need expiry dates because they are not
--   subject to change (and hence attacks like freeze attacks are not a
--   concern).
data Targets
Targets :: FileVersion -> FileExpires -> FileMap -> Maybe Delegations -> Targets
[targetsVersion] :: Targets -> FileVersion
[targetsExpires] :: Targets -> FileExpires
[targetsTargets] :: Targets -> FileMap
[targetsDelegations] :: Targets -> Maybe Delegations

-- | Delegations
--   
--   Much like the Root datatype, this must have an invariant that ALL used
--   keys (apart from the global keys, which are in the root key
--   environment) must be listed in <a>delegationsKeys</a>.
data Delegations
Delegations :: KeyEnv -> [DelegationSpec] -> Delegations
[delegationsKeys] :: Delegations -> KeyEnv
[delegationsRoles] :: Delegations -> [DelegationSpec]

-- | Delegation specification
--   
--   NOTE: This is a close analogue of <tt>RoleSpec</tt>.
data DelegationSpec
DelegationSpec :: [Some PublicKey] -> KeyThreshold -> Delegation -> DelegationSpec
[delegationSpecKeys] :: DelegationSpec -> [Some PublicKey]
[delegationSpecThreshold] :: DelegationSpec -> KeyThreshold
[delegation] :: DelegationSpec -> Delegation

-- | A delegation
--   
--   A delegation is a pair of a pattern and a replacement.
--   
--   See <tt>match</tt> for an example.
data Delegation
Delegation :: (Pattern a) -> (Replacement a) -> Delegation
targetsLookup :: TargetPath -> Targets -> Maybe FileInfo
data Timestamp
Timestamp :: FileVersion -> FileExpires -> FileInfo -> Timestamp
[timestampVersion] :: Timestamp -> FileVersion
[timestampExpires] :: Timestamp -> FileExpires
[timestampInfoSnapshot] :: Timestamp -> FileInfo
data Ed25519
data Key a
[KeyEd25519] :: PublicKey -> SecretKey -> Key Ed25519
data PublicKey a
[PublicKeyEd25519] :: PublicKey -> PublicKey Ed25519
data PrivateKey a
[PrivateKeyEd25519] :: SecretKey -> PrivateKey Ed25519
data KeyType typ
[KeyTypeEd25519] :: KeyType Ed25519
somePublicKey :: Some Key -> Some PublicKey
somePublicKeyType :: Some PublicKey -> Some KeyType
someKeyId :: HasKeyId key => Some key -> KeyId
publicKey :: Key a -> PublicKey a
privateKey :: Key a -> PrivateKey a
createKey :: KeyType key -> IO (Key key)
createKey' :: KeyType key -> IO (Some Key)

-- | The key ID of a key, by definition, is the hexdigest of the SHA-256
--   hash of the canonical JSON form of the key where the private object
--   key is excluded.
--   
--   NOTE: The FromJSON and ToJSON instances for KeyId are ntentially
--   omitted. Use writeKeyAsId instead.
newtype KeyId
KeyId :: String -> KeyId
[keyIdString] :: KeyId -> String

-- | Compute the key ID of a key
class HasKeyId key
keyId :: HasKeyId key => key typ -> KeyId

-- | Sign a bytestring and return the signature
--   
--   TODO: It is unfortunate that we have to convert to a strict bytestring
--   for ed25519
sign :: PrivateKey typ -> ByteString -> ByteString
verify :: PublicKey typ -> ByteString -> ByteString -> Bool
trusted :: Trusted a -> a

-- | Repository
--   
--   This is an abstract representation of a repository. It simply provides
--   a way to download metafiles and target files, without specifying how
--   this is done. For instance, for a local repository this could just be
--   doing a file read, whereas for remote repositories this could be using
--   any kind of HTTP client.
data Repository down
class DownloadedFile (down :: * -> *)

-- | Verify a download file
downloadedVerify :: DownloadedFile down => down a -> Trusted FileInfo -> IO Bool

-- | Read the file we just downloaded into memory
--   
--   We never read binary data, only metadata.
downloadedRead :: DownloadedFile down => down Metadata -> IO ByteString

-- | Copy a downloaded file to its destination
downloadedCopyTo :: DownloadedFile down => down a -> Path Absolute -> IO ()

-- | Repository-specific exceptions
--   
--   For instance, for repositories using HTTP this might correspond to a
--   404; for local repositories this might correspond to file-not-found,
--   etc.
data SomeRemoteError :: *
[SomeRemoteError] :: Exception e => e -> SomeRemoteError

-- | Log messages
--   
--   We use a <a>RemoteFile</a> rather than a <a>RepoPath</a> here because
--   we might not have a <a>RepoPath</a> for the file that we were trying
--   to download (that is, for example if the server does not provide an
--   uncompressed tarball, it doesn't make much sense to list the path to
--   that non-existing uncompressed tarball).
data LogMessage

-- | Root information was updated
--   
--   This message is issued when the root information is updated as part of
--   the normal check for updates procedure. If the root information is
--   updated because of a verification error WarningVerificationError is
--   issued instead.
LogRootUpdated :: LogMessage

-- | A verification error
--   
--   Verification errors can be temporary, and may be resolved later; hence
--   these are just warnings. (Verification errors that cannot be resolved
--   are thrown as exceptions.)
LogVerificationError :: VerificationError -> LogMessage

-- | Download a file from a repository
LogDownloading :: (RemoteFile fs typ) -> LogMessage

-- | Incrementally updating a file from a repository
LogUpdating :: (RemoteFile fs Binary) -> LogMessage

-- | Selected a particular mirror
LogSelectedMirror :: MirrorDescription -> LogMessage

-- | Updating a file failed (we will instead download it whole)
LogCannotUpdate :: (RemoteFile fs Binary) -> UpdateFailure -> LogMessage

-- | We got an exception with a particular mirror (we will try with a
--   different mirror if any are available)
LogMirrorFailed :: MirrorDescription -> SomeException -> LogMessage

-- | Re-throw all exceptions thrown by the client API as unchecked
--   exceptions
uncheckClientErrors :: ((Throws VerificationError, Throws SomeRemoteError, Throws InvalidPackageException) => IO a) -> IO a

-- | Errors thrown during role validation
data VerificationError

-- | Not enough signatures signed with the appropriate keys
VerificationErrorSignatures :: TargetPath -> VerificationError

-- | The file is expired
VerificationErrorExpired :: TargetPath -> VerificationError

-- | The file version is less than the previous version
VerificationErrorVersion :: TargetPath -> VerificationError

-- | File information mismatch
VerificationErrorFileInfo :: TargetPath -> VerificationError

-- | We tried to lookup file information about a particular target file,
--   but the information wasn't in the corresponding <tt>targets.json</tt>
--   file.
VerificationErrorUnknownTarget :: TargetPath -> VerificationError

-- | The metadata for the specified target is missing a SHA256
VerificationErrorMissingSHA256 :: TargetPath -> VerificationError

-- | Some verification errors materialize as deserialization errors
--   
--   For example: if we try to deserialize a timestamp file but the
--   timestamp key has been rolled over, deserialization of the file will
--   fail with <a>DeserializationErrorUnknownKey</a>.
VerificationErrorDeserialization :: TargetPath -> DeserializationError -> VerificationError

-- | The spec stipulates that if a verification error occurs during the
--   check for updates, we must download new root information and start
--   over. However, we limit how often we attempt this.
--   
--   We record all verification errors that occurred before we gave up.
VerificationErrorLoop :: VerificationHistory -> VerificationError
type VerificationHistory = [Either RootUpdated VerificationError]

-- | Root metadata updated (as part of the normal update process)
data RootUpdated
RootUpdated :: RootUpdated
data InvalidPackageException
InvalidPackageException :: PackageIdentifier -> InvalidPackageException
data InvalidFileInIndex
InvalidFileInIndex :: IndexFile dec -> ByteString -> DeserializationError -> InvalidFileInIndex
[invalidFileInIndex] :: InvalidFileInIndex -> IndexFile dec
[invalidFileInIndexRaw] :: InvalidFileInIndex -> ByteString
[invalidFileInIndexError] :: InvalidFileInIndex -> DeserializationError
data LocalFileCorrupted
LocalFileCorrupted :: DeserializationError -> LocalFileCorrupted
instance GHC.Classes.Ord Hackage.Security.Client.DirectoryEntry
instance GHC.Classes.Eq Hackage.Security.Client.DirectoryEntry
instance GHC.Classes.Ord Hackage.Security.Client.HasUpdates
instance GHC.Classes.Eq Hackage.Security.Client.HasUpdates
instance GHC.Show.Show Hackage.Security.Client.HasUpdates
instance GHC.Show.Show Hackage.Security.Client.InvalidPackageException
instance GHC.Show.Show Hackage.Security.Client.LocalFileCorrupted
instance GHC.Show.Show Hackage.Security.Client.InvalidFileInIndex
instance GHC.Show.Show Hackage.Security.Client.DirectoryEntry
instance GHC.Read.Read Hackage.Security.Client.DirectoryEntry
instance GHC.Exception.Exception Hackage.Security.Client.InvalidPackageException
instance GHC.Exception.Exception Hackage.Security.Client.LocalFileCorrupted
instance GHC.Exception.Exception Hackage.Security.Client.InvalidFileInIndex
instance Hackage.Security.Util.Pretty.Pretty Hackage.Security.Client.InvalidPackageException
instance Hackage.Security.Util.Pretty.Pretty Hackage.Security.Client.LocalFileCorrupted
instance Hackage.Security.Util.Pretty.Pretty Hackage.Security.Client.InvalidFileInIndex