com.github.pgasync.impl.io.AuthenticationDecoder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of postgres-async-driver Show documentation
Show all versions of postgres-async-driver Show documentation
Asynchronous PostgreSQL Java driver
/*
* 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
*
* http://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 com.github.pgasync.impl.io;
import com.github.pgasync.impl.message.Authentication;
import java.nio.ByteBuffer;
/**
* See PostgreSQL message formats
*
*
* AuthenticationOk (B)
* Byte1('R')
* Identifies the message as an authentication request.
* Int32(8)
* Length of message contents in bytes, including self.
* Int32(0)
* Specifies that the authentication was successful.
*
* AuthenticationMD5Password (B)
* Byte1('R')
* Identifies the message as an authentication request.
* Int32(12)
* Length of message contents in bytes, including self.
* Int32(5)
* Specifies that an MD5-encrypted password is required.
* Byte4
* The salt to use when encrypting the password.
*
*
* @author Antti Laisi
*/
public class AuthenticationDecoder implements Decoder {
static final int OK = 0;
static final int PASSWORD_MD5_CHALLENGE = 5;
@Override
public byte getMessageId() {
return 'R';
}
@Override
public Authentication read(ByteBuffer buffer) {
int type = buffer.getInt();
switch (type) {
case OK:
return new Authentication(true, null);
case PASSWORD_MD5_CHALLENGE:
byte[] salt = new byte[4];
buffer.get(salt);
return new Authentication(false, salt);
default:
throw new UnsupportedOperationException("Unsupported authentication type: " + type);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy