Skip to content

Commit

Permalink
missing files for PR eclipse-leshan#7
Browse files Browse the repository at this point in the history
  • Loading branch information
jvermillard committed Jul 1, 2014
1 parent 6b3d04e commit 106a4e1
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2014 Institute for Pervasive Computing, ETH Zurich and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Julien Vermillard - Sierra Wireless
******************************************************************************/
package org.eclipse.californium.scandium.dtls.pskstore;

import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* An in-memory pre-shared-key storage. To be used only for testing and evaluation.
* You are supposed to store your key in a secure way:
* keeping them in-memory is not a good idea.
*/
public class InMemoryPskStore implements PskStore {

private Map<String, byte[]> keys = new ConcurrentHashMap<>();

@Override
public byte[] getKey(String identity) {
byte[] key = keys.get(identity);
if (key == null) {
return null;
} else {
// defensive copy
return Arrays.copyOf(key, key.length);
}
}

/**
* Set a key value for a given identity.
*
* @param identity the identity associated with the key
* @param key the key used to authenticate the identity
*/
public void setKey(String identity, byte[] key) {
keys.put(identity, key);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2014 Institute for Pervasive Computing, ETH Zurich and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Julien Vermillard - Sierra Wireless
******************************************************************************/
package org.eclipse.californium.scandium.dtls.pskstore;

/**
* A storage for pre-shared-key identity.
*/
public interface PskStore {

/**
* Get the key for a given identity.
* @param identity the identity to authenticate
* @return the key or <code>null</code> if not found
*/
byte[] getKey(String identity);

}

0 comments on commit 106a4e1

Please sign in to comment.