mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Change to_utf8 to to_utf8_buffer and to_ascii to to_ascii_buffer in remaining docs
The method `to_utf8` doesn't exist in Godot 4, but is still mentioned in
the documentation in some places. Replace it with the new name
`to_utf8_buffer`. Same for ascii. Same for C#.
(cherry picked from commit 57dca93718)
This commit is contained in:
parent
51fdbf6ac7
commit
a6e15e2f15
7 changed files with 38 additions and 38 deletions
|
|
@ -15,27 +15,27 @@
|
||||||
var key = "My secret key!!!" # Key must be either 16 or 32 bytes.
|
var key = "My secret key!!!" # Key must be either 16 or 32 bytes.
|
||||||
var data = "My secret text!!" # Data size must be multiple of 16 bytes, apply padding if needed.
|
var data = "My secret text!!" # Data size must be multiple of 16 bytes, apply padding if needed.
|
||||||
# Encrypt ECB
|
# Encrypt ECB
|
||||||
aes.start(AESContext.MODE_ECB_ENCRYPT, key.to_utf8())
|
aes.start(AESContext.MODE_ECB_ENCRYPT, key.to_utf8_buffer())
|
||||||
var encrypted = aes.update(data.to_utf8())
|
var encrypted = aes.update(data.to_utf8_buffer())
|
||||||
aes.finish()
|
aes.finish()
|
||||||
# Decrypt ECB
|
# Decrypt ECB
|
||||||
aes.start(AESContext.MODE_ECB_DECRYPT, key.to_utf8())
|
aes.start(AESContext.MODE_ECB_DECRYPT, key.to_utf8_buffer())
|
||||||
var decrypted = aes.update(encrypted)
|
var decrypted = aes.update(encrypted)
|
||||||
aes.finish()
|
aes.finish()
|
||||||
# Check ECB
|
# Check ECB
|
||||||
assert(decrypted == data.to_utf8())
|
assert(decrypted == data.to_utf8_buffer())
|
||||||
|
|
||||||
var iv = "My secret iv!!!!" # IV must be of exactly 16 bytes.
|
var iv = "My secret iv!!!!" # IV must be of exactly 16 bytes.
|
||||||
# Encrypt CBC
|
# Encrypt CBC
|
||||||
aes.start(AESContext.MODE_CBC_ENCRYPT, key.to_utf8(), iv.to_utf8())
|
aes.start(AESContext.MODE_CBC_ENCRYPT, key.to_utf8_buffer(), iv.to_utf8_buffer())
|
||||||
encrypted = aes.update(data.to_utf8())
|
encrypted = aes.update(data.to_utf8_buffer())
|
||||||
aes.finish()
|
aes.finish()
|
||||||
# Decrypt CBC
|
# Decrypt CBC
|
||||||
aes.start(AESContext.MODE_CBC_DECRYPT, key.to_utf8(), iv.to_utf8())
|
aes.start(AESContext.MODE_CBC_DECRYPT, key.to_utf8_buffer(), iv.to_utf8_buffer())
|
||||||
decrypted = aes.update(encrypted)
|
decrypted = aes.update(encrypted)
|
||||||
aes.finish()
|
aes.finish()
|
||||||
# Check CBC
|
# Check CBC
|
||||||
assert(decrypted == data.to_utf8())
|
assert(decrypted == data.to_utf8_buffer())
|
||||||
[/gdscript]
|
[/gdscript]
|
||||||
[csharp]
|
[csharp]
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
@ -50,27 +50,27 @@
|
||||||
string key = "My secret key!!!"; // Key must be either 16 or 32 bytes.
|
string key = "My secret key!!!"; // Key must be either 16 or 32 bytes.
|
||||||
string data = "My secret text!!"; // Data size must be multiple of 16 bytes, apply padding if needed.
|
string data = "My secret text!!"; // Data size must be multiple of 16 bytes, apply padding if needed.
|
||||||
// Encrypt ECB
|
// Encrypt ECB
|
||||||
_aes.Start(AesContext.Mode.EcbEncrypt, key.ToUtf8());
|
_aes.Start(AesContext.Mode.EcbEncrypt, key.ToUtf8Buffer());
|
||||||
byte[] encrypted = _aes.Update(data.ToUtf8());
|
byte[] encrypted = _aes.Update(data.ToUtf8Buffer());
|
||||||
_aes.Finish();
|
_aes.Finish();
|
||||||
// Decrypt ECB
|
// Decrypt ECB
|
||||||
_aes.Start(AesContext.Mode.EcbDecrypt, key.ToUtf8());
|
_aes.Start(AesContext.Mode.EcbDecrypt, key.ToUtf8Buffer());
|
||||||
byte[] decrypted = _aes.Update(encrypted);
|
byte[] decrypted = _aes.Update(encrypted);
|
||||||
_aes.Finish();
|
_aes.Finish();
|
||||||
// Check ECB
|
// Check ECB
|
||||||
Debug.Assert(decrypted == data.ToUtf8());
|
Debug.Assert(decrypted == data.ToUtf8Buffer());
|
||||||
|
|
||||||
string iv = "My secret iv!!!!"; // IV must be of exactly 16 bytes.
|
string iv = "My secret iv!!!!"; // IV must be of exactly 16 bytes.
|
||||||
// Encrypt CBC
|
// Encrypt CBC
|
||||||
_aes.Start(AesContext.Mode.EcbEncrypt, key.ToUtf8(), iv.ToUtf8());
|
_aes.Start(AesContext.Mode.EcbEncrypt, key.ToUtf8Buffer(), iv.ToUtf8Buffer());
|
||||||
encrypted = _aes.Update(data.ToUtf8());
|
encrypted = _aes.Update(data.ToUtf8Buffer());
|
||||||
_aes.Finish();
|
_aes.Finish();
|
||||||
// Decrypt CBC
|
// Decrypt CBC
|
||||||
_aes.Start(AesContext.Mode.EcbDecrypt, key.ToUtf8(), iv.ToUtf8());
|
_aes.Start(AesContext.Mode.EcbDecrypt, key.ToUtf8Buffer(), iv.ToUtf8Buffer());
|
||||||
decrypted = _aes.Update(encrypted);
|
decrypted = _aes.Update(encrypted);
|
||||||
_aes.Finish();
|
_aes.Finish();
|
||||||
// Check CBC
|
// Check CBC
|
||||||
Debug.Assert(decrypted == data.ToUtf8());
|
Debug.Assert(decrypted == data.ToUtf8Buffer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[/csharp]
|
[/csharp]
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
cert.save("user://generated.crt")
|
cert.save("user://generated.crt")
|
||||||
# Encryption
|
# Encryption
|
||||||
var data = "Some data"
|
var data = "Some data"
|
||||||
var encrypted = crypto.encrypt(key, data.to_utf8())
|
var encrypted = crypto.encrypt(key, data.to_utf8_buffer())
|
||||||
# Decryption
|
# Decryption
|
||||||
var decrypted = crypto.decrypt(key, encrypted)
|
var decrypted = crypto.decrypt(key, encrypted)
|
||||||
# Signing
|
# Signing
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
var verified = crypto.verify(HashingContext.HASH_SHA256, data.sha256_buffer(), signature, key)
|
var verified = crypto.verify(HashingContext.HASH_SHA256, data.sha256_buffer(), signature, key)
|
||||||
# Checks
|
# Checks
|
||||||
assert(verified)
|
assert(verified)
|
||||||
assert(data.to_utf8() == decrypted)
|
assert(data.to_utf8_buffer() == decrypted)
|
||||||
[/gdscript]
|
[/gdscript]
|
||||||
[csharp]
|
[csharp]
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
@ -56,7 +56,7 @@
|
||||||
_cert.Save("user://generated.crt");
|
_cert.Save("user://generated.crt");
|
||||||
// Encryption
|
// Encryption
|
||||||
string data = "Some data";
|
string data = "Some data";
|
||||||
byte[] encrypted = _crypto.Encrypt(_key, data.ToUtf8());
|
byte[] encrypted = _crypto.Encrypt(_key, data.ToUtf8Buffer());
|
||||||
// Decryption
|
// Decryption
|
||||||
byte[] decrypted = _crypto.Decrypt(_key, encrypted);
|
byte[] decrypted = _crypto.Decrypt(_key, encrypted);
|
||||||
// Signing
|
// Signing
|
||||||
|
|
@ -65,7 +65,7 @@
|
||||||
bool verified = _crypto.Verify(HashingContext.HashType.Sha256, Data.Sha256Buffer(), signature, _key);
|
bool verified = _crypto.Verify(HashingContext.HashType.Sha256, Data.Sha256Buffer(), signature, _key);
|
||||||
// Checks
|
// Checks
|
||||||
Debug.Assert(verified);
|
Debug.Assert(verified);
|
||||||
Debug.Assert(data.ToUtf8() == decrypted);
|
Debug.Assert(data.ToUtf8Buffer() == decrypted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[/csharp]
|
[/csharp]
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
if p.get_status() == PacketPeerDTLS.STATUS_CONNECTED:
|
if p.get_status() == PacketPeerDTLS.STATUS_CONNECTED:
|
||||||
while p.get_available_packet_count() > 0:
|
while p.get_available_packet_count() > 0:
|
||||||
print("Received message from client: %s" % p.get_packet().get_string_from_utf8())
|
print("Received message from client: %s" % p.get_packet().get_string_from_utf8())
|
||||||
p.put_packet("Hello DTLS client".to_utf8())
|
p.put_packet("Hello DTLS client".to_utf8_buffer())
|
||||||
[/gdscript]
|
[/gdscript]
|
||||||
[csharp]
|
[csharp]
|
||||||
// ServerNode.cs
|
// ServerNode.cs
|
||||||
|
|
@ -77,7 +77,7 @@
|
||||||
while (p.GetAvailablePacketCount() > 0)
|
while (p.GetAvailablePacketCount() > 0)
|
||||||
{
|
{
|
||||||
GD.Print($"Received Message From Client: {p.GetPacket().GetStringFromUtf8()}");
|
GD.Print($"Received Message From Client: {p.GetPacket().GetStringFromUtf8()}");
|
||||||
p.PutPacket("Hello DTLS Client".ToUtf8());
|
p.PutPacket("Hello DTLS Client".ToUtf8Buffer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -103,7 +103,7 @@
|
||||||
if dtls.get_status() == PacketPeerDTLS.STATUS_CONNECTED:
|
if dtls.get_status() == PacketPeerDTLS.STATUS_CONNECTED:
|
||||||
if !connected:
|
if !connected:
|
||||||
# Try to contact server
|
# Try to contact server
|
||||||
dtls.put_packet("The answer is... 42!".to_utf8())
|
dtls.put_packet("The answer is... 42!".to_utf8_buffer())
|
||||||
while dtls.get_available_packet_count() > 0:
|
while dtls.get_available_packet_count() > 0:
|
||||||
print("Connected: %s" % dtls.get_packet().get_string_from_utf8())
|
print("Connected: %s" % dtls.get_packet().get_string_from_utf8())
|
||||||
connected = true
|
connected = true
|
||||||
|
|
@ -133,7 +133,7 @@
|
||||||
if (!_connected)
|
if (!_connected)
|
||||||
{
|
{
|
||||||
// Try to contact server
|
// Try to contact server
|
||||||
_dtls.PutPacket("The Answer Is..42!".ToUtf8());
|
_dtls.PutPacket("The Answer Is..42!".ToUtf8Buffer());
|
||||||
}
|
}
|
||||||
while (_dtls.GetAvailablePacketCount() > 0)
|
while (_dtls.GetAvailablePacketCount() > 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@
|
||||||
var ctx = HMACContext.new()
|
var ctx = HMACContext.new()
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
var key = "supersecret".to_utf8()
|
var key = "supersecret".to_utf8_buffer()
|
||||||
var err = ctx.start(HashingContext.HASH_SHA256, key)
|
var err = ctx.start(HashingContext.HASH_SHA256, key)
|
||||||
assert(err == OK)
|
assert(err == OK)
|
||||||
var msg1 = "this is ".to_utf8()
|
var msg1 = "this is ".to_utf8_buffer()
|
||||||
var msg2 = "super duper secret".to_utf8()
|
var msg2 = "super duper secret".to_utf8_buffer()
|
||||||
err = ctx.update(msg1)
|
err = ctx.update(msg1)
|
||||||
assert(err == OK)
|
assert(err == OK)
|
||||||
err = ctx.update(msg2)
|
err = ctx.update(msg2)
|
||||||
|
|
@ -34,11 +34,11 @@
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
byte[] key = "supersecret".ToUtf8();
|
byte[] key = "supersecret".ToUtf8Buffer();
|
||||||
Error err = _ctx.Start(HashingContext.HashType.Sha256, key);
|
Error err = _ctx.Start(HashingContext.HashType.Sha256, key);
|
||||||
Debug.Assert(err == Error.Ok);
|
Debug.Assert(err == Error.Ok);
|
||||||
byte[] msg1 = "this is ".ToUtf8();
|
byte[] msg1 = "this is ".ToUtf8Buffer();
|
||||||
byte[] msg2 = "super duper secret".ToUtf8();
|
byte[] msg2 = "super duper secret".ToUtf8Buffer();
|
||||||
err = _ctx.Update(msg1);
|
err = _ctx.Update(msg1);
|
||||||
Debug.Assert(err == Error.Ok);
|
Debug.Assert(err == Error.Ok);
|
||||||
err = _ctx.Update(msg2);
|
err = _ctx.Update(msg2);
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@
|
||||||
socket = PacketPeerUDP.new()
|
socket = PacketPeerUDP.new()
|
||||||
# Server
|
# Server
|
||||||
socket.set_dest_address("127.0.0.1", 789)
|
socket.set_dest_address("127.0.0.1", 789)
|
||||||
socket.put_packet("Time to stop".to_ascii())
|
socket.put_packet("Time to stop".to_ascii_buffer())
|
||||||
|
|
||||||
# Client
|
# Client
|
||||||
while socket.wait() == OK:
|
while socket.wait() == OK:
|
||||||
|
|
@ -124,7 +124,7 @@
|
||||||
var socket = new PacketPeerUDP();
|
var socket = new PacketPeerUDP();
|
||||||
// Server
|
// Server
|
||||||
socket.SetDestAddress("127.0.0.1", 789);
|
socket.SetDestAddress("127.0.0.1", 789);
|
||||||
socket.PutPacket("Time to stop".ToAscii());
|
socket.PutPacket("Time to stop".ToAsciiBuffer());
|
||||||
|
|
||||||
// Client
|
// Client
|
||||||
while (socket.Wait() == OK)
|
while (socket.Wait() == OK)
|
||||||
|
|
|
||||||
|
|
@ -177,10 +177,10 @@
|
||||||
[b]Note:[/b] To put an ASCII string without prepending its size, you can use [method put_data]:
|
[b]Note:[/b] To put an ASCII string without prepending its size, you can use [method put_data]:
|
||||||
[codeblocks]
|
[codeblocks]
|
||||||
[gdscript]
|
[gdscript]
|
||||||
put_data("Hello world".to_ascii())
|
put_data("Hello world".to_ascii_buffer())
|
||||||
[/gdscript]
|
[/gdscript]
|
||||||
[csharp]
|
[csharp]
|
||||||
PutData("Hello World".ToAscii());
|
PutData("Hello World".ToAsciiBuffer());
|
||||||
[/csharp]
|
[/csharp]
|
||||||
[/codeblocks]
|
[/codeblocks]
|
||||||
</description>
|
</description>
|
||||||
|
|
@ -221,10 +221,10 @@
|
||||||
[b]Note:[/b] To put an UTF-8 string without prepending its size, you can use [method put_data]:
|
[b]Note:[/b] To put an UTF-8 string without prepending its size, you can use [method put_data]:
|
||||||
[codeblocks]
|
[codeblocks]
|
||||||
[gdscript]
|
[gdscript]
|
||||||
put_data("Hello world".to_utf8())
|
put_data("Hello world".to_utf8_buffer())
|
||||||
[/gdscript]
|
[/gdscript]
|
||||||
[csharp]
|
[csharp]
|
||||||
PutData("Hello World".ToUtf8());
|
PutData("Hello World".ToUtf8Buffer());
|
||||||
[/csharp]
|
[/csharp]
|
||||||
[/codeblocks]
|
[/codeblocks]
|
||||||
</description>
|
</description>
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
if !connected:
|
if !connected:
|
||||||
# Try to contact server
|
# Try to contact server
|
||||||
udp.put_packet("The answer is... 42!".to_utf8())
|
udp.put_packet("The answer is... 42!".to_utf8_buffer())
|
||||||
if udp.get_available_packet_count() > 0:
|
if udp.get_available_packet_count() > 0:
|
||||||
print("Connected: %s" % udp.get_packet().get_string_from_utf8())
|
print("Connected: %s" % udp.get_packet().get_string_from_utf8())
|
||||||
connected = true
|
connected = true
|
||||||
|
|
@ -110,7 +110,7 @@
|
||||||
if (!_connected)
|
if (!_connected)
|
||||||
{
|
{
|
||||||
// Try to contact server
|
// Try to contact server
|
||||||
_udp.PutPacket("The Answer Is..42!".ToUtf8());
|
_udp.PutPacket("The Answer Is..42!".ToUtf8Buffer());
|
||||||
}
|
}
|
||||||
if (_udp.GetAvailablePacketCount() > 0)
|
if (_udp.GetAvailablePacketCount() > 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue