diff --git a/.editorconfig b/.editorconfig
index cb644d7..09e32b4 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -24,3 +24,7 @@ csharp_using_directive_placement = outside_namespace:warning
dotnet_style_qualification_for_field = false:warning
dotnet_style_qualification_for_property = false:warning
dotnet_style_qualification_for_method = false:warning
+
+# Tests: literal arrays in assertions read better than static fields.
+[tests/**.cs]
+dotnet_diagnostic.CA1861.severity = none
diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml
index fa38f3d..96bc28f 100644
--- a/.gitea/workflows/ci.yml
+++ b/.gitea/workflows/ci.yml
@@ -32,6 +32,7 @@ jobs:
ANUBIS_TEST_DB: ${{ matrix.db }}
ANUBIS_TEST_PG_HOST: postgres
ANUBIS_TEST_PG_PORT: "5432"
+ ANUBIS_TEST_PG_PASSWORD: anubis-ci
DOTNET_CLI_TELEMETRY_OPTOUT: "1"
DOTNET_NOLOGO: "1"
TESTINGPLATFORM_TELEMETRY_OPTOUT: "1"
diff --git a/Directory.Packages.props b/Directory.Packages.props
index 9bd7a72..4318d09 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -9,4 +9,11 @@
+
+
+
+
+
+
+
diff --git a/docs/API-NOTES.md b/docs/API-NOTES.md
index f170a47..7a5a863 100644
--- a/docs/API-NOTES.md
+++ b/docs/API-NOTES.md
@@ -170,7 +170,7 @@ Ultime versioni stabili lette dall'API di NuGet il 10 novembre 2026. Quelle già
| `Microsoft.NET.Test.Sdk` | 18.11.0 | MIT | Fase 0 | https://www.nuget.org/packages/Microsoft.NET.Test.Sdk |
| `Microsoft.Data.Sqlite` | 10.0.14 | MIT | Fase 1 | https://www.nuget.org/packages/Microsoft.Data.Sqlite/10.0.14 |
| `Npgsql` | 10.0.3 | PostgreSQL License | Fase 1 | https://www.nuget.org/packages/Npgsql/10.0.3 |
-| `System.Security.Cryptography.ProtectedData` | 10.0.14 | MIT | Fase 10 | https://www.nuget.org/packages/System.Security.Cryptography.ProtectedData/10.0.14 |
+| `System.Security.Cryptography.ProtectedData` | 10.0.14 | MIT | Fase 1 (la custodia della chiave dei segreti su desktop nasce con lo strato di piattaforma) | https://www.nuget.org/packages/System.Security.Cryptography.ProtectedData/10.0.14 |
| `Microsoft.Web.WebView2` | 1.0.4314.35 | Licenza Microsoft di tipo BSD | Fase 10 | https://www.nuget.org/packages/Microsoft.Web.WebView2/1.0.4314.35 |
| `Microsoft.ML`, `Microsoft.ML.LightGbm`, `Microsoft.ML.FastTree` | 5.0.1 | MIT | Fase 8 | https://www.nuget.org/packages/Microsoft.ML/5.0.1 |
| `Microsoft.ML.OnnxRuntime` | 1.31.1 (librerie native per linux-x64 e win-x64) | MIT | Fase 7 | https://www.nuget.org/packages/Microsoft.ML.OnnxRuntime/1.31.1 |
@@ -202,7 +202,7 @@ Quando la fase indicata aggiunge il pacchetto, il nome entra nell'elenco del tes
| Dipendenza | Di chi, licenza | Arriva con | Fase | Nota |
|---|---|---|---|---|
-| `SQLitePCLRaw.bundle_e_sqlite3`, `SQLitePCLRaw.core` 2.1.13 | Eric Sink, Apache-2.0 | `Microsoft.Data.Sqlite` | 1 | Contiene la libreria nativa di SQLite. |
+| `SQLitePCLRaw.bundle_e_sqlite3`, `SQLitePCLRaw.core`, `SQLitePCLRaw.lib.e_sqlite3`, `SQLitePCLRaw.provider.e_sqlite3` 2.1.13 | Eric Sink, Apache-2.0 | `Microsoft.Data.Sqlite` | 1 (in uso) | Contengono la libreria nativa di SQLite e il suo caricatore. Sono nell'elenco del test dalla Fase 1. |
| `Newtonsoft.Json` 13.0.3 | James Newton-King, MIT | `Microsoft.ML`, LightGbm, FastTree | 8 | — |
| `LightGBM` 4.6.0 | progetto microsoft/LightGBM, pubblicato a nome di Guolin Ke, MIT | `Microsoft.ML.LightGbm` | 8 | Libreria nativa; in Docker serve `libgomp1`. |
| `Google.Protobuf` 3.30.2 | Google, BSD-3-Clause | `Microsoft.ML.Tokenizers` | 7 | — |
diff --git a/src/Anubis.Desktop/packages.lock.json b/src/Anubis.Desktop/packages.lock.json
index 8f93eae..e5f82ab 100644
--- a/src/Anubis.Desktop/packages.lock.json
+++ b/src/Anubis.Desktop/packages.lock.json
@@ -2,8 +2,87 @@
"version": 2,
"dependencies": {
"net10.0-windows7.0": {
+ "Microsoft.Data.Sqlite.Core": {
+ "type": "Transitive",
+ "resolved": "10.0.14",
+ "contentHash": "1p9rO3Q2X/L/9YrYog3vaDzi8u+WZfJCOkDYoHqmofqYP0DLPLPyZcS2Rnh/79JXAodgbs1AgsaNwLpIvC3Xew==",
+ "dependencies": {
+ "SQLitePCLRaw.core": "2.1.13"
+ }
+ },
+ "Microsoft.Extensions.DependencyInjection.Abstractions": {
+ "type": "Transitive",
+ "resolved": "10.0.0",
+ "contentHash": "L3AdmZ1WOK4XXT5YFPEwyt0ep6l8lGIPs7F5OOBZc77Zqeo01Of7XXICy47628sdVl0v/owxYJTe86DTgFwKCA=="
+ },
+ "Microsoft.Extensions.Logging.Abstractions": {
+ "type": "Transitive",
+ "resolved": "10.0.0",
+ "contentHash": "FU/IfjDfwaMuKr414SSQNTIti/69bHEMb+QKrskRb26oVqpx3lNFXMjs/RC9ZUuhBhcwDM2BwOgoMw+PZ+beqQ==",
+ "dependencies": {
+ "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.0"
+ }
+ },
+ "SQLitePCLRaw.bundle_e_sqlite3": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "NlDixlC7uHmo+ojXRgkNvN0tQtVGpLDZ3x2OpgNj+G07VHh5cXSszFDrAiC4BpUiPwkcaeuQkMV9WQ123xVtmQ==",
+ "dependencies": {
+ "SQLitePCLRaw.lib.e_sqlite3": "2.1.13",
+ "SQLitePCLRaw.provider.e_sqlite3": "2.1.13"
+ }
+ },
+ "SQLitePCLRaw.core": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "2joofoinuHBFs0nMX3nKuXgxpXryRkCOdM2Ua6HBqQLLy6IW+5f28ZI+HAvMyF8vG7XfNz/lwfBfE6V4juru8Q=="
+ },
+ "SQLitePCLRaw.lib.e_sqlite3": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "D2UAuiGxFYBqeRXjjjGgvJ5UQifzn6wefmSqeKU7XcNGKLbJRP6X7kcPZ6opOBJGdCIlgbSxTvDpBbLvsN594A=="
+ },
+ "SQLitePCLRaw.provider.e_sqlite3": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "ZU60dSqoSNRe49KcQDUmOVgdRtjITOssVXFtiISs+zJXDI4D2Sndwpn2NOtzDQNPu0ZAvpoLPQ+GLKv6iEZn8Q==",
+ "dependencies": {
+ "SQLitePCLRaw.core": "2.1.13"
+ }
+ },
"anubis": {
- "type": "Project"
+ "type": "Project",
+ "dependencies": {
+ "Microsoft.Data.Sqlite": "[10.0.14, )",
+ "Npgsql": "[10.0.3, )",
+ "System.Security.Cryptography.ProtectedData": "[10.0.14, )"
+ }
+ },
+ "Microsoft.Data.Sqlite": {
+ "type": "CentralTransitive",
+ "requested": "[10.0.14, )",
+ "resolved": "10.0.14",
+ "contentHash": "muyroan6rKrf0omZL8UF7Kw5uOGp/yBg1L/XWvkFN3WhKaNtK2IWqRZw93nIwVqjhTVDO0l4CEGhHIh+mb+sKg==",
+ "dependencies": {
+ "Microsoft.Data.Sqlite.Core": "10.0.14",
+ "SQLitePCLRaw.bundle_e_sqlite3": "2.1.13",
+ "SQLitePCLRaw.core": "2.1.13"
+ }
+ },
+ "Npgsql": {
+ "type": "CentralTransitive",
+ "requested": "[10.0.3, )",
+ "resolved": "10.0.3",
+ "contentHash": "7nb5YzXuvWWJxB0J8DiyL3we+X4FOctZrt0fIBnucOIaIevFEEwGQVZKtiu9olXdlNAK1eNgqSral6r/jlhI4w==",
+ "dependencies": {
+ "Microsoft.Extensions.Logging.Abstractions": "10.0.0"
+ }
+ },
+ "System.Security.Cryptography.ProtectedData": {
+ "type": "CentralTransitive",
+ "requested": "[10.0.14, )",
+ "resolved": "10.0.14",
+ "contentHash": "UuaBUHgmtc9h6CMxaQqFDDJxkS5JVy7XEB+DbtCvD68GFcVM9/AccuNwFpARx8nwCnvjaxzoOBjG3gPz32P1Eg=="
}
}
}
diff --git a/src/Anubis.Guard/packages.lock.json b/src/Anubis.Guard/packages.lock.json
index c644c09..e42c9af 100644
--- a/src/Anubis.Guard/packages.lock.json
+++ b/src/Anubis.Guard/packages.lock.json
@@ -2,8 +2,87 @@
"version": 2,
"dependencies": {
"net10.0": {
+ "Microsoft.Data.Sqlite.Core": {
+ "type": "Transitive",
+ "resolved": "10.0.14",
+ "contentHash": "1p9rO3Q2X/L/9YrYog3vaDzi8u+WZfJCOkDYoHqmofqYP0DLPLPyZcS2Rnh/79JXAodgbs1AgsaNwLpIvC3Xew==",
+ "dependencies": {
+ "SQLitePCLRaw.core": "2.1.13"
+ }
+ },
+ "Microsoft.Extensions.DependencyInjection.Abstractions": {
+ "type": "Transitive",
+ "resolved": "10.0.0",
+ "contentHash": "L3AdmZ1WOK4XXT5YFPEwyt0ep6l8lGIPs7F5OOBZc77Zqeo01Of7XXICy47628sdVl0v/owxYJTe86DTgFwKCA=="
+ },
+ "Microsoft.Extensions.Logging.Abstractions": {
+ "type": "Transitive",
+ "resolved": "10.0.0",
+ "contentHash": "FU/IfjDfwaMuKr414SSQNTIti/69bHEMb+QKrskRb26oVqpx3lNFXMjs/RC9ZUuhBhcwDM2BwOgoMw+PZ+beqQ==",
+ "dependencies": {
+ "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.0"
+ }
+ },
+ "SQLitePCLRaw.bundle_e_sqlite3": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "NlDixlC7uHmo+ojXRgkNvN0tQtVGpLDZ3x2OpgNj+G07VHh5cXSszFDrAiC4BpUiPwkcaeuQkMV9WQ123xVtmQ==",
+ "dependencies": {
+ "SQLitePCLRaw.lib.e_sqlite3": "2.1.13",
+ "SQLitePCLRaw.provider.e_sqlite3": "2.1.13"
+ }
+ },
+ "SQLitePCLRaw.core": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "2joofoinuHBFs0nMX3nKuXgxpXryRkCOdM2Ua6HBqQLLy6IW+5f28ZI+HAvMyF8vG7XfNz/lwfBfE6V4juru8Q=="
+ },
+ "SQLitePCLRaw.lib.e_sqlite3": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "D2UAuiGxFYBqeRXjjjGgvJ5UQifzn6wefmSqeKU7XcNGKLbJRP6X7kcPZ6opOBJGdCIlgbSxTvDpBbLvsN594A=="
+ },
+ "SQLitePCLRaw.provider.e_sqlite3": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "ZU60dSqoSNRe49KcQDUmOVgdRtjITOssVXFtiISs+zJXDI4D2Sndwpn2NOtzDQNPu0ZAvpoLPQ+GLKv6iEZn8Q==",
+ "dependencies": {
+ "SQLitePCLRaw.core": "2.1.13"
+ }
+ },
"anubis": {
- "type": "Project"
+ "type": "Project",
+ "dependencies": {
+ "Microsoft.Data.Sqlite": "[10.0.14, )",
+ "Npgsql": "[10.0.3, )",
+ "System.Security.Cryptography.ProtectedData": "[10.0.14, )"
+ }
+ },
+ "Microsoft.Data.Sqlite": {
+ "type": "CentralTransitive",
+ "requested": "[10.0.14, )",
+ "resolved": "10.0.14",
+ "contentHash": "muyroan6rKrf0omZL8UF7Kw5uOGp/yBg1L/XWvkFN3WhKaNtK2IWqRZw93nIwVqjhTVDO0l4CEGhHIh+mb+sKg==",
+ "dependencies": {
+ "Microsoft.Data.Sqlite.Core": "10.0.14",
+ "SQLitePCLRaw.bundle_e_sqlite3": "2.1.13",
+ "SQLitePCLRaw.core": "2.1.13"
+ }
+ },
+ "Npgsql": {
+ "type": "CentralTransitive",
+ "requested": "[10.0.3, )",
+ "resolved": "10.0.3",
+ "contentHash": "7nb5YzXuvWWJxB0J8DiyL3we+X4FOctZrt0fIBnucOIaIevFEEwGQVZKtiu9olXdlNAK1eNgqSral6r/jlhI4w==",
+ "dependencies": {
+ "Microsoft.Extensions.Logging.Abstractions": "10.0.0"
+ }
+ },
+ "System.Security.Cryptography.ProtectedData": {
+ "type": "CentralTransitive",
+ "requested": "[10.0.14, )",
+ "resolved": "10.0.14",
+ "contentHash": "UuaBUHgmtc9h6CMxaQqFDDJxkS5JVy7XEB+DbtCvD68GFcVM9/AccuNwFpARx8nwCnvjaxzoOBjG3gPz32P1Eg=="
}
}
}
diff --git a/src/Anubis.Server/packages.lock.json b/src/Anubis.Server/packages.lock.json
index c644c09..7d7d6af 100644
--- a/src/Anubis.Server/packages.lock.json
+++ b/src/Anubis.Server/packages.lock.json
@@ -2,8 +2,71 @@
"version": 2,
"dependencies": {
"net10.0": {
+ "Microsoft.Data.Sqlite.Core": {
+ "type": "Transitive",
+ "resolved": "10.0.14",
+ "contentHash": "1p9rO3Q2X/L/9YrYog3vaDzi8u+WZfJCOkDYoHqmofqYP0DLPLPyZcS2Rnh/79JXAodgbs1AgsaNwLpIvC3Xew==",
+ "dependencies": {
+ "SQLitePCLRaw.core": "2.1.13"
+ }
+ },
+ "SQLitePCLRaw.bundle_e_sqlite3": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "NlDixlC7uHmo+ojXRgkNvN0tQtVGpLDZ3x2OpgNj+G07VHh5cXSszFDrAiC4BpUiPwkcaeuQkMV9WQ123xVtmQ==",
+ "dependencies": {
+ "SQLitePCLRaw.lib.e_sqlite3": "2.1.13",
+ "SQLitePCLRaw.provider.e_sqlite3": "2.1.13"
+ }
+ },
+ "SQLitePCLRaw.core": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "2joofoinuHBFs0nMX3nKuXgxpXryRkCOdM2Ua6HBqQLLy6IW+5f28ZI+HAvMyF8vG7XfNz/lwfBfE6V4juru8Q=="
+ },
+ "SQLitePCLRaw.lib.e_sqlite3": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "D2UAuiGxFYBqeRXjjjGgvJ5UQifzn6wefmSqeKU7XcNGKLbJRP6X7kcPZ6opOBJGdCIlgbSxTvDpBbLvsN594A=="
+ },
+ "SQLitePCLRaw.provider.e_sqlite3": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "ZU60dSqoSNRe49KcQDUmOVgdRtjITOssVXFtiISs+zJXDI4D2Sndwpn2NOtzDQNPu0ZAvpoLPQ+GLKv6iEZn8Q==",
+ "dependencies": {
+ "SQLitePCLRaw.core": "2.1.13"
+ }
+ },
"anubis": {
- "type": "Project"
+ "type": "Project",
+ "dependencies": {
+ "Microsoft.Data.Sqlite": "[10.0.14, )",
+ "Npgsql": "[10.0.3, )",
+ "System.Security.Cryptography.ProtectedData": "[10.0.14, )"
+ }
+ },
+ "Microsoft.Data.Sqlite": {
+ "type": "CentralTransitive",
+ "requested": "[10.0.14, )",
+ "resolved": "10.0.14",
+ "contentHash": "muyroan6rKrf0omZL8UF7Kw5uOGp/yBg1L/XWvkFN3WhKaNtK2IWqRZw93nIwVqjhTVDO0l4CEGhHIh+mb+sKg==",
+ "dependencies": {
+ "Microsoft.Data.Sqlite.Core": "10.0.14",
+ "SQLitePCLRaw.bundle_e_sqlite3": "2.1.13",
+ "SQLitePCLRaw.core": "2.1.13"
+ }
+ },
+ "Npgsql": {
+ "type": "CentralTransitive",
+ "requested": "[10.0.3, )",
+ "resolved": "10.0.3",
+ "contentHash": "7nb5YzXuvWWJxB0J8DiyL3we+X4FOctZrt0fIBnucOIaIevFEEwGQVZKtiu9olXdlNAK1eNgqSral6r/jlhI4w=="
+ },
+ "System.Security.Cryptography.ProtectedData": {
+ "type": "CentralTransitive",
+ "requested": "[10.0.14, )",
+ "resolved": "10.0.14",
+ "contentHash": "UuaBUHgmtc9h6CMxaQqFDDJxkS5JVy7XEB+DbtCvD68GFcVM9/AccuNwFpARx8nwCnvjaxzoOBjG3gPz32P1Eg=="
}
}
}
diff --git a/src/Anubis.Setup/packages.lock.json b/src/Anubis.Setup/packages.lock.json
index 8f93eae..e5f82ab 100644
--- a/src/Anubis.Setup/packages.lock.json
+++ b/src/Anubis.Setup/packages.lock.json
@@ -2,8 +2,87 @@
"version": 2,
"dependencies": {
"net10.0-windows7.0": {
+ "Microsoft.Data.Sqlite.Core": {
+ "type": "Transitive",
+ "resolved": "10.0.14",
+ "contentHash": "1p9rO3Q2X/L/9YrYog3vaDzi8u+WZfJCOkDYoHqmofqYP0DLPLPyZcS2Rnh/79JXAodgbs1AgsaNwLpIvC3Xew==",
+ "dependencies": {
+ "SQLitePCLRaw.core": "2.1.13"
+ }
+ },
+ "Microsoft.Extensions.DependencyInjection.Abstractions": {
+ "type": "Transitive",
+ "resolved": "10.0.0",
+ "contentHash": "L3AdmZ1WOK4XXT5YFPEwyt0ep6l8lGIPs7F5OOBZc77Zqeo01Of7XXICy47628sdVl0v/owxYJTe86DTgFwKCA=="
+ },
+ "Microsoft.Extensions.Logging.Abstractions": {
+ "type": "Transitive",
+ "resolved": "10.0.0",
+ "contentHash": "FU/IfjDfwaMuKr414SSQNTIti/69bHEMb+QKrskRb26oVqpx3lNFXMjs/RC9ZUuhBhcwDM2BwOgoMw+PZ+beqQ==",
+ "dependencies": {
+ "Microsoft.Extensions.DependencyInjection.Abstractions": "10.0.0"
+ }
+ },
+ "SQLitePCLRaw.bundle_e_sqlite3": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "NlDixlC7uHmo+ojXRgkNvN0tQtVGpLDZ3x2OpgNj+G07VHh5cXSszFDrAiC4BpUiPwkcaeuQkMV9WQ123xVtmQ==",
+ "dependencies": {
+ "SQLitePCLRaw.lib.e_sqlite3": "2.1.13",
+ "SQLitePCLRaw.provider.e_sqlite3": "2.1.13"
+ }
+ },
+ "SQLitePCLRaw.core": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "2joofoinuHBFs0nMX3nKuXgxpXryRkCOdM2Ua6HBqQLLy6IW+5f28ZI+HAvMyF8vG7XfNz/lwfBfE6V4juru8Q=="
+ },
+ "SQLitePCLRaw.lib.e_sqlite3": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "D2UAuiGxFYBqeRXjjjGgvJ5UQifzn6wefmSqeKU7XcNGKLbJRP6X7kcPZ6opOBJGdCIlgbSxTvDpBbLvsN594A=="
+ },
+ "SQLitePCLRaw.provider.e_sqlite3": {
+ "type": "Transitive",
+ "resolved": "2.1.13",
+ "contentHash": "ZU60dSqoSNRe49KcQDUmOVgdRtjITOssVXFtiISs+zJXDI4D2Sndwpn2NOtzDQNPu0ZAvpoLPQ+GLKv6iEZn8Q==",
+ "dependencies": {
+ "SQLitePCLRaw.core": "2.1.13"
+ }
+ },
"anubis": {
- "type": "Project"
+ "type": "Project",
+ "dependencies": {
+ "Microsoft.Data.Sqlite": "[10.0.14, )",
+ "Npgsql": "[10.0.3, )",
+ "System.Security.Cryptography.ProtectedData": "[10.0.14, )"
+ }
+ },
+ "Microsoft.Data.Sqlite": {
+ "type": "CentralTransitive",
+ "requested": "[10.0.14, )",
+ "resolved": "10.0.14",
+ "contentHash": "muyroan6rKrf0omZL8UF7Kw5uOGp/yBg1L/XWvkFN3WhKaNtK2IWqRZw93nIwVqjhTVDO0l4CEGhHIh+mb+sKg==",
+ "dependencies": {
+ "Microsoft.Data.Sqlite.Core": "10.0.14",
+ "SQLitePCLRaw.bundle_e_sqlite3": "2.1.13",
+ "SQLitePCLRaw.core": "2.1.13"
+ }
+ },
+ "Npgsql": {
+ "type": "CentralTransitive",
+ "requested": "[10.0.3, )",
+ "resolved": "10.0.3",
+ "contentHash": "7nb5YzXuvWWJxB0J8DiyL3we+X4FOctZrt0fIBnucOIaIevFEEwGQVZKtiu9olXdlNAK1eNgqSral6r/jlhI4w==",
+ "dependencies": {
+ "Microsoft.Extensions.Logging.Abstractions": "10.0.0"
+ }
+ },
+ "System.Security.Cryptography.ProtectedData": {
+ "type": "CentralTransitive",
+ "requested": "[10.0.14, )",
+ "resolved": "10.0.14",
+ "contentHash": "UuaBUHgmtc9h6CMxaQqFDDJxkS5JVy7XEB+DbtCvD68GFcVM9/AccuNwFpARx8nwCnvjaxzoOBjG3gPz32P1Eg=="
}
}
}
diff --git a/src/Anubis/Access/AccessStore.cs b/src/Anubis/Access/AccessStore.cs
new file mode 100644
index 0000000..2c5dba5
--- /dev/null
+++ b/src/Anubis/Access/AccessStore.cs
@@ -0,0 +1,268 @@
+using System.Security.Cryptography;
+using System.Text;
+using Anubis.Core;
+using Anubis.Db;
+
+namespace Anubis.Access;
+
+public sealed record User(Guid Id, string Username, bool MustChangePassword, bool HasSecondFactor);
+
+public sealed record SessionInfo(Guid Id, User User, DateTimeOffset CreatedAt, DateTimeOffset ExpiresAt);
+
+public enum LoginResult
+{
+ Ok,
+ WrongPassword,
+ SecondFactorNeeded,
+ WrongSecondFactor,
+ Locked,
+ NoUser,
+}
+
+///
+/// Limit on sign-in attempts (SPEC 15.4): after 5 failures from the same address in 15 minutes that address
+/// waits 15 minutes; after 20 failures overall, everyone waits. Kept in memory: a restart clears it, which
+/// costs an attacker a restart they cannot cause.
+///
+public sealed class LoginLimiter(IClock clock)
+{
+ public const int PerAddress = 5;
+ public const int Overall = 20;
+ public static readonly TimeSpan Window = TimeSpan.FromMinutes(15);
+
+ private readonly Lock _gate = new();
+ private readonly Dictionary> _failures = new(StringComparer.Ordinal);
+ private readonly List _all = [];
+
+ /// How long must still wait, or zero.
+ public TimeSpan Wait(string address)
+ {
+ lock (_gate)
+ {
+ var now = clock.UtcNow;
+ Trim(now);
+ var mine = _failures.TryGetValue(address, out var list) ? list : [];
+ var wait = TimeSpan.Zero;
+ if (mine.Count >= PerAddress)
+ {
+ wait = mine[^PerAddress] + Window - now;
+ }
+
+ if (_all.Count >= Overall)
+ {
+ var overall = _all[^Overall] + Window - now;
+ wait = overall > wait ? overall : wait;
+ }
+
+ return wait > TimeSpan.Zero ? wait : TimeSpan.Zero;
+ }
+ }
+
+ public void Failed(string address)
+ {
+ lock (_gate)
+ {
+ var now = clock.UtcNow;
+ if (!_failures.TryGetValue(address, out var list))
+ {
+ _failures[address] = list = [];
+ }
+
+ list.Add(now);
+ _all.Add(now);
+ }
+ }
+
+ public void Succeeded(string address)
+ {
+ lock (_gate)
+ {
+ _failures.Remove(address);
+ }
+ }
+
+ private void Trim(DateTimeOffset now)
+ {
+ _all.RemoveAll(t => t + Window <= now);
+ foreach (var key in _failures.Keys.ToList())
+ {
+ _failures[key].RemoveAll(t => t + Window <= now);
+ if (_failures[key].Count == 0)
+ {
+ _failures.Remove(key);
+ }
+ }
+ }
+}
+
+///
+/// The single user of Anubis and their sessions (SPEC 15.4). Sessions are random tokens in an HttpOnly cookie;
+/// only their SHA-256 is stored, so a copy of the database does not let anyone in.
+///
+public sealed class AccessStore(Database db, IClock clock, SecretStore secrets, int iterations = Passwords.DefaultIterations)
+{
+ public const string AdminName = "admin";
+ public static readonly TimeSpan IdleTimeout = TimeSpan.FromHours(12);
+ public static readonly TimeSpan MaxLifetime = TimeSpan.FromDays(7);
+
+ public Task HasUserAsync(CancellationToken cancellationToken = default) =>
+ db.ReadAsync(async s => await s.CountAsync("SELECT COUNT(*) FROM users").ConfigureAwait(false) > 0, cancellationToken);
+
+ /// Creates the user when there is none. In Docker the initial password must be changed at first sign-in.
+ public async Task EnsureUserAsync(string password, bool mustChange, CancellationToken cancellationToken = default)
+ {
+ var hash = Passwords.Hash(password, iterations);
+ var now = clock.UtcNow;
+ return await db.WriteAsync(async s =>
+ {
+ if (await s.CountAsync("SELECT COUNT(*) FROM users").ConfigureAwait(false) > 0)
+ {
+ return false;
+ }
+
+ await s.ExecuteAsync("INSERT INTO users (id, username, password_hash, must_change_password, totp_secret, created_at, updated_at) VALUES (@id, @u, @h, @m, NULL, @t, @t)",
+ cancellationToken, ("id", Ids.NewId(clock)), ("u", AdminName), ("h", hash), ("m", mustChange), ("t", now)).ConfigureAwait(false);
+ return true;
+ }, cancellationToken).ConfigureAwait(false);
+ }
+
+ public async Task<(LoginResult Result, string? Token)> SignInAsync(string password, string? code, string? userAgent, string? address, CancellationToken cancellationToken = default)
+ {
+ var user = await db.ReadAsync(s => s.FirstOrDefaultAsync("SELECT id, password_hash, totp_secret FROM users WHERE username = @u",
+ r => (Id: r.Id("id"), Hash: r.Text("password_hash"), Totp: r.BytesOrNull("totp_secret")), ("u", AdminName)), cancellationToken).ConfigureAwait(false);
+ if (user == default)
+ {
+ return (LoginResult.NoUser, null);
+ }
+
+ if (!Passwords.Verify(password, user.Hash))
+ {
+ return (LoginResult.WrongPassword, null);
+ }
+
+ if (user.Totp is not null)
+ {
+ if (string.IsNullOrWhiteSpace(code))
+ {
+ return (LoginResult.SecondFactorNeeded, null);
+ }
+
+ var secret = Convert.FromBase64String(secrets.Open("totp:" + user.Id.ToString("D"), user.Totp));
+ if (!Totp.Verify(secret, code, clock.UtcNow))
+ {
+ return (LoginResult.WrongSecondFactor, null);
+ }
+ }
+
+ var token = Ids.NewToken();
+ var now = clock.UtcNow;
+ await db.WriteAsync(s => s.ExecuteAsync(
+ "INSERT INTO sessions (id, user_id, token_hash, user_agent, address, created_at, last_seen_at, expires_at) VALUES (@id, @u, @h, @ua, @a, @t, @t, @e)",
+ cancellationToken, ("id", Ids.NewId(clock)), ("u", user.Id), ("h", HashToken(token)), ("ua", Truncate(userAgent, 300)), ("a", Truncate(address, 100)),
+ ("t", now), ("e", now + MaxLifetime)), cancellationToken).ConfigureAwait(false);
+ return (LoginResult.Ok, token);
+ }
+
+ /// The session behind a cookie token, or null when unknown, idle too long or expired.
+ public async Task ValidateAsync(string? token, CancellationToken cancellationToken = default)
+ {
+ if (string.IsNullOrEmpty(token))
+ {
+ return null;
+ }
+
+ var now = clock.UtcNow;
+ var found = await db.ReadAsync(s => s.FirstOrDefaultAsync(
+ "SELECT s.id, s.created_at, s.last_seen_at, s.expires_at, u.id AS user_id, u.username, u.must_change_password, u.totp_secret FROM sessions s JOIN users u ON u.id = s.user_id WHERE s.token_hash = @h",
+ r => new
+ {
+ Id = r.Id("id"),
+ Created = r.Moment("created_at"),
+ Seen = r.Moment("last_seen_at"),
+ Expires = r.Moment("expires_at"),
+ User = new User(r.Id("user_id"), r.Text("username"), r.Bool("must_change_password"), !r.IsNull("totp_secret")),
+ }, ("h", HashToken(token))), cancellationToken).ConfigureAwait(false);
+ if (found is null || now >= found.Expires || now - found.Seen >= IdleTimeout)
+ {
+ return null;
+ }
+
+ // Refresh the idle timer at most once a minute, to keep writes rare.
+ if (now - found.Seen > TimeSpan.FromMinutes(1))
+ {
+ await db.WriteAsync(s => s.ExecuteAsync("UPDATE sessions SET last_seen_at = @t WHERE id = @id", cancellationToken, ("t", now), ("id", found.Id)), cancellationToken)
+ .ConfigureAwait(false);
+ }
+
+ return new SessionInfo(found.Id, found.User, found.Created, found.Expires);
+ }
+
+ public Task SignOutAsync(string token, CancellationToken cancellationToken = default) =>
+ db.WriteAsync(s => s.ExecuteAsync("DELETE FROM sessions WHERE token_hash = @h", cancellationToken, ("h", HashToken(token))), cancellationToken);
+
+ /// Changes the password and ends every other session.
+ public async Task ChangePasswordAsync(Guid userId, string current, string replacement, Guid keepSession, CancellationToken cancellationToken = default)
+ {
+ var hash = await db.ReadAsync(s => s.FirstOrDefaultAsync("SELECT password_hash FROM users WHERE id = @id", r => r.Text("password_hash"), ("id", userId)), cancellationToken)
+ .ConfigureAwait(false);
+ if (hash is null || !Passwords.Verify(current, hash))
+ {
+ return false;
+ }
+
+ var replacementHash = Passwords.Hash(replacement, iterations);
+ var now = clock.UtcNow;
+ await db.WriteAsync(async s =>
+ {
+ await s.ExecuteAsync("UPDATE users SET password_hash = @h, must_change_password = @m, updated_at = @t WHERE id = @id", cancellationToken,
+ ("h", replacementHash), ("m", false), ("t", now), ("id", userId)).ConfigureAwait(false);
+ await s.ExecuteAsync("DELETE FROM sessions WHERE user_id = @u AND id <> @keep", cancellationToken, ("u", userId), ("keep", keepSession)).ConfigureAwait(false);
+ await LogAsync(s, "security.password", "cambiata", cancellationToken).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
+ return true;
+ }
+
+ /// Turns on the second factor after the user proved the app produces valid codes.
+ public async Task EnableSecondFactorAsync(Guid userId, byte[] secret, string code, CancellationToken cancellationToken = default)
+ {
+ ArgumentNullException.ThrowIfNull(secret);
+ if (!Totp.Verify(secret, code, clock.UtcNow))
+ {
+ return false;
+ }
+
+ var sealedSecret = secrets.Seal("totp:" + userId.ToString("D"), Convert.ToBase64String(secret));
+ await db.WriteAsync(async s =>
+ {
+ await s.ExecuteAsync("UPDATE users SET totp_secret = @s, updated_at = @t WHERE id = @id", cancellationToken,
+ ("s", sealedSecret), ("t", clock.UtcNow), ("id", userId)).ConfigureAwait(false);
+ await LogAsync(s, "security.second_factor", "attivato", cancellationToken).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
+ return true;
+ }
+
+ public async Task DisableSecondFactorAsync(Guid userId, string password, CancellationToken cancellationToken = default)
+ {
+ var hash = await db.ReadAsync(s => s.FirstOrDefaultAsync("SELECT password_hash FROM users WHERE id = @id", r => r.Text("password_hash"), ("id", userId)), cancellationToken)
+ .ConfigureAwait(false);
+ if (hash is null || !Passwords.Verify(password, hash))
+ {
+ return false;
+ }
+
+ await db.WriteAsync(async s =>
+ {
+ await s.ExecuteAsync("UPDATE users SET totp_secret = NULL, updated_at = @t WHERE id = @id", cancellationToken, ("t", clock.UtcNow), ("id", userId)).ConfigureAwait(false);
+ await LogAsync(s, "security.second_factor", "disattivato", cancellationToken).ConfigureAwait(false);
+ }, cancellationToken).ConfigureAwait(false);
+ return true;
+ }
+
+ private Task LogAsync(DbSession s, string key, string what, CancellationToken cancellationToken) =>
+ s.ExecuteAsync("INSERT INTO config_history (id, key, old_value, new_value, changed_by, created_at) VALUES (@id, @k, NULL, @n, @by, @t)", cancellationToken,
+ ("id", Ids.NewId(clock)), ("k", key), ("n", new DbJson(System.Text.Json.JsonSerializer.Serialize(what))), ("by", AdminName), ("t", clock.UtcNow));
+
+ private static string HashToken(string token) => Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes(token)));
+
+ private static string? Truncate(string? value, int length) => value is null || value.Length <= length ? value : value[..length];
+}
diff --git a/src/Anubis/Access/Passwords.cs b/src/Anubis/Access/Passwords.cs
new file mode 100644
index 0000000..91c9c4d
--- /dev/null
+++ b/src/Anubis/Access/Passwords.cs
@@ -0,0 +1,186 @@
+using System.Globalization;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace Anubis.Access;
+
+///
+/// Password hashes with PBKDF2-SHA512 (),
+/// in place of Argon2id (ADR 0003). Stored as pbkdf2-sha512$iterations$salt$hash so the cost can grow later.
+///
+public static class Passwords
+{
+ /// OWASP's figure for PBKDF2-HMAC-SHA512.
+ public const int DefaultIterations = 210_000;
+
+ public const int MinimumLength = 10;
+
+ private const string Scheme = "pbkdf2-sha512";
+
+ public static string Hash(string password, int iterations = DefaultIterations)
+ {
+ ArgumentNullException.ThrowIfNull(password);
+ var salt = RandomNumberGenerator.GetBytes(16);
+ var hash = Rfc2898DeriveBytes.Pbkdf2(Encoding.UTF8.GetBytes(password), salt, iterations, HashAlgorithmName.SHA512, 64);
+ return string.Join('$', Scheme, iterations.ToString(CultureInfo.InvariantCulture), Convert.ToBase64String(salt), Convert.ToBase64String(hash));
+ }
+
+ /// Checks a password in constant time. A malformed stored hash never verifies.
+ public static bool Verify(string password, string stored)
+ {
+ ArgumentNullException.ThrowIfNull(password);
+ ArgumentNullException.ThrowIfNull(stored);
+ var parts = stored.Split('$');
+ if (parts.Length != 4 || parts[0] != Scheme || !int.TryParse(parts[1], NumberStyles.None, CultureInfo.InvariantCulture, out var iterations) || iterations < 1)
+ {
+ return false;
+ }
+
+ byte[] salt;
+ byte[] expected;
+ try
+ {
+ salt = Convert.FromBase64String(parts[2]);
+ expected = Convert.FromBase64String(parts[3]);
+ }
+ catch (FormatException)
+ {
+ return false;
+ }
+
+ var actual = Rfc2898DeriveBytes.Pbkdf2(Encoding.UTF8.GetBytes(password), salt, iterations, HashAlgorithmName.SHA512, expected.Length);
+ return CryptographicOperations.FixedTimeEquals(actual, expected);
+ }
+
+ /// What is wrong with a new password, in plain Italian, or null when it is acceptable.
+ public static string? Problem(string? password, string? initialPassword = null)
+ {
+ if (string.IsNullOrEmpty(password) || password.Length < MinimumLength)
+ {
+ return $"La password deve avere almeno {MinimumLength} caratteri.";
+ }
+
+ if (initialPassword is not null && password == initialPassword)
+ {
+ return "Scegli una password diversa da quella iniziale del container.";
+ }
+
+ return null;
+ }
+}
+
+/// Base32 without padding (RFC 4648), the format authenticator apps expect for TOTP secrets.
+public static class Base32
+{
+ private const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
+
+ public static string Encode(ReadOnlySpan data)
+ {
+ var text = new StringBuilder((data.Length * 8 + 4) / 5);
+ int buffer = 0, bits = 0;
+ foreach (var b in data)
+ {
+ buffer = (buffer << 8) | b;
+ bits += 8;
+ while (bits >= 5)
+ {
+ text.Append(Alphabet[(buffer >> (bits - 5)) & 31]);
+ bits -= 5;
+ }
+ }
+
+ if (bits > 0)
+ {
+ text.Append(Alphabet[(buffer << (5 - bits)) & 31]);
+ }
+
+ return text.ToString();
+ }
+
+ public static byte[] Decode(string text)
+ {
+ ArgumentNullException.ThrowIfNull(text);
+ var clean = text.Replace(" ", "", StringComparison.Ordinal).Replace("-", "", StringComparison.Ordinal).TrimEnd('=').ToUpperInvariant();
+ var result = new List(clean.Length * 5 / 8);
+ int buffer = 0, bits = 0;
+ foreach (var c in clean)
+ {
+ var value = Alphabet.IndexOf(c, StringComparison.Ordinal);
+ if (value < 0)
+ {
+ throw new FormatException("Carattere non valido nel codice: " + c);
+ }
+
+ buffer = (buffer << 5) | value;
+ bits += 5;
+ if (bits >= 8)
+ {
+ result.Add((byte)(buffer >> (bits - 8)));
+ bits -= 8;
+ }
+ }
+
+ return [.. result];
+ }
+}
+
+///
+/// Time-based one-time passwords (RFC 6238), written in house and checked against the RFC's test vectors.
+/// Defaults are the ones every authenticator app uses: HMAC-SHA1, 6 digits, 30-second steps.
+///
+public static class Totp
+{
+ public static byte[] NewSecret() => RandomNumberGenerator.GetBytes(20);
+
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA5350", Justification = "RFC 6238 and every authenticator app use HMAC-SHA1; HMAC keeps SHA-1 safe here.")]
+ public static string Compute(ReadOnlySpan secret, DateTimeOffset at, int digits = 6, int stepSeconds = 30, string algorithm = "SHA1")
+ {
+ var counter = at.ToUnixTimeSeconds() / stepSeconds;
+ Span message = stackalloc byte[8];
+ for (var i = 7; i >= 0; i--)
+ {
+ message[i] = (byte)(counter & 0xff);
+ counter >>= 8;
+ }
+
+ byte[] hash = algorithm switch
+ {
+ "SHA1" => HMACSHA1.HashData(secret, message),
+ "SHA256" => HMACSHA256.HashData(secret, message),
+ "SHA512" => HMACSHA512.HashData(secret, message),
+ _ => throw new ArgumentException("Unsupported algorithm " + algorithm, nameof(algorithm)),
+ };
+ var offset = hash[^1] & 0x0f;
+ var binary = ((hash[offset] & 0x7f) << 24) | (hash[offset + 1] << 16) | (hash[offset + 2] << 8) | hash[offset + 3];
+ var modulo = (int)Math.Pow(10, digits);
+ return (binary % modulo).ToString(CultureInfo.InvariantCulture).PadLeft(digits, '0');
+ }
+
+ /// Accepts the code of the current step and of one step before or after, for clocks a little apart.
+ public static bool Verify(ReadOnlySpan secret, string? code, DateTimeOffset now)
+ {
+ if (code is null)
+ {
+ return false;
+ }
+
+ code = code.Replace(" ", "", StringComparison.Ordinal);
+ if (code.Length != 6 || !code.All(char.IsAsciiDigit))
+ {
+ return false;
+ }
+
+ var ok = false;
+ for (var step = -1; step <= 1; step++)
+ {
+ var expected = Compute(secret, now.AddSeconds(step * 30));
+ ok |= CryptographicOperations.FixedTimeEquals(Encoding.ASCII.GetBytes(expected), Encoding.ASCII.GetBytes(code));
+ }
+
+ return ok;
+ }
+
+ /// The address authenticator apps read (otpauth://), for manual entry or a QR code.
+ public static string Uri(string issuer, string account, ReadOnlySpan secret) =>
+ $"otpauth://totp/{System.Uri.EscapeDataString(issuer)}:{System.Uri.EscapeDataString(account)}?secret={Base32.Encode(secret)}&issuer={System.Uri.EscapeDataString(issuer)}&algorithm=SHA1&digits=6&period=30";
+}
diff --git a/src/Anubis/Anubis.csproj b/src/Anubis/Anubis.csproj
index a65610b..c75e33c 100644
--- a/src/Anubis/Anubis.csproj
+++ b/src/Anubis/Anubis.csproj
@@ -2,6 +2,14 @@
Anubis
+
+
+
+
+
+
+
+
diff --git a/src/Anubis/Core/Clock.cs b/src/Anubis/Core/Clock.cs
new file mode 100644
index 0000000..1c90931
--- /dev/null
+++ b/src/Anubis/Core/Clock.cs
@@ -0,0 +1,110 @@
+namespace Anubis.Core;
+
+///
+/// The only source of time in Anubis (SPEC 16, trap 12): no code reads the system clock directly,
+/// so tests and the demo mode can run at any moment.
+///
+public interface IClock
+{
+ DateTimeOffset UtcNow { get; }
+
+ /// Waits until the clock reaches . A manual clock returns when it is moved past it.
+ Task WaitUntilAsync(DateTimeOffset dueUtc, CancellationToken cancellationToken);
+}
+
+/// The real clock of the machine.
+public sealed class SystemClock : IClock
+{
+ public static SystemClock Instance { get; } = new();
+
+ public DateTimeOffset UtcNow => DateTimeOffset.UtcNow;
+
+ public async Task WaitUntilAsync(DateTimeOffset dueUtc, CancellationToken cancellationToken)
+ {
+ // Wake at least once a minute: after a sleep of the computer the remaining time is recomputed (trap 21).
+ while (true)
+ {
+ var remaining = dueUtc - UtcNow;
+ if (remaining <= TimeSpan.Zero)
+ {
+ return;
+ }
+
+ await Task.Delay(remaining < TimeSpan.FromMinutes(1) ? remaining : TimeSpan.FromMinutes(1), cancellationToken).ConfigureAwait(false);
+ }
+ }
+}
+
+/// A clock that moves only when told to: tests and the frozen demo clock (SPEC 13.1).
+public sealed class ManualClock(DateTimeOffset start) : IClock
+{
+ private readonly Lock _gate = new();
+ private readonly List<(DateTimeOffset Due, TaskCompletionSource Done)> _waiters = [];
+ private DateTimeOffset _now = start.ToUniversalTime();
+
+ public DateTimeOffset UtcNow
+ {
+ get
+ {
+ lock (_gate)
+ {
+ return _now;
+ }
+ }
+ }
+
+ public void Set(DateTimeOffset value)
+ {
+ List ready;
+ lock (_gate)
+ {
+ _now = value.ToUniversalTime();
+ ready = _waiters.Where(w => w.Due <= _now).Select(w => w.Done).ToList();
+ _waiters.RemoveAll(w => w.Due <= _now);
+ }
+
+ foreach (var done in ready)
+ {
+ done.TrySetResult();
+ }
+ }
+
+ public void Advance(TimeSpan by) => Set(UtcNow + by);
+
+ /// Number of callers waiting for a future moment; lets tests know a loop has gone to sleep.
+ public int Waiting
+ {
+ get
+ {
+ lock (_gate)
+ {
+ return _waiters.Count;
+ }
+ }
+ }
+
+ public Task WaitUntilAsync(DateTimeOffset dueUtc, CancellationToken cancellationToken)
+ {
+ var done = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
+ lock (_gate)
+ {
+ if (dueUtc <= _now)
+ {
+ return Task.CompletedTask;
+ }
+
+ _waiters.Add((dueUtc, done));
+ }
+
+ cancellationToken.Register(() =>
+ {
+ lock (_gate)
+ {
+ _waiters.RemoveAll(w => w.Done == done);
+ }
+
+ done.TrySetCanceled(cancellationToken);
+ });
+ return done.Task;
+ }
+}
diff --git a/src/Anubis/Core/EventBus.cs b/src/Anubis/Core/EventBus.cs
new file mode 100644
index 0000000..09774ea
--- /dev/null
+++ b/src/Anubis/Core/EventBus.cs
@@ -0,0 +1,97 @@
+using System.Threading.Channels;
+
+namespace Anubis.Core;
+
+///
+/// In-process event bus (ADR 0003) on . Every subscriber gets its own
+/// bounded queue: a slow reader loses its oldest events instead of blocking the publisher (prices and orders
+/// must never wait for the interface).
+///
+public sealed class EventBus
+{
+ private readonly Lock _gate = new();
+ private readonly List _subscriptions = [];
+
+ /// Delivers to every current subscriber of (or a base type).
+ public void Publish(T message)
+ where T : notnull
+ {
+ Subscription[] targets;
+ lock (_gate)
+ {
+ targets = [.. _subscriptions];
+ }
+
+ foreach (var subscription in targets)
+ {
+ if (subscription.Type.IsInstanceOfType(message))
+ {
+ subscription.Writer.TryWrite(message);
+ }
+ }
+ }
+
+ /// Starts receiving messages of type . Dispose the result to stop.
+ public EventSubscription Subscribe(int capacity = 256)
+ {
+ var channel = Channel.CreateBounded