-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from JetBrains/graph-store-configurable-close
Graph store configurable close && crop cipher key
- Loading branch information
Showing
11 changed files
with
215 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/ODatabaseConnectionConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright ${inceptionYear} - ${year} ${owner} | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package jetbrains.exodus.entitystore.orientdb | ||
|
||
import com.orientechnologies.orient.core.db.ODatabaseType | ||
|
||
class ODatabaseConnectionConfig private constructor( | ||
val databaseRoot: String, | ||
val userName: String, | ||
val password: String, | ||
val databaseType: ODatabaseType, | ||
val closeAfterDelayTimeout: Int | ||
) { | ||
companion object { | ||
fun builder(): Builder { | ||
return Builder() | ||
} | ||
} | ||
|
||
@Suppress("unused") | ||
class Builder internal constructor() { | ||
private lateinit var databaseRoot: String | ||
private lateinit var userName: String | ||
private lateinit var password: String | ||
private var databaseType: ODatabaseType = ODatabaseType.MEMORY | ||
private var closeAfterDelayTimeout: Int = 10 | ||
|
||
fun withDatabaseRoot(databaseURL: String) = apply { this.databaseRoot = databaseURL } | ||
fun withUserName(userName: String) = apply { this.userName = userName } | ||
fun withPassword(password: String) = apply { this.password = password } | ||
fun withDatabaseType(databaseType: ODatabaseType) = apply { this.databaseType = databaseType } | ||
fun withCloseAfterDelayTimeout(closeAfterDelayTimeout: Int) = | ||
apply { this.closeAfterDelayTimeout = closeAfterDelayTimeout } | ||
|
||
fun build() = ODatabaseConnectionConfig( | ||
databaseRoot, userName, password, databaseType, | ||
closeAfterDelayTimeout | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
entity-store/src/test/kotlin/jetbrains/exodus/entitystore/orientdb/ODatabaseConfigTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright ${inceptionYear} - ${year} ${owner} | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package jetbrains.exodus.entitystore.orientdb | ||
|
||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
class ODatabaseConfigTest { | ||
@Test | ||
fun `cypher key is trunked to 24 bytes from bigger one`() { | ||
val key1 = Array(60) { "aa" }.joinToString(separator = "") | ||
|
||
val connConfig = ODatabaseConnectionConfig | ||
.builder() | ||
.withUserName("testUrl") | ||
.withPassword("testPassword") | ||
.withDatabaseRoot("aa") | ||
.build() | ||
|
||
|
||
val cfg = ODatabaseConfig | ||
.builder() | ||
.withConnectionConfig(connConfig) | ||
.withStringHexAndIV(key1, 10L) | ||
.withDatabaseName("aa") | ||
.build() | ||
|
||
Assert.assertEquals(24, cfg.cipherKey?.size) | ||
} | ||
|
||
@Test | ||
fun `cypher key is not trunked if key is smaller than 24`() { | ||
val key1 = "aabbccddaabbccdd" | ||
|
||
val connConfig = ODatabaseConnectionConfig.builder() | ||
.withUserName("testUrl") | ||
.withPassword("testPassword") | ||
.withDatabaseRoot("aa") | ||
.build() | ||
|
||
val cfg = ODatabaseConfig | ||
.builder() | ||
.withConnectionConfig(connConfig) | ||
.withStringHexAndIV(key1, 10L) | ||
.withDatabaseName("aa") | ||
|
||
.build() | ||
|
||
Assert.assertEquals(16, cfg.cipherKey?.size) | ||
} | ||
|
||
} |
Oops, something went wrong.