Keystore Plaintext Storage API and Local File implementation
[netconf.git] / keystore / plaintext-api / src / main / java / org / opendaylight / netconf / keystore / plaintext / api / MutablePlaintextStorage.java
1 /*
2  * Copyright (c) 2024 PANTHEON.tech s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.keystore.plaintext.api;
9
10 import java.io.IOException;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.eclipse.jdt.annotation.Nullable;
13
14 /**
15  * Mutable Plaintext Storage interface.
16  */
17 public interface MutablePlaintextStorage extends PlaintextStorage {
18
19     /**
20      * Removes the mapping for a key from this storage if it is present.
21      *
22      * @param key key whose mapping is to be removed from the map
23      * @return the previous value associated with key, or null if there was no mapping for key
24      * @throws IOException on storage update error
25      */
26     byte @Nullable [] removeKey(byte @NonNull [] key) throws IOException;
27
28     /**
29      * Removes the entry for the specified key only if it is currently mapped to the specified value.
30      *
31      * @param key key with which the specified value is associated
32      * @param value value expected to be associated with the specified key
33      * @return true if entry was removed, false otherwise
34      * @throws IOException on storage update error
35      */
36     boolean removeEntry(byte @NonNull [] key, byte @NonNull [] value) throws IOException;
37
38     /**
39      * If the specified key is not already associated with a value associates it with the given value and returns null,
40      * else returns the current value.
41      *
42      * @param key key with which the specified value is to be associated
43      * @param value value to be associated with the specified key
44      * @return the previous value associated with the specified key, or null if there was no mapping for the key
45      * @throws IOException on storage update error
46      */
47     byte @Nullable [] insertEntry(byte @NonNull [] key, byte @NonNull [] value) throws IOException;
48
49     /**
50      * Associates the specified value with the specified key.
51      *
52      * @param key key with which the specified value is to be associated
53      * @param value value to be associated with the specified key
54      * @return the previous value associated with key, or null if there was no mapping for key
55      * @throws IOException on storage update error
56      */
57     byte @Nullable [] putEntry(byte @NonNull [] key, byte @NonNull [] value) throws IOException;
58 }