-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Arnau Mora Gras <[email protected]>
- Loading branch information
1 parent
6740daf
commit 0a11129
Showing
4 changed files
with
78 additions
and
45 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
65 changes: 65 additions & 0 deletions
65
src/main/kotlin/at/bitfire/dav4jvm/property/push/PushPublicKey.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 @@ | ||
package at.bitfire.dav4jvm.property.push | ||
|
||
import at.bitfire.dav4jvm.Property | ||
import at.bitfire.dav4jvm.PropertyFactory | ||
import at.bitfire.dav4jvm.XmlReader | ||
import at.bitfire.dav4jvm.XmlUtils.propertyName | ||
import org.xmlpull.v1.XmlPullParser | ||
|
||
/** | ||
* Represents a public key property from Push. | ||
* | ||
* Experimental! See https://github.com/bitfireAT/webdav-push/ | ||
* | ||
* @see ClientPublicKey | ||
* @see ServerPublicKey | ||
*/ | ||
abstract class PushPublicKey: Property { | ||
|
||
companion object { | ||
@JvmField | ||
val NAME = Property.Name(NS_WEBDAV_PUSH, "server-public-key") | ||
|
||
val PROP_TYPE = Property.Name(NS_WEBDAV_PUSH, "type") | ||
} | ||
|
||
var type: String? = null | ||
var key: String? = null | ||
|
||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other !is PushPublicKey) return false | ||
|
||
if (type != other.type) return false | ||
if (key != other.key) return false | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = type?.hashCode() ?: 0 | ||
result = 31 * result + (key?.hashCode() ?: 0) | ||
return result | ||
} | ||
|
||
|
||
abstract class Factory<KeyType: PushPublicKey>( | ||
private val name: Property.Name, | ||
private val constructor: () -> KeyType | ||
): PropertyFactory { | ||
|
||
override fun getName() = name | ||
|
||
override fun create(parser: XmlPullParser): KeyType { | ||
val publicKey = constructor() | ||
|
||
publicKey.type = parser.getAttributeValue(null, "type") | ||
publicKey.key = XmlReader(parser).readText() | ||
|
||
return publicKey | ||
} | ||
|
||
} | ||
|
||
} |
24 changes: 2 additions & 22 deletions
24
src/main/kotlin/at/bitfire/dav4jvm/property/push/ServerPublicKey.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,37 +1,17 @@ | ||
package at.bitfire.dav4jvm.property.push | ||
|
||
import at.bitfire.dav4jvm.Property | ||
import at.bitfire.dav4jvm.PropertyFactory | ||
import org.xmlpull.v1.XmlPullParser | ||
|
||
/** | ||
* Represents a `{DAV:Push}server-public-key` property. | ||
* | ||
* Experimental! See https://github.com/bitfireAT/webdav-push/ | ||
*/ | ||
data class ServerPublicKey( | ||
val type: String?, | ||
val value: String? | ||
): Property { | ||
|
||
class ServerPublicKey: PushPublicKey() { | ||
companion object { | ||
@JvmField | ||
val NAME = Property.Name(NS_WEBDAV_PUSH, "server-public-key") | ||
|
||
const val PROP_TYPE = "type" | ||
} | ||
|
||
object Factory: PropertyFactory { | ||
|
||
override fun getName() = PushTransports.NAME | ||
|
||
override fun create(parser: XmlPullParser): ServerPublicKey { | ||
val type = parser.getAttributeValue(NS_WEBDAV_PUSH, PROP_TYPE) | ||
val value = parser.text | ||
|
||
return ServerPublicKey(type, value) | ||
} | ||
|
||
} | ||
|
||
object Factory : PushPublicKey.Factory<ServerPublicKey>(NAME, ::ServerPublicKey) | ||
} |
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