-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add internal xml writer (#183)
- Loading branch information
1 parent
c7a0c4b
commit ff00b26
Showing
12 changed files
with
211 additions
and
59 deletions.
There are no files selected for viewing
22 changes: 18 additions & 4 deletions
22
tinypass/src/commonMain/kotlin/io/spherelabs/crypto/tinypass/database/core/KdbxDatabase.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 |
---|---|---|
@@ -1,23 +1,37 @@ | ||
package io.spherelabs.crypto.tinypass.database.core | ||
|
||
import io.spherelabs.crypto.tinypass.database.buffer.KdbxBuffer | ||
import io.spherelabs.crypto.tinypass.database.buffer.KdbxReader | ||
import io.spherelabs.crypto.tinypass.database.getPlatformFileSystem | ||
import io.spherelabs.crypto.tinypass.database.header.KdbxInnerHeader | ||
import io.spherelabs.crypto.tinypass.database.header.KdbxOuterHeader | ||
import io.spherelabs.crypto.tinypass.database.model.component.KdbxQuery | ||
import io.spherelabs.crypto.tinypass.database.serializer.KdbxSerializer | ||
import kotlin.coroutines.CoroutineContext | ||
import okio.Buffer | ||
import okio.Path.Companion.toPath | ||
|
||
data class KdbxDatabase( | ||
val configuration: KdbxConfiguration, | ||
val outerHeader: KdbxOuterHeader, | ||
val innerHeader: KdbxInnerHeader, | ||
val query: KdbxQuery, | ||
) { | ||
// private val decoder = KdbxSerializer.decode(configuration) | ||
|
||
companion object { | ||
fun isEmpty(path: String): Boolean { | ||
return getPlatformFileSystem().exists(path.toPath()) | ||
} | ||
|
||
fun write(configuration: KdbxConfiguration): KdbxDatabase { | ||
return if (!isEmpty(configuration.path)) KdbxSerializer.encode(configuration) else { | ||
throw Exception("File is existed!") | ||
} | ||
} | ||
} | ||
|
||
fun read(): KdbxQuery { | ||
TODO() | ||
} | ||
|
||
fun write() { | ||
KdbxSerializer.encode(configuration) | ||
} | ||
} |
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
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
13 changes: 11 additions & 2 deletions
13
tinypass/src/commonMain/kotlin/io/spherelabs/crypto/tinypass/database/xml/XmlReader.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 |
---|---|---|
@@ -1,7 +1,16 @@ | ||
package io.spherelabs.crypto.tinypass.database.xml | ||
|
||
import com.fleeksoft.ksoup.nodes.Element | ||
import io.spherelabs.crypto.tinypass.database.common.xmlParser | ||
import io.spherelabs.crypto.tinypass.database.core.KdbxDatabase | ||
import io.spherelabs.crypto.tinypass.database.core.KdbxQuery | ||
import okio.BufferedSource | ||
|
||
interface XmlReader<T : Any> { | ||
fun read(element: Element): T | ||
|
||
object XmlReader { | ||
fun read(source: BufferedSource, option: XmlOption): KdbxQuery { | ||
val documentation = xmlParser(source.readByteArray()) | ||
val root = documentation.root() | ||
TODO() | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
...s/src/commonMain/kotlin/io/spherelabs/crypto/tinypass/database/xml/internal/_XmlWriter.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,56 @@ | ||
package io.spherelabs.crypto.tinypass.database.xml.internal | ||
|
||
import com.benasher44.uuid.Uuid | ||
import com.fleeksoft.ksoup.nodes.Element | ||
import io.spherelabs.crypto.tinypass.database.common.addBytes | ||
import io.spherelabs.crypto.tinypass.database.common.addUuid | ||
import io.spherelabs.crypto.tinypass.database.model.autotype.toXmlString | ||
import io.spherelabs.crypto.tinypass.database.xml.XmlOption | ||
|
||
|
||
internal fun element(tagName: String, builder: Element.() -> Unit): Element = | ||
Element(tagName).apply(builder) | ||
|
||
internal inline fun Element.writeElement( | ||
tagName: String, | ||
value: String, | ||
option: XmlOption, | ||
) { | ||
appendElement(tagName).text(value) | ||
} | ||
|
||
internal inline fun Element.writeElement( | ||
tagName: String, | ||
value: String, | ||
) { | ||
appendElement(tagName).text(value) | ||
} | ||
|
||
internal inline fun Element.writeElement( | ||
tagName: String, | ||
raw: ByteArray, | ||
) { | ||
appendElement(tagName).addBytes(raw) | ||
} | ||
|
||
internal inline fun Element.writeElement( | ||
tagName: String, | ||
raw: Boolean, | ||
) { | ||
appendElement(tagName).text(raw.toXmlString()) | ||
} | ||
|
||
internal inline fun Element.writeElement( | ||
tagName: String, | ||
uuid: Uuid, | ||
) { | ||
appendElement(tagName).addUuid(uuid) | ||
} | ||
|
||
internal inline fun Element.writeIfElement( | ||
predicate: Boolean, | ||
tagName: String, | ||
raw: String, | ||
) { | ||
if (predicate) appendElement(tagName).text(raw) | ||
} |
Oops, something went wrong.