From f3d8b4474302a00fd923581046b0f5828a4c5976 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 12 Apr 2022 20:55:34 +0200 Subject: copyright headers --- packages/anastasis-core/src/crypto.ts | 16 ++++++++++++++ packages/anastasis-core/src/index.ts | 32 +++++++++++++++++++++++++++ packages/anastasis-core/src/provider-types.ts | 18 +++++++++++++-- packages/anastasis-core/src/reducer-types.ts | 16 ++++++++++++++ 4 files changed, 80 insertions(+), 2 deletions(-) (limited to 'packages/anastasis-core') diff --git a/packages/anastasis-core/src/crypto.ts b/packages/anastasis-core/src/crypto.ts index 37e8c4f54..9f412c6dc 100644 --- a/packages/anastasis-core/src/crypto.ts +++ b/packages/anastasis-core/src/crypto.ts @@ -1,3 +1,19 @@ +/* + This file is part of GNU Anastasis + (C) 2021-2022 Anastasis SARL + + GNU Anastasis is free software; you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with + GNU Anastasis; see the file COPYING. If not, see + */ + import { canonicalJson, decodeCrock, diff --git a/packages/anastasis-core/src/index.ts b/packages/anastasis-core/src/index.ts index 5a9199e02..542e7eafb 100644 --- a/packages/anastasis-core/src/index.ts +++ b/packages/anastasis-core/src/index.ts @@ -74,6 +74,7 @@ import { DiscoveryResult, PolicyMetaInfo, ChallengeInfo, + AggregatedPolicyMetaInfo, } from "./reducer-types.js"; import fetchPonyfill from "fetch-ponyfill"; import { @@ -1451,6 +1452,37 @@ async function updateSecretExpiration( }); } +export function mergeDiscoveryAggregate( + newPolicies: PolicyMetaInfo[], + oldAgg: AggregatedPolicyMetaInfo[], +): AggregatedPolicyMetaInfo[] { + const aggregatedPolicies: AggregatedPolicyMetaInfo[] = [...oldAgg] ?? []; + const polHashToIndex: Record = {}; + for (const pol of newPolicies) { + const oldIndex = polHashToIndex[pol.policy_hash]; + if (oldIndex != null) { + aggregatedPolicies[oldIndex].providers.push({ + provider_url: pol.provider_url, + version: pol.version, + }); + } else { + aggregatedPolicies.push({ + attribute_mask: pol.attribute_mask, + policy_hash: pol.policy_hash, + providers: [ + { + provider_url: pol.provider_url, + version: pol.version, + }, + ], + secret_name: pol.secret_name, + }); + polHashToIndex[pol.policy_hash] = aggregatedPolicies.length - 1; + } + } + return aggregatedPolicies; +} + const backupTransitions: Record< BackupStates, Transition diff --git a/packages/anastasis-core/src/provider-types.ts b/packages/anastasis-core/src/provider-types.ts index fe6292b02..b788f629d 100644 --- a/packages/anastasis-core/src/provider-types.ts +++ b/packages/anastasis-core/src/provider-types.ts @@ -1,7 +1,21 @@ +/* + This file is part of GNU Anastasis + (C) 2021-2022 Anastasis SARL + + GNU Anastasis is free software; you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with + GNU Anastasis; see the file COPYING. If not, see + */ + import { - Amounts, AmountString, - TalerProtocolDuration, TalerProtocolTimestamp, } from "@gnu-taler/taler-util"; diff --git a/packages/anastasis-core/src/reducer-types.ts b/packages/anastasis-core/src/reducer-types.ts index 47238cd3f..7e8d4da25 100644 --- a/packages/anastasis-core/src/reducer-types.ts +++ b/packages/anastasis-core/src/reducer-types.ts @@ -1,3 +1,19 @@ +/* + This file is part of GNU Anastasis + (C) 2021-2022 Anastasis SARL + + GNU Anastasis is free software; you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Anastasis is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with + GNU Anastasis; see the file COPYING. If not, see + */ + import { AmountString, buildCodecForObject, -- cgit v1.2.3